Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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?

share|improve this question
2  
Have you deleted the .aux-file? –  Toscho Mar 6 at 15:47
1  
Welcome to TeX.SX! Please help us to help you and add a minimal working example (MWE) that illustrates your problem. It will be much easier for us to reproduce your situation and find out what the issue is when we see compilable code, starting with \documentclass{...} and ending with \end{document}. –  Henri Menke Mar 6 at 15:56
    
Strangely deleting the .aux file resolved the issue. I have no idea why that is, but it's good enough for me ;) –  Novice User Mar 6 at 16:04
1  
I wouldn't say "strangely", rather "quite obviously";). When I was about halfway through your question, I had the exact same suspicion. However, I have to admit that this behavior of LaTeX is quite baffling, well, for novice users;). –  mbork Mar 6 at 20:10
2  
Re: putting this on hold: I would definitely reopen this, the question needs rewording (maybe as community wiki), but (unless there's some duplicate) this may be a serious problem for many people, and having the answer somewhere on the internet (and why not here?) would be great. I voted for reopening. –  mbork Mar 6 at 20:12

2 Answers 2

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.

share|improve this answer
2  
I have doubts, that a recently removed zref is the reason. For this very reason package zref and many other of my packages provide the commands that are used in the .aux file at the begin of the .aux file. It's the reason for package auxhook. Also package zref does not know a \zref@n. But there is \zref@newlabel. Thus my guess would be a truncated .aux file (aborted TeX run process, ...). –  Heiko Oberdiek Mar 6 at 21:23
    
@HeikoOberdiek: Great observation! –  Werner Mar 6 at 21:24

In his answer Werner has shown in detail, how the file can be found that belongs to the line number in the error message. My guess is the .aux file, because deleting it has cured the problem.

\zref@n looks like a command of package zref. However, it does not define or know this command; it is not listed in the index of the package documentation. Also package zref provide command definitions at the very begin of the .aux files for the commands that are used by the package there.

Thus my guess is that \zref@n is a truncated command. A good candidate for the full name would be \zref@newlabel, the equivalent to \@newlabel that is written by LaTeX's \label.

A possible scenario:

  • Usually the output is buffered, when the .aux file is written. The last buffer written ends with \zref@n, the next buffer would start with ewlabel. Then the LaTeX run aborts, the computer is powered off, while the write cache is not yet cleared, the disk is full, ... -> The result is a truncated .aux file.

  • The next LaTeX run reads the .aux file at \begin{document}. Without errors, it would delete the .aux file by opening a fresh .aux file for writing. It gets then filled during the rest of the document body.

  • However, if during the first read, LaTeX does not continue (the user pressed x, for example), then the problematic .aux file is kept and causing the same trouble in the next LaTeX run regardless, how the document body is changed. Even if the document is replaced by a simple "hello world" document. The reading of the .aux file in \begin{document} will continue causing the error.

Ways to deal with such sort of problems:

  • The removal of the auxiliary files cures the problem, because the unknown command because of a truncated .aux file vanishes.
  • Sometimes ignoring the error or pressing q for batch mode at the prompt of the error message can help. If LaTeX can continue its job, then it comes to the point, where the .aux file is reopened for writing and the old contents is cleared. Then the next LaTeX run has a new .aux file (hopefully without errors).
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.