Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes filename tracking in errorformat #20

Closed
wants to merge 1 commit into from

Conversation

netj
Copy link
Contributor

@netj netj commented Jun 6, 2015

Fixes an incorrect 'errorformat' set by vim-latex to the correct ones in the latest Vim documentation.

@tyll
Copy link
Contributor

tyll commented Jun 6, 2015

Can you please provide an example that makes it possible to reproduce the bug that is fixed here?

@netj
Copy link
Contributor Author

netj commented Jun 6, 2015

Sorry for not being clear. Here's a minimal example I created: https://gist.github.com/netj/f61c5931598d0c6ff704

When you compile a multi-file .tex document where the master .tex \inputs or \includes other .tex files,
the %P and %Q efms should recognize different filenames in the log. For some unknown reason, it's been broken for a while (at least for pdflatex), so I made this quick fix ~3 years ago. However, it turns out my patch doesn't actually fix the problem. I'll figure out and update the pull request soon.

When a document consists of multiple .tex files, the current errorformat
can lose track of the filename the warning refers to.

See https://gist.github.com/netj/f61c5931598d0c6ff704 for an example to
reproduce this bug.
@netj netj changed the title Fixes bugs in errorformat Fixes filename tracking in errorformat Jun 7, 2015
@netj
Copy link
Contributor Author

netj commented Jun 7, 2015

Please take another look. I've amended the previous commit to work with my example as well as a larger document (with dozens of inputs). Getting the efm for %P and %Q correct is surprisingly difficult than it seems. The one introduced in vim's documentation (:h errorformat-LaTeX) actually no longer works with modern latex output. I tried to stick to what vim's doc suggests and make minimal changes to fix it. I admit the resulting code is a bit ugly and there may be ways to simplify it, but it finally fixes the annoying problem of jumping to random files!

@rekka
Copy link

rekka commented May 12, 2016

@netj Thanks for the fix, seems to work great!

@gerw
Copy link
Contributor

gerw commented May 20, 2016

I agree that the errorformat could be improved.

@netj: I do not get the problem with your posted example. For me, everything works fine with the current errorformat. What do you get with the current errorformat in the quickfix window (:copen) and what do you expect?

@rekka: Could you please post an example *.log-file for which the current errorformat does not work?

@netj
Copy link
Contributor Author

netj commented May 20, 2016

@gerw Interestingly it's working fine now without my patch. fbda235 has no problem picking up the correct file names with texlive-2015 (on Mac) in Vim 7.4.1589.

I updated the gist with new a.log whose diff is shown here: https://gist.github.com/netj/f61c5931598d0c6ff704/revisions
I see slight changes to the old lines 68-71: from [1\n...\n] (a.aux) to [1\n...]\n(a.aux) which I'm guessing to be the old cause.

Honestly, I forgot what exactly was the old problem and how I fixed it since this was many many years ago. However, I'm pretty sure I was trying to make the errorformat more robust. I'd vote for putting this in, but feel free to close it.

UPDATE: Sorry, those lines may be a red herring since no actual errors follow. I don't know.. maybe it was my old Vim version, but I probably tested on the latest back then too before creating this PR.

@gerw
Copy link
Contributor

gerw commented May 20, 2016

Thank you for your reply. I think that I can imagine what your patch tries to improve. The usage of the errorformat by vim is quite 'special' and this makes the creation of a proper errorformat difficult.

One thing involves the %f-pattern. It matches anything that looks like a file-name, but the file-name is only pushed to the stack if the file exists. One should keep this in mind while testing log files from other persons.
(Moreover, the %r is only processed if there is no %f in the pattern or the %f matches an existing file)

I will try to improve the errorformat in the next days/weeks/years. For this it would help to see log-files created by different versions of latex.

@gerw
Copy link
Contributor

gerw commented Jan 22, 2017

The last commit tries to improve the errorformat. Please check whether it works for you.

@gerw gerw closed this Jan 22, 2017
@rekka
Copy link

rekka commented Jan 23, 2017

Thanks for all your work. It definitely works better in that it picks up some file name for an error. However, it is very fragile, failing on quite simple included tex files with figures, for instance. Minimal example with 3 files test.tex, other.tex, some.pdf:

% test.tex
\documentclass{article}
\usepackage{graphicx}
\begin{document}
\input{other.tex}
\undefined
\end{document}

% other.tex
\includegraphics{some.pdf}

Reports error in the wrong file:

other.tex|5 error| Undefined control sequence. \undefined 

Log: https://gist.github.com/rekka/6db540ef4cd47992cc26cd86d9fdf257

@gerw
Copy link
Contributor

gerw commented Jan 23, 2017

Thank you for reporting.

This is weird since (other.tex on line 134 is clearly closed on line 139: ). For me, it works fine. Can you delete lines 135-138 line-by-line to see which of these lines causes the error? Which version of vim are you using? Can you post your efm setting?

However, there is another problem on your line 86: the ) should be on the previous line. (But this should not cause your error). You should set max_print_line of LaTeX to some high number, e.g., 1024, see http://tex.stackexchange.com/questions/83600/how-can-i-use-max-print-line-in-pdftex-texlive

@rekka
Copy link

rekka commented Jan 23, 2017

Thank you for your quick reply.

So based on your suggestion, I double checked how I am running pdflatex and noticed that I had a custom command that was missing -file-line-error-style. Adding it fixed the above test case. So now, errors seem to work fine. I suppose errors are using the file:line:error format, but not warnings...

However, I noticed that warnings still have a problem. Minimal test case (other.tex) as above, with default pdflatex command set by vim-latex:

\documentclass{article}
\usepackage{graphicx}
\begin{document}
\input{other.tex}
\undefined
\ref{none}
\undefined
\ref{none}
\end{document}

