LaTeXDiff可以比较TeX代码, 然后生成比较后的PDF, 效果见图:

下面来说下基本的安装与使用。
安装latexdiff
使用latexdiff
基本用法即可:
latexdiff draft.tex revision.tex > diff.tex
然后正常编译diff.tex
这个tex文件即可得到pdf。
使用latexdiff注意事项
- 在align环境中, 如果有
\intertext
的话可能会比较出错。例如\begin{align*} a&=b\\ \intertext{and} c&=d \end{align*}
删除后, 得到比较后的tex为
\DIFdelbegin \begin{align*} \DIFdel{a}&\DIFdel{=b}\\ \DIFdel{\intertext{and} c}&\DIFdel{=d }\end{align*}
这是, 运行会报错。
只需将代码改成如下即可:\DIFdelbegin \begin{align*} \DIFdel{a}&\DIFdel{=b}\\ \intertext{\DIFdel{and}} \DIFdel{c}&\DIFdel{=d }\end{align*}
-
! Limit controls must follow a math operator. \[email protected] ...hrest \mathop {\kern \z@ #1}\limits \sb {\[email protected] \[email protected]...
这可能是因为我们使用了非标准的
dcases
环境, 例如你新增一段代码:\begin{equation}\label{eq:diff} \begin{dcases} ... \end{dcases} \end{equation}
则diff后是形如
\DIFaddbegin \begin{equation} \DIFadd{\label{\label{eq:diff}} \begin{dcases} ... \end{dcases} } \end{equation}
我们只需将其改为
\DIFaddbegin \begin{equation} \begin{dcases} \DIFadd{\label{\label{eq:diff}} ... } \end{dcases} \end{equation}
\DIFadd{...}
中的…部分不能含有\left,\right,\big,\bigg,\Big
等定义的各种括号, 如果有应该将其改为\left\{\DIFadd{…}\right\}- 比较的tex源码必须位于同一个目录, 支持不同目录里源码的比较, 但是
input
文件不会自动修改路径。 - 报错:
! Argument of \[email protected] has an extra }.
\par解决办法是添加参数
--exclude-textcmd="section,subsection,subsubsection"
最后, 更多设置可以参考latexdiff手册.
本作品采用创作共用版权协议, 要求署名、非商业用途和保持一致. 转载本站内容必须也遵循署名-非商业用途-保持一致的创作共用协议.