LaTeX 中的条件导入?
我将记下大量的讲义,然后将它们编译成 LaTeX,这样我就可以获得优秀的文档供将来查看。我正在尝试组织一些事情,以便我可以拥有一堆包含讲座笔记的小文档,然后在学期结束时将它们编译成包含所有内容的大文档。我过去曾成功地使用过 import/include 等,但在编译主文档之前,我必须删除子文档头部和底部的内容。 ,我必须从每个子文档中删除:
\begin{document}
和
\end{document}
例如,在编译主文档之前 。对于包含 5 个左右部分的报告来说这还不错,但对于包含 100 个以上部分的报告来说就很麻烦了。对于在使用 import 命令时以编程方式忽略 LaTeX 文件的内容有什么建议吗?
I'm going to be taking a ton of lecture notes, and then compiling them into LaTeX so that I can have excellent documents for future me to look over. I'm trying to organize things so that I can have a bunch of little documents containing the notes from a lecture, and then compile them at the end of the semester into one large document containing all of them. I have used import/include etc. successfully in the past, but I've had to remove the content at the head and foot of the sub-documents before compiling the main document. For example, I would have to remove:
\begin{document}
and
\end{document}
from every sub-document before compiling the main document. This is fine for a report with 5 or so sections, but a pain in the ass for something with 100+. Any recommendations for ignoring the contents of a LaTeX file programmatically when using the import command?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我在这里看到两种方法。要么仔细构建文档,要么使用一些 hacky TeX 魔法:
聪明的方法
将较小的文档分成页眉部分、页脚部分和内容部分。
header.tex:
footer.tex:
foo-content.tex:
foo.tex (小纸质版本):
在你收集的文章文档的 .tex 中:
The hacky TeX way
将其放入一些常见的包含文件中,供您个人使用文件:
在各个文件中使用
\inbpdocument
和\outbpdocument
代替\begin{document}
和\end{document }
。在主文件中,在包含或导入任何内容之前放入\def \ismaindoc {}
。I see two approaches here. Either carefully structure your documents, or use some hacky TeX magic:
The smart way
Break your smaller documents into a header part, a footer part and a content part.
header.tex:
footer.tex:
foo-content.tex:
foo.tex (the small paper version):
In your .tex for the collected articles document:
The hacky TeX way
Put this in some common include file, used by your individual files:
Use
\inbpdocument
and\outbpdocument
in your individual files, in place of\begin{document}
and\end{document}
. In your main file, put in a\def \ismaindoc {}
before including or importing anything.这是另一种可能的方法:如果您将魔术字符串(即
% % BEGIN LECTURE % %
...% % END LECTURE % %
)放入各个文件中,您可以awk 取出各个文件的内容,使用 make/sh 组装它们,然后\include
它们。Here's another possible approach: if you put magic strings (i.e.,
% % BEGIN LECTURE % %
...% % END LECTURE % %
) in the individual files, you could awk out the guts of the individual files, assemble them using make/sh, and then\include
them.我还没有使用过它,但看起来“subfiles”包正是你想要的:
http://en.wikibooks.org/wiki/LaTeX/Modular_Documents#Subfiles_package
I haven't used it, but it looks like the "subfiles" package does exactly what you want:
http://en.wikibooks.org/wiki/LaTeX/Modular_Documents#Subfiles_package
您可以使用另一种黑客方法,它不需要修改单个文件...只需暂时重新定义 {document} 环境(到良性的,即无操作),\include 单个文件,然后恢复 {文档}环境定义。
如果我没记错的话,执行此操作的命令是 \let 和 \renewenvironment。
嗯。您可能还必须暂时重新定义 \documentclass 和 \usepackage。是的,这是一个黑客行为,但我认为它应该有效。
There's another hack you could use, which wouldn't require modifying the individual files... just temporarily redefine the {document} environment (to something benign, i.e. a no-op), \include the individual files, and then restore the {document} environment definition.
If I recall correctly, the commands to do this are \let and \renewenvironment.
Hm. You might also have to temporarily redefine \documentclass and \usepackage, too. It's a hack, yes, but I think it should work.