texstudio-org / texstudio

TeXstudio is a fully featured LaTeX editor. Our goal is to make writing LaTeX documents as easy and comfortable as possible.
http://www.texstudio.org/
GNU General Public License v3.0
2.81k stars 345 forks source link

Wrong file name in error log #325

Open kbauer opened 6 years ago

kbauer commented 6 years ago

Environment

Related to older bugreport https://sourceforge.net/p/texstudio/bugs/577/

Expected behavior

Given the snippet (full example: foo.zip)

Microscopically, it can be a full causal response function,
\errmessage{POS1}
\sidenote{
  We assume a sum-convention for integrals
  ($f(\rr,\rr')g(\rr') \equiv \int\dr' f(\rr,\rr')g(\rr')$)
  and indices
  ($f_{ab}g_b \equiv \sum_b f_{ab}g_b$).
\errmessage{POS2}
}
\errmessage{POS3}

all error messages are expected to be reported for the same \include file.

Actual behavior

In the given context, the following output is produced:

! POS2.
<argument> ...m _b f_{ab}g_b$). \errmessage {POS2}

l.11 }

(That was another \errmessage.)

Underfull \hbox (badness 10000) in paragraph at lines 11--11
[]$[]$  \T2A/cmr/m/n/10 We as-
 []

Underfull \hbox (badness 2617) in paragraph at lines 11--11
\T2A/cmr/m/n/10 sume a sum-
 []

Underfull \hbox (badness 10000) in paragraph at lines 11--11
\T2A/cmr/m/n/10 convention
 []

Underfull \hbox (badness 10000) in paragraph at lines 11--11
\T2A/cmr/m/n/10 for in-te-grals
 []

Overfull \hbox (12.0719pt too wide) in paragraph at lines 11--11
[] [][]\OML/cmm/m/it/10 f\OT1/cmr/m/n/10 (\OT1/cmr/bx/n/10 r\OML/cmm/m/it/10 ; 
\OT1/cmr/bx/n/10 r[]\OT1/cmr/m/n/10 )\OML/cmm/m/it/10 g\OT1/cmr/m/n/10 (\OT1/cm
r/bx/n/10 r[]\OT1/cmr/m/n/10 )$\T2A/cmr/m/n/10 )
 []

Underfull \hbox (badness 10000) in paragraph at lines 11--11
\T2A/cmr/m/n/10 and in-dices
 []

Underfull \hbox (badness 10000) in paragraph at lines 11--11
\T2A/cmr/m/n/10 ($\OML/cmm/m/it/10 f[]g[] \OMS/cmsy/m/n/10 
 []

! POS3.
l.12 \errmessage{POS3}

(That was another \errmessage.)

) [1

and the second error-message is wrongly reported to be in the master file. The issue seems to be an unbalanced parenthesis occurs in the block

Overfull \hbox (12.0719pt too wide) in paragraph at lines 11--11
[] [][]\OML/cmm/m/it/10 f\OT1/cmr/m/n/10 (\OT1/cmr/bx/n/10 r\OML/cmm/m/it/10 ; 
\OT1/cmr/bx/n/10 r[]\OT1/cmr/m/n/10 )\OML/cmm/m/it/10 g\OT1/cmr/m/n/10 (\OT1/cm
r/bx/n/10 r[]\OT1/cmr/m/n/10 )$\T2A/cmr/m/n/10 )

A second unbalanced parenthesis was added to the log only due to the debug messages.

! POS2.
<argument> ...m _b f_{ab}g_b$). \errmessage {POS2}

Possible fix

Box warnings are likely candidates, since they contain snippets of low-level tex code. Their format always seems to be

Overfull \hbox (0.97472pt too wide) in paragraph at lines 34--38
yada yada yada
yada yada yada (varying number of lines, 1 to 4 usually)
 []

i.e. after the initial warning, I always see them ended by the string <space>[], followed by an empty line.

Unlike the <argument> example, where the log summary is fixed by simply fixing the first compilation error, the warnings cannot easily be fixed by the user.

kbauer commented 6 years ago

Another option would be to support the --file-line-error option, which outputs error messages in a C-Style format \:\:\.

Downsides:

See https://tex.stackexchange.com/questions/454474/

timhoffm commented 6 years ago

Thanks for the detailed report. Parsing log files is difficult because the do not distinguish between log structuring parentheses and context code. We have to use some heuristics in there and the parser is already quite complicated. We have to see how we can get this in.

kbauer commented 5 years ago

