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?

  • 3
    Have you deleted the .aux-file?
    – Toscho
    Commented Mar 6, 2014 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}. Commented Mar 6, 2014 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 ;) Commented Mar 6, 2014 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
    Commented Mar 6, 2014 at 20:10
  • 3
    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
    Commented Mar 6, 2014 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:

\usepackage{mwe}% http://ctan.org/pkg/lipsum

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

Document Class: article 2007/10/19 v1.4h Standard LaTeX document class
File: size10.clo 2007/10/19 v1.4h Standard LaTeX file (size option)
) (/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)
Package: graphicx 1999/02/16 v1.0f Enhanced LaTeX Graphics (DPC,SPQR)
Package: keyval 1999/03/16 v1.13 key=value parser (DPC)
) (/usr/local/texlive/2013/texmf-dist/tex/latex/graphics/graphics.sty
Package: graphics 2009/02/05 v1.0o Standard LaTeX Graphics (DPC,SPQR)
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.
File: pdftex.def 2011/05/27 v0.06d Graphics/color for pdfTeX
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)
) (/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
) (/usr/local/texlive/2013/texmf-dist/tex/latex/blindtext/blindtext.sty
Package: blindtext 2012/01/06 V2.0 blindtext-Package
Package: xspace 2009/10/20 v1.13 Space after command names (DPC,MH)
)) (/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.
[Loading MPS to PDF converter (version 2006.09.02).]
) (/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
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
Package: grfext 2010/08/19 v1.1 Manage graphics extensions (HO)
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)
Package: kvsetkeys 2012/04/25 v1.16 Key value parser (HO)
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
(grfext)             \AppendGraphicsExtensions on input line 452.
File: epstopdf-sys.cfg 2010/07/13 v1.3 Configuration of (r)epstopdf for TeX Liv
)) [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:


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.

  • 3
    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, ...). Commented Mar 6, 2014 at 21:23
  • @HeikoOberdiek: Great observation!
    – Werner
    Commented Mar 6, 2014 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).

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .