I am using TeXworks to try and create a PDF file. The problem is that it seems that the \tableofcontents is making the pdf generation fail. Here is part of my code which seems to be causing the trouble:

\tableofcontents
\thispagestyle{empty}
\clearpage


As soon as I remove that from the script, the pdf is generated. I am very new to LaTeX so I am definitely doing something that I shouldn't. Anyone can tell me what is there problem or where can I look?

I have reduced my code to this (and still managed to replicate the error

\documentclass[a4paper,12pt]{article}
\begin{document}

\tableofcontents

\clearpage

\setcounter{page}{1}
{\Huge Sample Text}
\section{Introduction}

\section{Background}

\section{Aims and Objectives}

\section{Rationale}

\section{Methodology}

\section{Work Packages}

\section{Relevance to Beneficiaries}

\section{Justification of resources}

\begin{thebibliography}{12}

\end{thebibliography}

\end{document}


The error I get:

{section}{\numberline{1}Introduction}{1} Thanks

-
please provide a minimal but complete example which produces the error. Your given code is error free. I guess, you don't add entry text to the TOC. For example, if this argument contains a macro, there might be a problem. –  Stefan Kottwitz Jan 10 '11 at 19:36
This code contains a spurious \end{bibliography} –  Seamus Jan 10 '11 at 20:25

In your edited question, the following code line raises an error:

\addtocontents{toc}


The second mandatory argument is missing: what text should be written to the TOC.

In the first code snippet it has been correct.

In the case that you would like to use \addtocontents in order to change the page style within the TOC, put the command into an argument and protect it:

\addtocontents{toc}{\protect\thispagestyle{empty}}

-
I am still getting the same error: {section}{\numberline{1}Introduction}{1} –  npinti Jan 10 '11 at 20:19
@npinti: As long as you don't post your code but some fictional code instead, I cannot really help you. Your code example doesn't contain Introduction like the error, for example. –  Stefan Kottwitz Jan 10 '11 at 20:25
The problem is that this is part of an assignment, so I can't throw my work on the net so as to avoid possible plagiarism issues. Despite the fact that I removed any section headers from my code, I am still getting that error. –  npinti Jan 10 '11 at 20:54
@npinti: You don't need to post your content. Just make a copy, remove prose content and formulas, shrink it to get it smaller as long as the error remains, then post it. Have a serious look at What is a minimal working example? to get help now and in the future. And did you follow the link in my first comment to the question? –  Stefan Kottwitz Jan 10 '11 at 21:12
@npinti: Delete the .toc file (if it still contains an error) and compile/typeset again. When I compile your current example, it brings no error, just a warning "Empty thebibliography environment". –  Stefan Kottwitz Jan 10 '11 at 22:05

I think that there was something wrong with the LaTeX installation. I tried parsing the document with a plugin available for eclipse (here). The document was parsed without any problems and the pdf was successfully generated.

-