In most cases, supporting the --file-line-error format would help greatly. Sadly, Miktex currently omits the usual context information when this switch is used (see https://github.com/MiKTeX/miktex/issues/181).

Also, currently the switch doesn't affect warning messages (see https://github.com/MiKTeX/miktex/issues/230, though in this case TeXlive is equally affected).

The issue seems to be tricky, as some warnings are hardcoded, and some are written as highlevel LaTeX commands.

timhoffm commented 5 years ago

Thanks for the information on the current status. As long as --file-line-error doesn't work for all messages (including warnings) and addtionally adds context information, it's not worth going there.

kbauer commented 5 years ago

I encountered another, somewhat weird, case of the bug (v2.12.14):

Overfull \hbox (5.60309pt too wide) detected at line 561
 $\OT1/cmr/m/n/12 []\OT1/cmr/bx/n/12 P\OT1/cmr/m/n/12 (\OT1/cmr/bx/n/12 r\OML/
cmm/m/it/12 ; t\OT1/cmr/m/n/12 ) = [] [] []$  
 []

Having this warning in the log prevented correct attribution to the source file, even though it doesn't contain any unbalanced parentheses.

All manners of miniscule changes restored correct attribution to the included files, such as deleting the first line of the warning, removing the line break between the second and third lines, or removing the second and third lines. Removing the control character in the middle of the second line ( or ^A or 0x01), which is likely a unicode artifact, didn't make a difference.

The larger context of the (reduced) example was:

 (4_abini.tex
chapter 4.

[82]
Overfull \hbox (5.60309pt too wide) detected at line 561
 $\OT1/cmr/m/n/12 []\OT1/cmr/bx/n/12 P\OT1/cmr/m/n/12 (\OT1/cmr/bx/n/12 r\cmm/
m/OML/it/12 ; t\OT1/cmr/m/n/12 ) = [] [] []$  
 []
! Undefined control sequence.
l.797 ...ds and the number $N_{{\rm unocc}}\apprge
                                                   N_{{\rm bands}}-N_{{\rm o...
tmelorc commented 4 years ago

Any idea if this was solved? I'm getting some similar problem with the MWE below. What is strange is that the problem appears only when loading amsmath.

TeXstudio 3.00.00 (git n/a) Using Qt Version 5.11.1, compiled with Qt 5.11.1 R Linux Mint 18 with texlive 2020 updated

The Log panel shows the error \OML/cmm/m/it/10.95 H[]\OT1/cmr/m/n/10.95 (\OML/cmm/m/it/10.95 X[]\OT1/cmr/m/ and compilation stops.

The piece of code from log file is:

Overfull \hbox (29.54893pt too wide) in paragraph at lines 12--13
\T1/cmr/m/n/10.95 com ho-mo-mor-fis-mos $\OML/cmm/m/it/10.95 f[] [] [] H[]\OT1/
cmr/m/n/10.95 (\OML/cmm/m/it/10.95 X[]\OT1/cmr/m/n/10.95 ) \OMS/cmsy/m/n/10.95 
! \OML/cmm/m/it/10.95 H[]\OT1/cmr/m/n/10.95 (\OML/cmm/m/it/10.95 X[]\OT1/cmr/m/
n/10.95 )$ \T1/cmr/m/n/10.95 in-duzi-dos pelas in-clus�es $\OML/cmm/m/it/10.95 
H[]\OT1/cmr/m/n/10.95 (\OML/cmm/m/it/10.95 X[]\OT1/cmr/m/n/10.95 ) \OML/cmm/m/i
t/10.95 ,[]\OMS/cmsy/m/n/10.95 !
 []

MWE

\documentclass[11pt,a4paper]{report}
\usepackage{amsmath} %   <-------- no problem without this
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}

\begin{document}
Consideramos a sequência \[ 0=H_p(X_{a_0}) \to H_p(X_{a_1}) \to \dots \to H_p(X_{a_N}) \to \cdots \] com homomorfismos $f_i^j\colon H_p(X_{a_i})\to H_p(X_{a_j})$ induzidos pelas inclusões $H_p(X_{a_i})\hookrightarrow H_p(X_{a_j})$, para $a_i\leq a_j$.
\end{document}
muzimuzhi commented 4 years ago

@tmelorc

Short workaround

Since you are using TeX Live, just run tlmgr conf tlmgr max_print_line 2000 (or even larger number, latex-workshop uses 10000).

Edit Aug 31, 2020: You should run tlmgr conf texmf max_print_line 2000.

Long story

After complaining the overfull \hbox, TeX writes the expanded result of that overfull \hbox to log. The result contains \OMS/cmsy/m/n/10.95 !, which is the expansion of math command \to. Also, the result is so long that TeX splits it into multiple lines. By coincidence, one of the split line starts with ! (a "!" followed by a space), which is wrongly recognized as the beginning of a TeX error by TeXstudio. https://github.com/texstudio-org/texstudio/blob/6ff4aa3bb043155edad8114a36e36fd3b804fde6/src/latexoutputfilter.cpp#L633

I checked how latex-workshop, a popular LaTeX extension for Visual Studio Code, deals with this kind of problems, and find that it uses variable max_print_line to avoid long log lines being split. See implementation in latex-workshop's builder.ts, lines containing MaxPrintLine.

As long as TeX splits log lines, there could be anything appear at the beginning or ending of (split) log line, hence any regular expression might fail on corner cases. So I think setting max_print_line is a good idea. However, automatically setting max_print_line by editor is not that easy.

Information about max_print_line

In TeX Live, the value of max_print_line comes from a texmf.cnf config file, or an environment variable with the same name. The latter, if exists, overwrites the former.

# print current value
$ tlmgr conf texmf max_print_line
tlmgr: max_print_line not defined in texmf config file (/usr/local/texlive/2019basic/texmf.cnf)
tlmgr: texmf max_print_line default value: 79 (from kpsewhich -var-value)

# set new value (sudo is required on macOS)
$ tlmgr conf texmf max_print_line 200

# use as an env variable
$ max_print_line = 2000 pdflatex main.tex

latex-workshop always run something like max_print_line=10000 pdflatex main.tex, but this does not always work for MiKTeX.

In MiKTeX, both pdftex and xetex accept option --max-print-line=<num>, but luatex doesn't. See MiKTeX doc. Hence latex-workshop detects distribution and engine for whether using that option.

tmelorc commented 4 years ago

@muzimuzhi

Thanks a lot for the very detailed answer. I think I got the key point. Regards.

muzimuzhi commented 4 years ago

@tmelorc I made a mistake in https://github.com/texstudio-org/texstudio/issues/325#issuecomment-649918868. To set max_print_line, one should execute tlmgr conf texmf max_print_line 2000, noting the word following conf should be texmf instead of tlmgr.

If tlmgr conf tlmgrmax_print_line 2000 is executed, tlmgr will complains

tlmgr: /Users/guten/Library/texlive/2020basic/texmf-config/tlmgr/config: unknown tlmgr configuration variable: max_print_line

in every future executions.