我有一个小问题,我想将 LaTeX 文档的 svn diff 插入到
另一个 LaTeX 文档,目标是显示自修订版 XXX 以来发生的更改。
然而,由于 diff 包含大量 LaTeX 命令,我无法将其直接包含到文档中,因为 LaTeX 会解释它们,而不仅仅是“打印”它们。
今天我的 Makefile 中有这个
DIFF_INFO=diff.info.tex
DIFF_REV=167
diffinfo:
$(shell echo "\n" > $(DIFF_INFO) )
$(shell echo "\\section{diff $(DIFF_REV)} \n" >> $(DIFF_INFO) )
$(shell echo \\\\begin{verbatim} >> $(DIFF_INFO) )
$(shell svn diff --revision $(DIFF_REV) $(N).tex >> $(DIFF_INFO) )
$(shell echo \\\\end{verbatim} >> $(DIFF_INFO) )
在 LaTeX 文档的末尾我有这个:
\IfFileExists{diff.info.tex}
{
\newpage
\input{diff.info.tex}
}
但这很难失败!
我的下一个想法是编写一个 perl 脚本,用 LaTeX 可以显示的内容替换所有无效字符,但感觉我冒着重新发明轮子的风险,所以我想我可以问是否有人有更好的主意?
如何在文档中包含并显示 LaTeX 代码?
谢谢
约翰
更新:
感谢“未知(谷歌)”逐字指出,它做了我想要的事情。
更新:
我看起来也应该尝试 las3rjock 告诉我们的列表,因为它看起来不错。
更新:
无法让列表在我的情况下工作,我收到一些关于无效字符的奇怪 utf 警告。但逐字记录是有效的,所以这次我将使用这种方式。
I have a little problem where I would like to insert a svn diff of a LaTeX document into
another LaTeX document, the goal is to show what has changed since revision XXX.
However since the diff contains a lot of LaTeX command I can't include it right into the document since LaTeX will interpit them and not just "print" them.
Today I have this in my Makefile
DIFF_INFO=diff.info.tex
DIFF_REV=167
diffinfo:
$(shell echo "\n" > $(DIFF_INFO) )
$(shell echo "\\section{diff $(DIFF_REV)} \n" >> $(DIFF_INFO) )
$(shell echo \\\\begin{verbatim} >> $(DIFF_INFO) )
$(shell svn diff --revision $(DIFF_REV) $(N).tex >> $(DIFF_INFO) )
$(shell echo \\\\end{verbatim} >> $(DIFF_INFO) )
And at the end of the LaTeX document I have this:
\IfFileExists{diff.info.tex}
{
\newpage
\input{diff.info.tex}
}
But this fails hard!
My next idea is to write a perl script that replaces all invalid chars with something that LaTeX can show, but it feels like I'm risking to reinvent the wheel so I figured that I could ask if someone had a better idea?
How do I include and show LaTeX code in the document?
Thanks
Johan
Update:
Thanks "unknown (google)" for pointing out verbatim, it did what I wanted it to.
Update:
I also looks like I should try that listings that las3rjock told us about since it look kind of nice.
Update:
Could not get listings to work in my case, I get some strange utf warnings about invalid chars. But the verbatim is working so I will use that way this time.
发布评论
评论(2)
我在对另一个答案的评论中赞同 Boojum 的建议,即您使用 列表包。对于 LaTeX 代码列表,我使用在 André Miede 的 中找到的设置classicthesis 包。以下是示例文档 (
quine.tex
) 及其输出:I second Boojum's recommendation in a comment to another answer that you use the listings package. For LaTeX code listings, I use settings that I found in André Miede's classicthesis package. Here is a sample document (
quine.tex
) and its output:您可以将一个
verbatim
包包含在\usepackage{verbatim}
中,并使用\verbatiminput{
filename}
进行访问>。There' a
verbatim
package that you can include with\usepackage{verbatim}
and access using\verbatiminput{
filename}
.