[Tex/LaTex] Permanent “Undefined Control Sequence?”

errors

I'm incredibly confused, and I have absolutely no explanation for this whatsoever. I was happily going about writing my document, which had compiled just fine for weeks beforehand, when I added something minor and got this result:

! Undefined control sequence.
l.65 \zref@n

?

Ok, so I went to line 65. That line was a comment. Just to be sure, I deleted out the comment anyway, and got the exact same error. I deleted out the part which I had added, thus going back to a document that had compiled perfectly literally 5 minutes before. Same error.

Here's where it got weird. I deleted everything around line 65 as well (which was still part of my premable so it was some command definitions) – and got the exact same error! Now I'm really confused, so I deleted everything in my preamble except the bare minimum necessary (e.g. \documentclass and \begin{document}). Once again, the result was an undefined control sequence at line 65. Out of curiousity, I deleted the entire thing, replacing it with a simple Hello World document. Again – undefined control sequence at line 65 (which didn't even exist in the Hello World document, much less define a command)

I don't really know very much about LaTeX beyond how to create a relatively simple document, and google has not been particularly helpful on this subject. I'm completely stuck. Has anyone had any similar issue whatsoever?

Best Answer

TeX uses external files to manage its process of compilation. The reason for this is that it does a compile in a very straight-forward one-pass way, gobbling and typesetting on the fly. The only way you can therefore have a successful forward-looking reference, say, is to retro-actively correct it once you've established what it should be. TeX's way of managing this uses the auxiliary .aux. file. For more on this, see Understanding how references and labels work.

Here's what may have happened:

You used the zref package for something. zref is a cross-referencing package, and these references use the .aux extensively. So, something was written to the .aux that uses the functionality/interface known to zref, but to no other package and, perhaps, compilation was aborted writing an ill-formed control sequence \zref@n. You then removed \usepackage{zref} thinking it would not affect your document. However, by the time the .aux is being read in (at \begin{document}), zref-related content was still there from the last compile, and now is unknown to the compiler. The line number referenced in the .log/console would be line 65 inside the .aux file, not in your main file.*

The way around this is to start fresh, typically by deleting all auxiliary files and re-compiling.


* How would you know? Files included in your document are braced by (...) in the .log. For example, take the following minimal document:

\documentclass{article}
\usepackage{mwe}% http://ctan.org/pkg/lipsum
\begin{document}
\lipsum
\end{document}

While it includes only one package, it loads a whole host of files. Examining the .log shows

...
(/usr/local/texlive/2013/texmf-dist/tex/latex/base/article.cls
Document Class: article 2007/10/19 v1.4h Standard LaTeX document class
(/usr/local/texlive/2013/texmf-dist/tex/latex/base/size10.clo
File: size10.clo 2007/10/19 v1.4h Standard LaTeX file (size option)
)
\c@part=\count79
\c@section=\count80
\c@subsection=\count81
\c@subsubsection=\count82
\c@paragraph=\count83
\c@subparagraph=\count84
\c@figure=\count85
\c@table=\count86
\abovecaptionskip=\skip41
\belowcaptionskip=\skip42
\bibindent=\dimen102
) (/usr/local/texlive/2013/texmf-dist/tex/latex/mwe/mwe.sty
Package: mwe 2012/05/15 v0.3 Package to support minimal working examples (MWE)
(/usr/local/texlive/2013/texmf-dist/tex/latex/graphics/graphicx.sty
Package: graphicx 1999/02/16 v1.0f Enhanced LaTeX Graphics (DPC,SPQR)
(/usr/local/texlive/2013/texmf-dist/tex/latex/graphics/keyval.sty
Package: keyval 1999/03/16 v1.13 key=value parser (DPC)
\KV@toks@=\toks14
) (/usr/local/texlive/2013/texmf-dist/tex/latex/graphics/graphics.sty
Package: graphics 2009/02/05 v1.0o Standard LaTeX Graphics (DPC,SPQR)
(/usr/local/texlive/2013/texmf-dist/tex/latex/graphics/trig.sty
Package: trig 1999/03/16 v1.09 sin cos tan (DPC)
) (/usr/local/texlive/2013/texmf-dist/tex/latex/latexconfig/graphics.cfg
File: graphics.cfg 2010/04/23 v1.9 graphics configuration of TeX Live
)
Package graphics Info: Driver file: pdftex.def on input line 91.
(/usr/local/texlive/2013/texmf-dist/tex/latex/pdftex-def/pdftex.def
File: pdftex.def 2011/05/27 v0.06d Graphics/color for pdfTeX
(/usr/local/texlive/2013/texmf-dist/tex/generic/oberdiek/infwarerr.sty
Package: infwarerr 2010/04/08 v1.3 Providing info/warning/error messages (HO)
) (/usr/local/texlive/2013/texmf-dist/tex/generic/oberdiek/ltxcmds.sty
Package: ltxcmds 2011/11/09 v1.22 LaTeX kernel commands for general use (HO)
)
\Gread@gobject=\count87
))
\Gin@req@height=\dimen103
\Gin@req@width=\dimen104
) (/usr/local/texlive/2013/texmf-dist/tex/latex/lipsum/lipsum.sty
Package: lipsum 2011/04/14 v1.2 150 paragraphs of Lorem Ipsum dummy text
\c@lips@count=\count88
) (/usr/local/texlive/2013/texmf-dist/tex/latex/blindtext/blindtext.sty
Package: blindtext 2012/01/06 V2.0 blindtext-Package
(/usr/local/texlive/2013/texmf-dist/tex/latex/tools/xspace.sty
Package: xspace 2009/10/20 v1.13 Space after command names (DPC,MH)
)
\c@blindtext=\count89
\c@Blindtext=\count90
\c@blind@countparstart=\count91
\blind@countxx=\count92
\blindtext@numBlindtext=\count93
\blind@countyy=\count94
\c@blindlist=\count95
\c@blindlistlevel=\count96
\c@blindlist@level=\count97
\blind@listitem=\count98
\c@blind@listcount=\count99
\c@blind@levelcount=\count100
\blind@mathformula=\count101
\blind@Mathformula=\count102
\c@blind@randomcount=\count103
\c@blind@randommax=\count104
\c@blind@pangramcount=\count105
\c@blind@pangrammax=\count106
)) (/compile/output.aux)
\openout1 = `output.aux'.

LaTeX Font Info:    Checking defaults for OML/cmm/m/it on input line 3.
LaTeX Font Info:    ... okay on input line 3.
LaTeX Font Info:    Checking defaults for T1/cmr/m/n on input line 3.
LaTeX Font Info:    ... okay on input line 3.
LaTeX Font Info:    Checking defaults for OT1/cmr/m/n on input line 3.
LaTeX Font Info:    ... okay on input line 3.
LaTeX Font Info:    Checking defaults for OMS/cmsy/m/n on input line 3.
LaTeX Font Info:    ... okay on input line 3.
LaTeX Font Info:    Checking defaults for OMX/cmex/m/n on input line 3.
LaTeX Font Info:    ... okay on input line 3.
LaTeX Font Info:    Checking defaults for U/cmr/m/n on input line 3.
LaTeX Font Info:    ... okay on input line 3.
(/usr/local/texlive/2013/texmf-dist/tex/context/base/supp-pdf.mkii
[Loading MPS to PDF converter (version 2006.09.02).]
\scratchcounter=\count107
\scratchdimen=\dimen105
\scratchbox=\box26
\nofMPsegments=\count108
\nofMParguments=\count109
\everyMPshowfont=\toks15
\MPscratchCnt=\count110
\MPscratchDim=\dimen106
\MPnumerator=\count111
\makeMPintoPDFobject=\count112
\everyMPtoPDFconversion=\toks16
) (/usr/local/texlive/2013/texmf-dist/tex/generic/oberdiek/pdftexcmds.sty
Package: pdftexcmds 2011/11/29 v0.20 Utility functions of pdfTeX for LuaTeX (HO
)
(/usr/local/texlive/2013/texmf-dist/tex/generic/oberdiek/ifluatex.sty
Package: ifluatex 2010/03/01 v1.3 Provides the ifluatex switch (HO)
Package ifluatex Info: LuaTeX not detected.
) (/usr/local/texlive/2013/texmf-dist/tex/generic/oberdiek/ifpdf.sty
Package: ifpdf 2011/01/30 v2.3 Provides the ifpdf switch (HO)
Package ifpdf Info: pdfTeX in PDF mode is detected.
)
Package pdftexcmds Info: LuaTeX not detected.
Package pdftexcmds Info: \pdf@primitive is available.
Package pdftexcmds Info: \pdf@ifprimitive is available.
Package pdftexcmds Info: \pdfdraftmode found.
) (/usr/local/texlive/2013/texmf-dist/tex/latex/oberdiek/epstopdf-base.sty
Package: epstopdf-base 2010/02/09 v2.5 Base part for package epstopdf
(/usr/local/texlive/2013/texmf-dist/tex/latex/oberdiek/grfext.sty
Package: grfext 2010/08/19 v1.1 Manage graphics extensions (HO)
(/usr/local/texlive/2013/texmf-dist/tex/generic/oberdiek/kvdefinekeys.sty
Package: kvdefinekeys 2011/04/07 v1.3 Define keys (HO)
)) (/usr/local/texlive/2013/texmf-dist/tex/latex/oberdiek/kvoptions.sty
Package: kvoptions 2011/06/30 v3.11 Key value format for package options (HO)
(/usr/local/texlive/2013/texmf-dist/tex/generic/oberdiek/kvsetkeys.sty
Package: kvsetkeys 2012/04/25 v1.16 Key value parser (HO)
(/usr/local/texlive/2013/texmf-dist/tex/generic/oberdiek/etexcmds.sty
Package: etexcmds 2011/02/16 v1.5 Avoid name clashes with e-TeX commands (HO)
Package etexcmds Info: Could not find \expanded.
(etexcmds)             That can mean that you are not using pdfTeX 1.50 or
(etexcmds)             that some package has redefined \expanded.
(etexcmds)             In the latter case, load this package earlier.
)))
Package grfext Info: Graphics extension search list:
(grfext)             [.pdf,.png,.jpg,.mps,.jpeg,.jbig2,.jb2,.PNG,.PDF,.JPG,.JPE
G,.JBIG2,.JB2,.eps]
(grfext)             \AppendGraphicsExtensions on input line 452.
(/usr/local/texlive/2013/texmf-dist/tex/latex/latexconfig/epstopdf-sys.cfg
File: epstopdf-sys.cfg 2010/07/13 v1.3 Configuration of (r)epstopdf for TeX Liv
e
)) [1

{/usr/local/texlive/2013/texmf-var/fonts/map/pdftex/updmap/pdftex.map}] [2] (/c
ompile/output.aux) )
...

Trimming most of the output, you'll note the braced (nested) structure that highlights the packages in terms of their filenames using a (...) approach:

...
(output.tex
  (article.cls
    (size10.clo)
  )
  (mwe.sty
    (graphicx.sty
      (keyval.sty)
      (graphics.sty
        (trig.sty)
        (graphics.cfg)
        (pdftex.def
          (infwarerr.sty)
          (ltxcmds.sty)
        )
      )
    )
    (lipsum.sty)
    (blindtext.sty
      (xspace.sty)
    )
  )
  (output.aux)
  (supp-pdf.mkii)
  (pdftexcmds.sty
    (ifluatex.sty)
    (ifpdf.sty)
  )
  (epstopdf-base.sty
    (grfext.sty
      (kvdefinekeys.sty)
    )
    (kvoptions.sty
      (kvsetkeys.sty
        (etexcmds.sty)
      )
    )
    (epstopdf-sys.cfg)
  )
  (output.aux)
)
...

The first instance of output.aux is used to read in whatever was available from the previous compile. the second instance represents then it is being opened for writing during the current compile.