列表和独立包的问题

列表和独立包的问题

我正在使用多个文件编写文档。直到今天,我一直在使用独立包,没有任何问题。我需要创建一个包含一些 Matlab 代码的附录章节,因此我决定使用 listings 包。但是,现在我收到一个错误,导致无法编译随后出现的参考书目。基本上,现在我可以看到整个文档,直到本附录的最后一页,但没有参考书目。我可以毫无问题地编译独立附录,也可以毫无问题地编译没有该章节的其余文档。

这是我的相关代码。首先是 main.tex 文件。

\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}

现在讨论附录。

\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}

我简化了最后一个文件,忽略了许多lstinputlinstings调用。这是因为即使只有一个输入,错误也会出现。

在此先感谢所有提供帮助的人:)

答案1

我将您的代码最小化为以下代码

% 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}

这给了我错误:

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

这里的问题是,您将该subpreambles选项与类似 的逐字包一起使用。将子文件的前言复制到主文件listings时会出现问题。删除附录的前言并将其复制到主文件即可解决问题。我想这是目前可行的方法。standalonesubpreambles

相关内容