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 tozref
, 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:While it includes only one package, it loads a whole host of files. Examining the
.log
showsTrimming 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.