相关问题

相关问题

进行多次调用仅包括:

\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. 使用 \input{} 添加的文件中的相对路径会发生什么情况?
  2. \includeonly 的变体
  3. 如何使主文件识别导入文件中使用的相对路径?
  4. subimport 和 includeonly
  5. 使用独立程序将多个 .tex 合并为一个文件
  6. 文件是否可以知道它是否已被 \include 或 \input ?
  7. 生成合并的 LaTeX 文件,其中包含 \input 代码?
  8. 如何合并多个 tex 文件以便它们具有一个目录/表格和图表列表
  9. 何时应使用 \input 和 \include?
  10. 使用相同内容和不同布局构建多个文档的选项
  11. \input 会引起哪些状态改变?

答案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}

参考

  1. 在 LaTeX 中使用字符串变量
  2. 如何将字符串连接成单个命令?
  3. 将命令字符串化为宏序列
  4. 'filecontents' 如何保持 LaTeX 解析,同时暂时停止写入输出
  5. 如何在 TeX 中形成“如果...或...那么”条件?
  6. 逻辑字符串长度
  7. 如何将数据附加到全局字符串变量?

相关内容