LaTeX compiling error if more sections are added: "Undefined control sequence"

8,632

You seem to be trying to create a function to get the current chaptername and put that in the footer. The function caused some problems. Also, the function already exists. It is called \leftmark, which would in a report print the current chapter, and you also have \rightmark which prints the current section. In an article these would respectively be the section and the subsection.

Output

enter image description here

Code

\documentclass[11pt, twoside, draft]{report}

\usepackage[utf8]{inputenc}
\usepackage{graphicx}
\usepackage[a4paper,width=150mm,top=25mm,bottom=25mm,bindingoffset=6mm]{geometry}
\usepackage{fancyhdr}
\usepackage{subcaption}
\usepackage[numbers,sort&compress]{natbib}
\usepackage{color,soul}
\usepackage{xcolor}
\usepackage{pgfplots}
\usepackage{tikz}
\usepackage{booktabs}
\usepackage{tabularx}
\usepackage{longtable}
\usepackage{tabu}
\usepackage{array}
\usepackage{colortbl}
\usepackage{hyperref}
\usepackage{xr}
\usepackage{textcomp}
\usepackage{courier}
\usepackage{graphicx}
\usepackage{caption}

\captionsetup{font=footnotesize, labelfont=sc}
\graphicspath{ {images/} }
%\pagestyle{fancy}

\definecolor{bblue}{HTML}{A9D0F5}
\definecolor{lightbblue}{HTML}{CEF6EC}
\definecolor{darkbblue}{HTML}{4189F5}
\definecolor{ggreen}{HTML}{D8F6CE}
\definecolor{darkggreen}{HTML}{41F583}
\definecolor{verydarkggreen}{HTML}{31B404}
\definecolor{rred}{HTML}{F5A9A9}
\definecolor{verydarkrred}{HTML}{DF0101}
\definecolor{oorange}{HTML}{F5ECCE}
\definecolor{verydarkoorange}{HTML}{DF7401}
\usepackage{pgffor,lipsum}
% \def\tabularxcolumn#1{m{#1}} This is for vertical centering in tabularx.



%\input{Chapters/01_Title}

%\input{Chapters/02_Abstract}

\pagestyle{fancy}
%\let\Chaptermark\chaptermark
%\def\chaptermark#1{\def\Chaptername{#1}\Chaptermark{#1}}
\fancyhead{}
\fancyhead[L]{\small \emph{Title}}
\fancyhead[R]{\small Author name}
\fancyfoot{}
\fancyfoot[R]{\small \thepage}
\fancyfoot[L]{\small \itshape \leftmark.}

\begin{document}
\tableofcontents

\listoffigures

\listoftables


\chapter{Presentation}
\foreach \x in {1,...,50}{
\section{Sectiontitle}
\lipsum
}
%\externaldocument{Chapters/03_Presentation}
%\input{Chapters/03_Presentation}

\chapter{Introduction}
%\externaldocument{Chapters/04_Introduction}
%\input{Chapters/04_Introduction}

%\bibliographystyle{IEEEtran}
%\bibliography{References/Bibliography_report}

%\appendix

\chapter{Appendix}
%\externaldocument{Chapters/99_Appendix}
%\input{Chapters/99_Appendix}

\end{document}
Share:
8,632
Gerard.Ill
Author by

Gerard.Ill

Updated on August 15, 2022

