分类
LaTeX

LaTeX版本比较:latexdiff的使用

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

LaTeXDiff 效果图
LaTeXDiff 效果图

下面来说下基本的安装与使用。

 

安装latexdiff

  • 安装perl
  • 安装Latexdiff:其实就是一个tex宏包,你可以用tex包管理器安装, 也可以手动安装(从CTAN下载压缩包,解压到perl的bin目录下即可)

使用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手册.


发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据