3

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.

\documentclass[12pt,a4paper,twoside,openright,titlepage]{book}
\usepackage[subpreambles=true]{standalone}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[italian,english]{babel}
\usepackage{siunitx}
\usepackage{csquotes}
\MakeOuterQuote{"}
\usepackage{microtype}
\usepackage[binding=5mm]{layaureo}
\usepackage{calc}
\usepackage[strict]{changepage}
\usepackage{import}
\usepackage[hidelinks]{hyperref}
\usepackage{tocbibind}
\usepackage[overload]{empheq}
\renewcommand{\thefootnote}{\fnsymbol{footnote}}

% CAPTIONS settings
\usepackage{caption}
\captionsetup{tableposition=top,figureposition=bottom,font=small}

% HEADERS settings
\usepackage{fancyhdr}
\pagestyle{fancy}
\renewcommand{\chaptermark}[1]{\markboth{\thechapter.\ #1}{}}
\renewcommand{\sectionmark}[1]{\markright{\thesection\ #1}{}}
\fancyhead{}
\fancyhead[RO,LE]{\thepage}
\fancyhead[CE]{\nouppercase{\small{\leftmark}}}
\fancyhead[CO]{\nouppercase{\small{\rightmark}}}
\fancyfoot{}

% TITLES settings
\usepackage{titlesec}
\titleformat{\chapter}[display]
    {\Huge \bfseries}
    {\flushright \chaptername \ \thechapter}
    {40pt}
    {\Huge \bfseries}

%BIBLIOGRAPHY settings
\usepackage[backend=biber,style=science,sorting=none,sortcites=true,maxnames=1,date=year,doi=false,isbn=false,url=true,useeditor=false]{biblatex}
\bibliography{/usr/local/texlive/texmf-local/bibtex/bib/local/library.bib}
\renewcommand{\autocite}[1]{\textsuperscript{\cite{#1}}}

\begin{document}
\pagenumbering{gobble}
\import{title_page/}{source}
\import{dedica/}{source}

\frontmatter
\pagenumbering{Roman}
\tableofcontents
\listoffigures

\mainmatter
\import{chapters/chapter_01/}{source}
\import{chapters/chapter_02/}{source}
\import{chapters/chapter_03/}{source}
\import{chapters/chapter_04/}{source}
\import{chapters/chapter_05/}{source}
\import{chapters/chapter_06/}{source}
\import{chapters/appendix_A/}{source}

\backmatter
\printbibliography[heading=bibintoc]
\end{document}

And now the appendix.

\documentclass[class=book,float=false,crop=false]{standalone}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{xcolor}
\usepackage{courier}

\definecolor{mygreen}{rgb}{0.133,0.545,0.133}
\definecolor{myviolet}{rgb}{0.627,0.125,0.941}

\usepackage{listings}
\lstset{basicstyle=\footnotesize\ttfamily,language=Matlab,numbers=left,breaklines=true,keywordstyle=\color{blue},commentstyle=\color{mygreen},numberstyle=\tiny\color{gray},stringstyle=\color{myviolet}
}
\usepackage[backend=biber]{biblatex}
\bibliography{/usr/local/texlive/texmf-local/bibtex/bib/local/library.bib}

\begin{document}
\appendix
\renewcommand\chaptername{Appendix}
\chapter{Implemented code}
The developed code is organized in multiple files. The analysis is called either invoking BLA BLA BLA

\lstinputlisting{/PATH/TO/FILE.m}

\end{document}

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 :)

3
  • Welcome to TeX.SE! What is the exact error message that you get?
    – Marijn
    Commented Nov 22, 2017 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
    Commented Nov 23, 2017 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). Commented Nov 24, 2017 at 7:39

1 Answer 1

2

I minimised your code to the following code

% main file
\documentclass{book}
\usepackage[subpreambles=true]{standalone}
\begin{document}
\input{appendix}
\end{document}

.

% appendix.tex
\documentclass[crop=false]{standalone}
\usepackage{listings}
\begin{document}
\lstinputlisting{t402620.tex}
\end{document}

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.

2
  • 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
    Commented Nov 24, 2017 at 9:56
  • Ok, I just tried and it worked. Thank you very much!
    – Sandro
    Commented Nov 24, 2017 at 10:19

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .