Latexdiff 无法编译

Latexdiff 无法编译

我刚刚发现了 Latexdiff,它正是我现在需要的。但不幸的是,我无法.tex在我的计算机上编译 Latexdiff 创建的文件。我尝试了一个最小的例子:

文件编号 1:ori.tex

\documentclass{article}

\begin{document}

Hello World

\end{document}

文件编号 2:ori_v2.tex

\documentclass{article}

\begin{document}
    
    Hello to this world!
    
\end{document}

它们都可以很好地编译。

但是,运行 Latexdiff 会产生以下文件,该文件无法编译:

\documentclass{article}

%DIF LATEXDIFF DIFFERENCE FILE
%DIF DEL ori.tex      Wed May 17 14:28:16 2023
%DIF ADD ori_v2.tex   Wed May 17 14:29:17 2023
%DIF PREAMBLE EXTENSION ADDED BY LATEXDIFF
%DIF UNDERLINE PREAMBLE %DIF PREAMBLE
\RequirePackage[normalem]{ulem} %DIF PREAMBLE
\RequirePackage{color}\definecolor{RED}{rgb}{1,0,0}\definecolor{BLUE}{rgb}{0,0,1} %DIF PREAMBLE
\providecommand{\DIFadd}[1]{{\protect\color{blue}\uwave{#1}}} %DIF PREAMBLE
\providecommand{\DIFdel}[1]{{\protect\color{red}\sout{#1}}}                      %DIF PREAMBLE
%DIF SAFE PREAMBLE %DIF PREAMBLE
\providecommand{\DIFaddbegin}{} %DIF PREAMBLE
\providecommand{\DIFaddend}{} %DIF PREAMBLE
\providecommand{\DIFdelbegin}{} %DIF PREAMBLE
\providecommand{\DIFdelend}{} %DIF PREAMBLE
\providecommand{\DIFmodbegin}{} %DIF PREAMBLE
\providecommand{\DIFmodend}{} %DIF PREAMBLE
%DIF FLOATSAFE PREAMBLE %DIF PREAMBLE
\providecommand{\DIFaddFL}[1]{\DIFadd{#1}} %DIF PREAMBLE
\providecommand{\DIFdelFL}[1]{\DIFdel{#1}} %DIF PREAMBLE
\providecommand{\DIFaddbeginFL}{} %DIF PREAMBLE
\providecommand{\DIFaddendFL}{} %DIF PREAMBLE
\providecommand{\DIFdelbeginFL}{} %DIF PREAMBLE
\providecommand{\DIFdelendFL}{} %DIF PREAMBLE
%DIF COLORLISTINGS PREAMBLE %DIF PREAMBLE
\RequirePackage{listings} %DIF PREAMBLE
\RequirePackage{color} %DIF PREAMBLE
\lstdefinelanguage{DIFcode}{ %DIF PREAMBLE
%DIF DIFCODE_UNDERLINE %DIF PREAMBLE
  moredelim=[il][\color{red}\sout]{\%DIF\ <\ }, %DIF PREAMBLE
  moredelim=[il][\color{blue}\uwave]{\%DIF\ >\ } %DIF PREAMBLE
} %DIF PREAMBLE
\lstdefinestyle{DIFverbatimstyle}{ %DIF PREAMBLE
    language=DIFcode, %DIF PREAMBLE
    basicstyle=\ttfamily, %DIF PREAMBLE
    columns=fullflexible, %DIF PREAMBLE
    keepspaces=true %DIF PREAMBLE
} %DIF PREAMBLE
\lstnewenvironment{DIFverbatim}{\lstset{style=DIFverbatimstyle}}{} %DIF PREAMBLE
\lstnewenvironment{DIFverbatim*}{\lstset{style=DIFverbatimstyle,showspaces=true}}{} %DIF PREAMBLE
%DIF END PREAMBLE EXTENSION ADDED BY LATEXDIFF

\begin{document}

    Hello \DIFdelbegin \DIFdel{World}\DIFdelend \DIFaddbegin \DIFadd{to this world!}\DIFaddend 

\end{document}

尝试编译它,我得到以下.log文件:

This is pdfTeX, Version 3.141592653-2.6-1.40.25 (MiKTeX 23.5) (preloaded format=pdflatex 2023.5.14)  18 MAY 2023 12:57
entering extended mode
 restricted \write18 enabled.
 %&-line parsing enabled.
**./ori_Diff.tex
(ori_Diff.tex
LaTeX2e <2022-11-01> patch level 1
L3 programming layer <2023-04-20>
! Undefined control sequence.
l.1 \^^@
        d^^@o^^@c^^@u^^@m^^@e^^@n^^@t^^@c^^@l^^@a^^@s^^@s^^@{^^@a^^@r^^@t^^@...
The control sequence at the end of the top line
of your error message was never \def'ed. If you have
misspelled it (e.g., `\hobx'), type `I' and the correct
spelling (e.g., `I\hbox'). Otherwise just continue,
and I'll forget about whatever was undefined.


! LaTeX Error: Missing \begin{document}.

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.
 ...                                              
                                                  
l.1 \^^@d
         ^^@o^^@c^^@u^^@m^^@e^^@n^^@t^^@c^^@l^^@a^^@s^^@s^^@{^^@a^^@r^^@t^^@...

You're in trouble here.  Try typing  <return>  to proceed.
If that doesn't work, type  X <return>  to quit.

Missing character: There is no d in font nullfont!
! Text line contains an invalid character.
l.1 \^^@d^^@
            o^^@c^^@u^^@m^^@e^^@n^^@t^^@c^^@l^^@a^^@s^^@s^^@{^^@a^^@r^^@t^^@...
A funny symbol that I can't read has just been input.
Continue, and I'll forget that it ever happened.
[...]

答案1

您以某种方式将 tex diff 文件保存为 utf-16。

^^@是 ascii 0 并且出现是因为对于\documentclass保存为 utf-16 的 ascii,每个其他字节都是 0。

通过将 diff 代码上传到此网站,您将其转换为 utf-8(整个网站都是 utf-8),因此您发布的代码可以正常工作,并且

在此处输入图片描述

相关内容