From the beginning, took me a lot of time to come with the following minimal example:
\PassOptionsToPackage{main=brazil,english,spanish,french}{babel}
\documentclass[
10pt,
a5paper,
]{memoir}
\makeatletter
\@ifpackagewith{babel}{english}{\message{English YES!^^J}}{\message{English NO!^^J}}
\@ifpackagewith{babel}{brazil}{\message{Brazil YES!^^J}}{\message{Brazil NO!^^J}}
\@ifpackagewith{babel}{turkish}{\message{Turkish YES!^^J}}{\message{Turkish NO!^^J}}
\@ifpackagewith{babel}{brazil}{\addto\captionsbrazil{\renewcommand{\lstlistingname}{Código}}}{}
\@ifpackagewith{babel}{english}{\addto\captionsenglish{\renewcommand{\lstlistingname}{Code}}}{}
\makeatother
\begin{document}
\chapter{Introduction}
Thing.
\end{document}
Runnning this example with:
'latexmk.exe' -cd -f -pdf -interaction=nonstopmode -synctex=1 '--output-directory=cache' -latexoption=-file-line-error -latexoption=-halt-on-error -latexoption=--max-print-line=10000 test1.tex
$ tex --version
MiKTeX-TeX 2.9.6300 (3.14159265) (MiKTeX 2.9.6400)]
...
Package tabularx [2008/07/23] emulated by memoir.
Package titleref [2008/07/23] emulated by memoir.
Package titling [2008/07/23] emulated by memoir.
Package tocbibind [2008/07/23] emulated by memoir.
Package tocloft [2008/07/23] emulated by memoir.
Package tocvsec2 [2008/07/23] emulated by memoir.
Package verbatim [2008/07/23] emulated by memoir.
Package verse [2008/07/23] emulated by memoir.
(D:\User\Documents\latex\texmfs\install\tex\latex\memoir\mempatch.sty
Package: mempatch 2009/07/24 v6.0f Patches for memoir class v1.6180339
)) English YES!
Brazil NO!
Turkish NO!
test1.tex:17: Undefined control sequence
Here is how much of TeX's memory you used:
3506 strings out of 493314
47031 string characters out of 3134142
129114 words of memory out of 3000000
7118 multiletter control sequences out of 15000+200000
4238 words of font info for 16 fonts, out of 3000000 for 9000
1141 hyphenation exceptions out of 8191
24i,1n,22p,129b,62s stack positions out of 5000i,500n,10000p,200000b,50000s
test1.tex:17: ==> Fatal error occurred, no output PDF file produced!
Latex does not tell me on its log which command is not defined. It only says Undefined control sequence, which is very much useless.
How can I make latex tell me exactly which command he is not finding defined?
Only after a lot of trying, I figured out that the ifpackagewith does not check whether the package is loaded. It only checks whether there is some option on the package name queue.
Then, a fixed version is:
\makeatletter
\@ifpackageloaded{babel}{\@ifpackagewith{babel}{english}{\message{English YES!^^J}}{\message{English NO!^^J}}}{}
\@ifpackageloaded{babel}{\@ifpackagewith{babel}{brazil}{\message{Brazil YES!^^J}}{\message{Brazil NO!^^J}}}{}
\@ifpackageloaded{babel}{\@ifpackagewith{babel}{turkish}{\message{Turkish YES!^^J}}{\message{Turkish NO!^^J}}}{}
\@ifpackageloaded{babel}{\@ifpackagewith{babel}{brazil}{\addto\captionsbrazil{\renewcommand{\lstlistingname}{Código}}}{}}{}
\@ifpackageloaded{babel}{\@ifpackagewith{babel}{english}{\addto\captionsenglish{\renewcommand{\lstlistingname}{Code}}}{}}{}
\makeatother
Or just load the babel package with \RequirePackage{babel}.
Now, forgetting about the fix, which is load babel or use \@ifpackageloaded. Why latex does not tell me which command was undefined from the beginning???
If I remove the -latexoption=-halt-on-error, then, latex tells me the command \lstlistingname is undefined, but that is the WRONG command. The command which is undefined is \add\to\captions from babel package, which was not loaded.
See here the output from latex:
'latexmk.exe' -cd -f -pdf -interaction=nonstopmode -synctex=1 '--output-directory=cache' -latexoption=-file-line-error -latexoption=--max-print-line=10000 test1.tex
x\memoir\mempatch.sty)) English YES!
Brazil NO!
Turkish NO!
test1.tex:15: Undefined control sequence
test1.tex:15: Undefined control sequence
test1.tex:15: LaTeX Error: \lstlistingname undefined.
See the LaTeX manual or LaTeX Companion for explanation.
Type H <return> for immediate help
If I remove the \lstlistingname from the input program like this:
\makeatletter
\@ifpackagewith{babel}{english}{\message{English YES!^^J}}{\message{English NO!^^J}}
\@ifpackagewith{babel}{brazil}{\message{Brazil YES!^^J}}{\message{Brazil NO!^^J}}
\@ifpackagewith{babel}{turkish}{\message{Turkish YES!^^J}}{\message{Turkish NO!^^J}}
\@ifpackagewith{babel}{brazil}{\addto\captionsbrazil{}}{}
\@ifpackagewith{babel}{english}{\addto\captionsenglish{}}{}
\makeatother
And run back latex again, without the -interaction=nonstopmode and -latexoption=-halt-on-error, then, latex tells me absolutely nothing about which command is undefined!
'latexmk.exe' -cd -f -pdf '--output-directory=cache' -latexoption=-file-line-error -latexoption=--max-print-line=10000 test1.tex
Latexmk: This is Latexmk, John Collins, 19 Jan. 2017, version: 4.52c.
Latexmk: Changing directory to './'
Latexmk: making output directory 'cache'
Latexmk: applying rule 'pdflatex'...
Rule 'pdflatex': Rules & subrules not known to be previously run:
pdflatex
Rule 'pdflatex': The following rules & subrules became out-of-date:
'pdflatex'
------------
Run number 1 of rule 'pdflatex'
------------
------------
Running 'pdflatex -file-line-error --max-print-line=10000 -recorder -output-directory="cache" "test1.tex"'
------------
This is pdfTeX, Version 3.14159265-2.6-1.40.18 (MiKTeX 2.9.6400)
entering extended mode
(test1.tex
LaTeX2e <2017-04-15>
Babel <3.12> and hyphenation patterns for 76 language(s) loaded.
(D:\User\Documents\latex\texmfs\install\tex\latex\memoir\memoir.cls
Document Class: memoir 2016/05/16 v3.7f configurable book, report, article document class
(D:\User\Documents\latex\texmfs\install\tex\generic\oberdiek\ifpdf.sty) (D:\User\Documents\latex\texmfs\install\tex\latex\ifetex\ifetex.sty (D:\User\Documents\latex\texmfs\install\tex\plain\ifetex\ifetex.tex)) (D:\User\Documents\latex\texmfs\install\tex\generic\ifxetex\ifxetex.sty) (D:\User\Documents\latex\texmfs\install\tex\generic\oberdiek\ifluatex.sty) (D:\User\Documents\latex\texmfs\install\tex\latex\memoir\mem10.clo) (D:\User\Documents\latex\texmfs\install\tex\latex\memoir\mempatch.sty)) English YES!
Brazil NO!
Turkish NO!
test1.tex:15: Undefined control sequence
test1.tex:15: Undefined control sequence
(D:\Test\cache\test1.aux) [1{D:/User/Documents/latex/texmfs/data/pdftex/config/pdftex.map}] (D:\Test\cache\test1.aux) )
(see the transcript file for additional information)<D:/User/Documents/latex/texmfs/install/fonts/type1/public/amsfonts/cm/cmbx12.pfb><D:/User/Documents/latex/texmfs/install/fonts/type1/public/amsfonts/cm/cmr10.pfb>
Output written on D:\Test\cache\test1.pdf (1 page, 21716 bytes).
Transcript written on D:\Test\cache\test1.log.
=== TeX engine is 'pdfTeX'
Latexmk: Log file says output to 'cache/test1.pdf'
Latexmk: applying rule 'pdflatex'...
Rule 'pdflatex': File changes, etc:
Changed files, or newly in use since previous run(s):
'cache/test1.aux'
------------
Run number 2 of rule 'pdflatex'
------------
------------
Running 'pdflatex -file-line-error --max-print-line=10000 -recorder -output-directory="cache" "test1.tex"'
------------
This is pdfTeX, Version 3.14159265-2.6-1.40.18 (MiKTeX 2.9.6400)
entering extended mode
(test1.tex
LaTeX2e <2017-04-15>
Babel <3.12> and hyphenation patterns for 76 language(s) loaded.
(D:\User\Documents\latex\texmfs\install\tex\latex\memoir\memoir.cls
Document Class: memoir 2016/05/16 v3.7f configurable book, report, article document class
(D:\User\Documents\latex\texmfs\install\tex\generic\oberdiek\ifpdf.sty) (D:\User\Documents\latex\texmfs\install\tex\latex\ifetex\ifetex.sty (D:\User\Documents\latex\texmfs\install\tex\plain\ifetex\ifetex.tex)) (D:\User\Documents\latex\texmfs\install\tex\generic\ifxetex\ifxetex.sty) (D:\User\Documents\latex\texmfs\install\tex\generic\oberdiek\ifluatex.sty) (D:\User\Documents\latex\texmfs\install\tex\latex\memoir\mem10.clo) (D:\User\Documents\latex\texmfs\install\tex\latex\memoir\mempatch.sty)) English YES!
Brazil NO!
Turkish NO!
test1.tex:15: Undefined control sequence
test1.tex:15: Undefined control sequence
(D:\Test\cache\test1.aux) [1{D:/User/Documents/latex/texmfs/data/pdftex/config/pdftex.map}] (D:\Test\cache\test1.aux) )
(see the transcript file for additional information)<D:/User/Documents/latex/texmfs/install/fonts/type1/public/amsfonts/cm/cmbx12.pfb><D:/User/Documents/latex/texmfs/install/fonts/type1/public/amsfonts/cm/cmr10.pfb>
Output written on D:\Test\cache\test1.pdf (1 page, 21716 bytes).
Transcript written on D:\Test\cache\test1.log.
=== TeX engine is 'pdfTeX'
Latexmk: Log file says output to 'cache/test1.pdf'
Latexmk: Errors, in force_mode: so I tried finishing targets
Collected error summary (may duplicate other messages):
pdflatex: Command for 'pdflatex' gave return code 1
Refer to 'cache/test1.log' for details
Latexmk: Undoing directory change
Why latex does not tell which command is not defined? Does it hurt him? Is he afraid it is too much information and I cannot handle it by myself???
Is there some fix I can apply to latex, so it starts telling me which commands is not defined when there is some error?
References:
latexmkbutpdflatextells me\addtois undefined. – Symbol 1 Apr 20 '19 at 23:41latexmk, it does not show complete error message. If you want to see complete error messages run pdflatex, bibtex, biber seperatly ... – Mensch Apr 21 '19 at 02:11-file-line-errorfails to include the second part of the error message, which in this case would tell you which command sequence is undefined. As far as I can see this is specific to MikTeX's version of the TeX binaries and using-file-line-error. – moewe Apr 21 '19 at 05:03-file -line-erroruntil it is fixed. – David Carlisle Apr 21 '19 at 08:20