# File ended while scanning use of \@new l@bel [closed]

I've been running into this weird issue using TeXShop. Whenever I compile LaTeX and get an error, the output tells me where it is. So I fix it ... and recompile. But then I get this:

File ended while scanning use of \@new l@bel

According to the discussion here, I can fix this temporarily by trashing the aux file and recompiling. But that's not an optimal situation because then every time I make a tiny error, I have to re-trash my aux file before getting the compilation to proceed smoothly.

By moving my \end{document} code, I was able to locate the problem in my document:

% [Other text up here...]
\vspace{10 pt}
\noindent \textbf{My Thoughts}: Well, that was interesting.

% This part is the problem!
\chapter{Multivariable Calculus}
\label{2chapter:2}

\textbf{General Idea}: This is the study of [...]
% [Other text down here...]


But I can't figure out why this label is giving me the problem. I put \end{document} directly under this, tried to make a random error (I put a $by itself), then deleted it, and came up with the error in the title. If I put \end{document} above this text and repeat the process of putting a$ by itself, I can delete it and compile LaTeX normally.

In fact, I also tried this trick with \end{document} at its normal spot. If I put that dollar sign above the line with 'Multivariable Calculus' it works as expected (i.e. error upon compiling, but works fine after I delete it), but if the dollar sign is below that line, I compile (get an error) and upon deleting that sign I get the error again (file ended while scanning, etc.)!

Here's the final few lines of the aux file that got created when I saw this error. I'm convinced that the problem is with the label here, or with the label assigned to the previous chapter (Single Variable Calculus).

\@writefile{toc}{\contentsline {chapter}{\numberline {12}Operating Systems}{29} {chapter.12}}
\newlabel{1chapter:12}{{12}{29}{Operating Systems\relax }{chapter.12}{}}
\@writefile{toc}{\contentsline {part}{II\hspace  {1em}Mathematics}{31}{part.2}}
\@writefile{toc}{\contentsline {chapter}{\numberline {13}Single Variable Calculus}{33}{chapter.13}}
\newlabel{2cha


What's confusing, though, is that all these labels are quite similar. I'm writing a book and I have formatted it so there would be a bunch of chapters, and each chapter gets a label where the label name is Xchapter:Y where X is the "part" number (2 in this case, which corresponds to "Mathematics"), and Y is the numbering of that chapter within that part (Y=2 here, so the Multivariable Calculus chapter is the second chapter in its part). Is there a problem with the way I'm labeling things?

In case this is helpful, here's part of the preamble (my preamble is about 100 lines long, but I commented out most of it and it doesn't seem to be giving me problems).

\documentclass[10pt,notitlepage]{book}
\usepackage{amssymb,amsmath,graphicx,url,enumitem,tikz}
\usepackage{exercise}
\usepackage{hyperref}
\usepackage{makeidx}
\usepackage[bottom]{footmisc}
\usetikzlibrary{arrows}
\usepackage[left=1in,top=1in,right=1in,bottom=1in]{geometry}

\makeindex

\makeatletter
\newcommand*{\toccontents}{\@starttoc{toc}}
\makeatother


Let me know if there's anything else you would need to understand this. I'm new here and not sure how much information is too much, and this post is already getting long enough as it is.

UPDATE

Okay, so I've managed to trim down the document considerably. If you copy and paste the following text, and experiment with creating random errors before and after the Multivariable Calculus text, you should see some 'file ended while scanning ...'

\documentclass[10pt,notitlepage]{book}
\usepackage{amssymb,amsmath,graphicx,url,enumitem,tikz}
\usepackage{exercise}
\usepackage{hyperref}
\usepackage{makeidx}
\usepackage[bottom]{footmisc}
\usetikzlibrary{arrows}
\usepackage[left=1in,top=1in,right=1in,bottom=1in]{geometry}

\makeindex

\makeatletter
\newcommand*{\toccontents}{\@starttoc{toc}}
\makeatother

\title{Important Stuff}

\begin{document}
\maketitle
\newpage
\vspace*{2 cm}
\textbf{\huge{Contents}}
\vspace{2 cm}
\toccontents

\newpage
\section{Introduction}

\part{Computer Science}
\label{part:1}

\chapter{Introduction to Computer Science}
\label{1chapter:1}

\label{1chapter:2}

\chapter{Computer Organization}
\label{1chapter:3}

\chapter{Algorithm Design and Analysis}
\label{1chapter:4}

\chapter{Principles of Programming Languages}
\label{1chapter:5}

\chapter{Computer Graphics}
\label{1chapter:6}

\chapter{Theory of Computation}
\label{1chapter:7}

\chapter{Machine Learning}
\label{1chapter:8}

\chapter{Artificial Intelligence}
\label{1chapter:9}

\chapter{Compiler Design}
\label{1chapter:10}

\chapter{Distributed Systems}
\label{1chapter:11}

\chapter{Operating Systems}
\label{1chapter:12}

\part{Mathematics}

\chapter{Single Variable Calculus}
\label{2chapter:1}

\chapter{Multivariable Calculus}
\label{2chapter:2}

\chapter{Linear Algebra}
\label{2chapter:3}

\clearpage
\printindex

\end{document}


## closed as unclear what you're asking by Joseph Wright♦Aug 11 '13 at 19:24

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

• @TakeS: It is obvious that your .aux is truncated prematurely during an erroneous compilation. As such, \newlabel is not fully written (out has the form \newlabel{<label>}{{<1>}{<2>}{<3>}{<4>}{<5>}} since you're loading hyperref), but how/why? A minimal working example (MWE) is something that can be replicated. Understandably this is difficult when working with a very large document. However, always try and put yourself in the shoes of the community. We want to be able to copy-and-paste the code and see what's happening. – Werner May 24 '13 at 18:35
• @DavidCarlisle and barbara beeton, if I delete the .aux file, all is good ... until I happen to cause another error in LaTeX. Then instead of finding that error, fixing it, and recompiling, I have to first delete that .aux file again, fix the text, and then recompile. – TakeS May 24 '13 at 19:46
• Either you or your editor, when an error occurs are abruptly killing Tex while it is writing the command to the aux file so it ends up with a corrupt aux file. As the aux file is read in at the start of the next run that just generates more errors until you delete it. It should (almost always) be possible to quit tex after an error without doing that – David Carlisle May 24 '13 at 19:53
• Following David's comment, it would be useful if you can show us what you use to invoke TeX from your editor/command line, and perhaps how it is killed. – Bruno Le Floch May 24 '13 at 20:12
• @TakeS I'm having the same problem using TexShop on my Mac - whenever I make an error I have to delete the aux file before I can compile again – supercoolphysicist Jul 14 '15 at 16:59