I am writing a document using multiple files. I've been using the standalone package without any problem until today. I need to create an appendix chapter containing some Matlab code, so I decided to use the listings package. However, now I am getting an error which prevents my bibliography, which comes afterwards, form being compiled. Basically now I can see my whole document down to the last page of this appendix, but no bibliography. I have no problem in compiling the standalone appendix, nor compiling the rest of the document without said chapter.

Here is my relevant code. First the main.tex file.


% CAPTIONS settings

% HEADERS settings
\renewcommand{\chaptermark}[1]{\markboth{\thechapter.\ #1}{}}
\renewcommand{\sectionmark}[1]{\markright{\thesection\ #1}{}}

% TITLES settings
    {\Huge \bfseries}
    {\flushright \chaptername \ \thechapter}
    {\Huge \bfseries}






And now the appendix.




\chapter{Implemented code}
The developed code is organized in multiple files. The analysis is called either invoking BLA BLA BLA



I simplified this last file neglecting lots of lstinputlinstings calls. This is because the error shows up even with just one input.

Thanks in advance to whoever will give some help :)

  • Welcome to TeX.SE! What is the exact error message that you get? – Marijn Nov 22 '17 at 21:55
  • @Marijn Hello! I get multiple errors actually. This morning I was able to recreate such errors using a minimal code, as explained in the listings manual. I therefore sent a bug report to the maintainer. However, since you might be able to help anyway, I report here the errors. They are all in the listings.sty file. Row 1576: "Undefined control sequence. \fi}" Row 1576: "Extra \else. \fi}" Row 1576: "Command \c@listings already defined. \fi}" Row 1576: "Extra \fi. \fi}" Thanks for your interest! – Sandro Nov 23 '17 at 7:29
  • Hi @Sandro, note that standalone is more intendent for diagrams etc. and not for whole chapters. Usually the \includeonly feature is good with compiling only single chapters (when they were \included). – Martin Scharrer Nov 24 '17 at 7:39

I minimised your code to the following code

% main file


% appendix.tex

Which gives me the error:

! Undefined control sequence.
<argument> ... \iffalse }{}\lst@ifnumberbychapter 
                                                  \newcounter {lstlisting}[c...
l.1576   \fi}

The problem here is that you are using the subpreambles option together with a verbatim package like listings. Something breaks when standalone copies the preamble of the subfile over to the main file. Removing subpreambles and coping the preamble of the appendix to the main file fixes the problem. I guess that is the way to go for now.

  • Hi! Thanks for your response! So, just to make sure I understood, should I remove the subpreambles option and move all the relevant preamble changes to my main file? – Sandro Nov 24 '17 at 9:56
  • Ok, I just tried and it worked. Thank you very much! – Sandro Nov 24 '17 at 10:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.