LaTeX 中的条件导入?

发布于 2024-09-18 04:10:15 字数 384 浏览 10 评论 0原文

我将记下大量的讲义,然后将它们编译成 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

开始看清了 2024-09-25 04:10:15

我在这里看到两种方法。要么仔细构建文档,要么使用一些 hacky TeX 魔法:

聪明的方法

将较小的文档分成页眉部分、页脚部分和内容部分。

header.tex:

\documentclass{article}
...
\begin{document}

footer.tex:

\end{document}

foo-content.tex:

In this paper, we discuss an new approach to metasyntactic variables...

foo.tex (小纸质版本):

\include{header}
\include{foo-content}
\include{footer}

在你收集的文章文档的 .tex 中:

\include{foo-content}

The hacky TeX way

将其放入一些常见的包含文件中,供您个人使用文件:

\ifx\ismaindoc\undefined
\newcommand{\inbpdocument}{\begin{document}}
\newcommand{\outbpdocument}{\end{document}}
\else
\newcommand{\inbpdocument}{}
\newcommand{\outbpdocument}{}
\fi

在各个文件中使用 \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:

\documentclass{article}
...
\begin{document}

footer.tex:

\end{document}

foo-content.tex:

In this paper, we discuss an new approach to metasyntactic variables...

foo.tex (the small paper version):

\include{header}
\include{foo-content}
\include{footer}

In your .tex for the collected articles document:

\include{foo-content}

The hacky TeX way

Put this in some common include file, used by your individual files:

\ifx\ismaindoc\undefined
\newcommand{\inbpdocument}{\begin{document}}
\newcommand{\outbpdocument}{\end{document}}
\else
\newcommand{\inbpdocument}{}
\newcommand{\outbpdocument}{}
\fi

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.

故事未完 2024-09-25 04:10:15

这是另一种可能的方法:如果您将魔术字符串(即 % % 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.

梦冥 2024-09-25 04:10:15

我还没有使用过它,但看起来“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

单身情人 2024-09-25 04:10:15

您可以使用另一种黑客方法,它不需要修改单个文件...只需暂时重新定义 {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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文