Now this prints

test2.tex|5 error| Undefined control sequence. \undefined 
other.tex|6 warning| LaTeX Warning: Reference `none' on page 1 undefined on input line 6.
test2.tex|7 error| Undefined control sequence. \undefined 
other.tex|8 warning| LaTeX Warning: Reference `none' on page 1 undefined on input line 8.

Here's the log output: https://gist.github.com/rekka/4c382f894c6a9a1f814aaa8b43295bb1

If I use max_print_line=1024, then even if I comment out the line \input{other.tex}, I get

test2.tex|5 error| Undefined control sequence. \undefined 
/usr/share/texlive/texmf-dist/tex/latex/oberdiek/epstopdf-base.sty|6 warning| LaTeX Warning: Reference `none' on page 1 undefined on input line 6.
test2.tex|7 error| Undefined control sequence. \undefined 
/usr/share/texlive/texmf-dist/tex/latex/oberdiek/epstopdf-base.sty|8 warning| LaTeX Warning: Reference `none' on page 1 undefined on input line 8.

Here's the log: https://gist.github.com/rekka/563e9f0ed58bd457d3509a445b41dc24

By the way, how can I delete lines in the log file line-by-line and then request vim to reparse the errors?


For completeness:

:version
VIM - Vi IMproved 7.4 (2013 Aug 10, compiled Nov 24 2016 22:32:42)
Included patches: 1-1829
Extra patches: 8.0.0056
 errorformat=%-G%.%#Underfull%.%#,%-G%.%#Overfull%.%#,%-G%.%#specifier changed to%.%#,%-G%.%#You ha
ve requested%.%#,%-G%.%#Missing number%\, treated as zero.%.%#,%-G%.%#There were undefined reference
s%.%#,%-G%.%#Citation %.%# undefined%.%#,%E! LaTeX %trror: %m,%E! %m,%E%f:%l: %m,%+WLaTeX %.%#Warnin
g: %.%#line %l%.%#,%+W%.%# at lines %l--%*\d,%+WLaTeX %.%#Warning: %m,%+WPackage %.%#Warning: %m,%-Z
 [],%-Z,%-C(%.%#) %#%m on input line %l.,%-C(%.%#) %#%m,%-Cl.%l %m,%-Cl.%l ,%-C  %m,%-C%.%#-%.%#,%-C
%.%#[]%.%#,%-C[]%.%#,%-C%.%#%[{}\]%.%#,%-C<%.%#>%m,%-GSee the LaTeX%m,%-GType  H <return>%m,%-G ...%
.%#,%-G%.%# (C) %.%#,%-G(see the transcript%.%#),%-G\s%#,%-O[%*\d]%r,%-Q %#)%r,%-Q %#[%\d%*[^()])%r,
%-Q %#])%r,%-O(%f)%r,%-P(%f%r,%-P%*[^()](%f%r,%-P(%f%*[^()],%-P[%\d%[^()]%#(%f%r,%-P(%f%r,%-Q)%r,%-O
(%f)%r,%-O[%*\d]%r,%-P(%f%r,%-Q)%r,%-O(%f)%r,%-O[%*\d]%r,%-P(%f%r,%-Q)%r,%-O(%f)%r,%-O[%*\d]%r,%-P(%
f%r,%-Q)%r,%-O(%f)%r,%-O[%*\d]%r,%-O[%*\d,%-O,%-G%.%#,%-O%.%# 

@gerw
Copy link
Contributor

gerw commented Jan 23, 2017

You can reload the errors by:

:set ef=test.log
:cg
:copen

It would be very nice if you could locate the problem in your log files. For debugging, I recommend to delete blocks in the log-file (dab is your friend) until the errors/warnings are recognized correctly, then you can back-track.

Again, your example with warnings works fine for me. For compiling, I can use both

max_print_line=1024 pdflatex --file-line-error --interaction=nonstopmode test.tex

and

max_print_line=1024 pdflatex --interaction=nonstopmode test.tex

In both cases, errors and warnings are recognized correctly.

@rekka
Copy link

rekka commented Jan 23, 2017

OK, this is strange. Just running :cg after compilation without touching the log file fixes the errors and warnings. That is, after compilation the location of warnings is wrong, running :cg fixes the location...

Tried this both on Ubuntu with GVim and macOS 10.12 with MacVim, the same behavior, even if I disable all other plugins. I'm using vim-plug for plugin installation.

@gerw
Copy link
Contributor

gerw commented Jan 23, 2017

Thank you for your answer. Indeed, if I compile with \ll (I never do this!), I see the same problem. I will have a look.

@rekka
Copy link

rekka commented Jan 23, 2017

Thank you so much for your time.

@gerw
Copy link
Contributor

gerw commented Jan 23, 2017

Using \ll uses the output of pdflatex, whereas :cg reads the log-file and both are different...

For me, I fixed this, by replacing the 3 on https://github.com/vim-latex/vim-latex/blob/master/compiler/tex.vim#L331 by 5 (4 was not enough).
Can you confirm this?

For the record, one can save the output of \ll by

:set mef=test.make.log
:au QuickfixCmdPost make !cp test.make.log test.Make.log
\ll

@rekka
Copy link

rekka commented Jan 24, 2017

Does not seem to work for me even with 5 even in the 2nd test case, picks up the wrong file:

\documentclass{article}
\usepackage{graphicx}
\begin{document}
\input{other.tex}
\ref{none}
\end{document}

Currently running :cg after compiling with max_print_line=1024, which seems to work for now.

@gerw
Copy link
Contributor

gerw commented Jan 24, 2017

This is weird. Can you compare the output of pdflatex called by \ll (see above) with the log-file?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants