我们假设一个项目有一个主文件,main.tex
其中包括带有 的章节\include
。
% main.tex
\documentclass{book}
\includeonly{one}
\begin{document}
\include{one}
\include{two}
\end{document}
% one.tex
\chapter{First chapter}
Some text
% two.tex
\chapter{Second chapter}
Some text
为了保持目录整洁,章节应保存在名为的文件夹中chapters/
。这样做也意味着将文件夹添加到每个\include
宏中,以及添加到\includeonly
。
\documentclass{book}
\includeonly{chapters/one}
\begin{document}
\include{chapters/one}
\include{chapters/two}
\end{document}
所以我想知道是否可以更改使用的默认路径\include(only)
?
答案1
似乎可以破解 的定义\include(only)
。这似乎可行,但我不确定后果如何……
\documentclass{book}
\makeatletter
\def\include#1{\relax
\ifnum\@auxout=\@partaux
\@latex@error{\string\include\space cannot be nested}\@eha
\else \@include{chapters/#1} \fi%
}
\def\includeonly#1{%
\@partswtrue
\edef\@partlist{\zap@space chapters/#1 \@empty}%
}
\makeatother
\includeonly{one}
\begin{document}
\include{one}
\include{two}
\end{document}
我考虑将其做成一个小包,提供一个宏\includepath{<dir>}
来自动添加目录。这样做会不会没有任何危害?
\documentclass{book}
\makeatletter
\def\@includepath{}
\newcommand*{\includepath}[1]{%
\xdef\@includepath{#1}%
}
\@onlypreamble\includepath
\def\include#1{\relax
\ifnum\@auxout=\@partaux
\@latex@error{\string\include\space cannot be nested}\@eha
\else \expandafter\@include{\@includepath#1} \fi%
}
\def\includeonly#1{%
\@partswtrue
\edef\@partlist{\expandafter\zap@space\@includepath#1 \@empty}%
\renewcommand*{\includepath}[1]{%
\typeout{ERROR: \string\includepath\space must be
used before \string\includeonly!}
}
}
\makeatother
\includeonly{two}
\begin{document}
\include{one}
\include{two}
\end{document}