进行多次调用仅包括:
\includeonly{myfirstinclude}
\includeonly{mysecondinclude}
它仅包含mysecondinclude
最后一次调用所调用的最后一个文件。当您列出并注释掉所有调用时\includeonly
,执行多次调用会很有用。\includeonly
\includeonly
\documentclass{article}
% How does 'filecontents' keep LaTeX parsing while temporarily stop writing output
% https://tex.stackexchange.com/questions/104159/how-does-filecontents-keep-latex
\usepackage{filecontents}
\begin{filecontents*}{myfirstinclude.tex}
myfirstinclude
\end{filecontents*}
\begin{filecontents*}{mysecondinclude.tex}
mysecondinclude
\end{filecontents*}
\begin{filecontents*}{mythirdinclude.tex}
mythirdinclude
\end{filecontents*}
% \includeonly{myfirstinclude}
% \includeonly{mysecondinclude}
% \includeonly{mythirdinclude}
\begin{document}
\include{myfirstinclude}
\include{mysecondinclude}
\include{mythirdinclude}
\end{document}
因此,当您只想包含一个或一些文件时,只需取消注释所需的行即可。
\includeonly{myfirstinclude}
\includeonly{mysecondinclude}
% \includeonly{mythirdinclude}
相关问题
答案1
为了你的具体用例你可以只使用一个includeonly
,将每个章节放在一行上:
\includeonly{%
myfirstinclude,
mysecondinclude,
mythirdinclude,
}
这样,就可以很容易地注释掉其中任何一个,比如第二个:
\includeonly{%
myfirstinclude,
%mysecondinclude,
mythirdinclude,
}
答案2
您可以创建一个新命令\addtoincludeonly{somefile}
,其中包含一个内部字符串,如上所述将命令字符串化为宏序列,那么在所有自定义仅包含调用之后,您将以 的形式调用另一个命令\doincludeonly
,该命令不带任何参数。
需要使用新的命令,因为我们只应在执行某些调用时\doincludeonly
调用。否则,空调用将创建一个几乎为空的文档,其中不包含任何由插入/添加的内容。\includeonly
\addtoincludeonly{somefile}
includeonly{}
\include{somefile}
\documentclass{article}
% How does 'filecontents' keep LaTeX parsing while temporarily stop writing output
% https://tex.stackexchange.com/questions/104159/how-does-filecontents-keep-latex
\usepackage{filecontents}
% Logical String Length
% https://tex.stackexchange.com/questions/87638/logical-string-length
\usepackage{xifthen}
\usepackage{xstring}
\newcommand{\includeonlyfilelist}[0]{}
\makeatletter
\newcommand{\addtoincludeonly}[1]
{%
\StrLen{\includeonlyfilelist}[\includeonlyfilelistlen]
% How to concatenate strings into a single command?
% https://tex.stackexchange.com/questions/74707/how-to-concatenate-strings-into-a
\ifnum\includeonlyfilelistlen>0
\g@addto@macro\includeonlyfilelist{,#1}
\else
\g@addto@macro\includeonlyfilelist{#1}
\fi
}
\newcommand{\doincludeonly}[0]
{%
\StrLen{\includeonlyfilelist}[\includeonlyfilelistlen]
\ifnum\includeonlyfilelistlen>0
\includeonly{\includeonlyfilelist}
\else
\fi
}
\makeatother
\begin{filecontents*}{myfirstinclude.tex}
myfirstinclude
\end{filecontents*}
\begin{filecontents*}{mysecondinclude.tex}
mysecondinclude
\end{filecontents*}
\begin{filecontents*}{mythirdinclude.tex}
mythirdinclude
\end{filecontents*}
\addtoincludeonly{myfirstinclude}
\addtoincludeonly{mysecondinclude}
% \addtoincludeonly{mythirdinclude}
\doincludeonly
\begin{document}
\include{myfirstinclude}
\include{mysecondinclude}
\include{mythirdinclude}
\end{document}