Comments

  • Gerard.Ill
    Gerard.Ill 3 months

    After several hours of trying to find the error that was making the compilation fail:

    Undefined control sequence. \listoffigures
    

    Resulted that this error has nothing to relate to figures, neither tables.

    It seems that I have reached a section max number limit (yes, it seems incredible also for me): if add another \section{title} to any of the .tex files that are called in the project, the error of Undefined control sequence. will arise.

    And, curiously, this max number of sections seems to be the number of sections that fit in a single page of the Table of Contents:

    enter image description here

    So, I have no idea how to deal with this.

    I am stuck and I simply cannot add any more sections \section{title} to my .tex project.

    Code in the main document (which calls other .tex files that are very simple and contain only commands for sectioning, tables, figures, and tikz pictures with captions):

    \documentclass[11pt, twoside, draft]{report}
    
    \usepackage[utf8]{inputenc}
    \usepackage{graphicx}
    \usepackage[a4paper,width=150mm,top=25mm,bottom=25mm,bindingoffset=6mm]{geometry}
    \usepackage{fancyhdr}
    \usepackage{subcaption}
    \usepackage[numbers,sort&compress]{natbib}
    \usepackage{color,soul}
    \usepackage{xcolor}
    \usepackage{pgfplots}
    \usepackage{tikz}
    \usepackage{booktabs}
    \usepackage{tabularx}
    \usepackage{longtable}
    \usepackage{tabu}
    \usepackage{array}
    \usepackage{colortbl}
    \usepackage{hyperref}
    \usepackage{xr}
    \usepackage{textcomp}
    \usepackage{courier}
    \usepackage{graphicx}
    \usepackage{caption}
    
    \captionsetup{font=footnotesize, labelfont=sc}
    \graphicspath{ {images/} }
    \pagestyle{fancy}
    
    \definecolor{bblue}{HTML}{A9D0F5}
    \definecolor{lightbblue}{HTML}{CEF6EC}
    \definecolor{darkbblue}{HTML}{4189F5}
    \definecolor{ggreen}{HTML}{D8F6CE}
    \definecolor{darkggreen}{HTML}{41F583}
    \definecolor{verydarkggreen}{HTML}{31B404}
    \definecolor{rred}{HTML}{F5A9A9}
    \definecolor{verydarkrred}{HTML}{DF0101}
    \definecolor{oorange}{HTML}{F5ECCE}
    \definecolor{verydarkoorange}{HTML}{DF7401}
    % \def\tabularxcolumn#1{m{#1}} This is for vertical centering in tabularx.
    
    \pgfplotsset{every tick label/.append style={font={{\scriptsize}}}}
    \pgfplotsset{/pgf/number format/use comma}
    \pgfplotsset{compat=1.5}
    
    \input{Chapters/01_Title}
    
    \input{Chapters/02_Abstract}
    
    \pagestyle{fancy}
    \let\Chaptermark\chaptermark
    \def\chaptermark#1{\def\Chaptername{#1}\Chaptermark{#1}}
    \fancyhead{}
    \fancyhead[L]{\small \emph{Title}}
    \fancyhead[R]{\small Author name}
    \fancyfoot{}
    \fancyfoot[R]{\small \thepage}
    \fancyfoot[L]{\small \emph{Chapter \thechapter. \Chaptername.}}
    
    \tableofcontents
    
    \listoffigures
    
    \listoftables
    
    
    \chapter{Presentation}
    \externaldocument{Chapters/03_Presentation}
    \input{Chapters/03_Presentation}
    
    \chapter{Introduction}
    \externaldocument{Chapters/04_Introduction}
    \input{Chapters/04_Introduction}
    
    \bibliographystyle{IEEEtran}
    \bibliography{References/Bibliography_report}
    
    \appendix
    
    \chapter{Appendix}
    \externaldocument{Chapters/99_Appendix}
    \input{Chapters/99_Appendix}
    
    \end{document}
    

    Thank you in advance for your help.

    EDIT Nº1 This is the error log near to the ! indicator. [...]

    ] (./Report.toc
    LaTeX Font Info:    External font `cmex10' loaded for size
    (Font)              <10.95> on input line 2.
    LaTeX Font Info:    External font `cmex10' loaded for size
    (Font)              <8> on input line 2.
    LaTeX Font Info:    External font `cmex10' loaded for size
    (Font)              <6> on input line 2.
     [4
    
    ])
    \[email protected]=\write4
    \openout4 = `Report.toc'.
    
    
    ! Undefined control sequence.
    <argument> Chapter \thechapter . \Chaptername 
                                                  .
    l.95 \listoffigures
    
    The control sequence at the end of the top line
    of your error message was never \def'ed. If you have
    misspelled it (e.g., `\hobx'), type `I' and the correct
    spelling (e.g., `I\hbox'). Otherwise just continue,
    and I'll forget about whatever was undefined.
    
    [5] (./Report.lof)
    \[email protected]=\write5
    \openout5 = `Report.lof'.
    
     [6
    
    ] (./Report.lot
    Overfull \hbox (1.74966pt too wide) in paragraph at lines 4--4
     [][] []\OT1/cmr/m/n/10.95 Summary of power-trains used and/or de-vel-op-ment i
    n pas-sen-ger light-weight |
     []
    
    )
    \[email protected]=\write6
    \openout6 = `Report.lot'.
    
     [7
    
    ]
    Chapter 1.
    

    [...]

    By the way, this error has something to relate with the auxiliary files result of the compilation, because if get the error, and then I delete the sections that "exceed", I keep obtaining the same error. I need to erase all the auxiliary files, and then if I compile (respecting this apparent max number of sections in the .tex project), it works; but obviously I will need soon or later to add more sections.

    • David Carlisle
      David Carlisle over 6 years
      the error you show is not the format tex uses so you have not shown which command is undefined. Copy the exact error message from the log all the lines from ! to ? put in a code block in your question so linebreaks are preserved
    • Runar
      Runar over 6 years
      The error is becouse of the lines regarding chaptermark and Chaptername. What are you trying to do there? Removing those lines solves your problem.
    • David Carlisle
      David Carlisle over 6 years
      the error message which was not in your original question shows that the undefined command is \Chaptername which you are (rather strangely) defining in a local scope that does not include the list of figures.
    • David Carlisle
      David Carlisle over 6 years
      you need to fix (or delete) the chaptermark definition, then delete the corrupted Report.lof file and regenerate.