3

I tried to use latexdiff with texstudio on win 10, but failed. This is the original tex:

\documentclass{article}
\begin{document}
This is the draft.
\end{document}

This is the revised tex:

\documentclass{article}
\begin{document}
This is the revision.
\end{document}

Command to use latexdiff:

latexdiff draft.tex revision.tex > diff.tex

This is the difference tex:

\documentclass{article}
%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
%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 END PREAMBLE EXTENSION ADDED BY LATEXDIFF

\begin{document}
This is the \DIFdelbegin \DIFdel{draft}\DIFdelend \DIFaddbegin \DIFadd{revision}\DIFaddend .
\end{document}

Yet I could not compile this tex to pdf. Error log with keyword "error":

! LaTeX Error: Missing \begin{document}.
The control sequence at the end of the top line of your error message was never \def'ed.

Any help is appreciated. Thank you in advance.

  • Maybe the logfile (here diff.log) provides more information? TeXstudio sometimes removes too much of the real error when it tries to present the most relevant part of the error. Or maybe you can try compiling on the command line (pdflatex diff.tex) and check the output you get there? – Marijn May 04 '20 at 05:32
  • Thanks for the response. Yet it didn't work. I'll try some other methods. – jian chang May 04 '20 at 07:07
  • So do you get exactly the same error in TeXstudio, in the log file, and on the command line? Or are there any differences between the three? – Marijn May 04 '20 at 09:13
  • Same error log, of both compile in texstudio and command line. – jian chang May 04 '20 at 13:32
  • 1
    That's weird. This diff .tex file looks fine to me, and in fact it processes absolutely fine on my computer (not TexStudio and not Windows, though), and of course \begin{document} should not be undefined ever in a latex document. So I don't think there is anything wrong with latexdiff but some more general problem with the setup. Do your input files process properly? Try copy/pasting the diff file from this very page. If this then suddenly works, compare file sizes - if they are different it could be that somehow an invisible character code has been inserted that messes up pdflatex – frederik May 05 '20 at 07:31
  • It works! Thank you very much! – jian chang May 05 '20 at 22:42
  • Similar error for me on a different document (Windows, TeXStudio, latexdiff). Tried pasting into notepad and then replacing it back into the file, but without luck. I'll try reproducing the example above and troubleshoot a bit more. – Sterling Nov 09 '22 at 06:57
  • Interesting, I was able to reproduce the \begin{document} error using latexdiff running in a (Miniconda) Powershell environment. I created the draft and revised documents in TeXStudio, ran the command, opened the diff file, and tried to compile. The draft and revised documents compiled fine - but the diff led to an error of the form failed to find 'C:/Users/.../diff.tex' which comes from the Missing \begin{document} error. I copy-pasted the snippet from above into the same file, and ran into the same error. However, when I created a new file and copied it there it built fine. – Sterling Nov 09 '22 at 19:39
  • Checking in VS Code, the diff file that doesn't compile uses the UTF-16 LE encoding, while the diff file that compiles is UTF-8. There's an option for doing this programatically, but something went wrong with the conversion (see my comment on the linked post). Maybe iconv handles this better. Copy-pasting the text from a UTF-16 LE to a UTF-8 file seems to work fine, and another option is running latexdiff via Windows Subsystem for Linux (WSL), which produces the desired UTF-8 file. – Sterling Nov 09 '22 at 19:52
  • Since I ran out of characters for the link: iconv – Sterling Nov 09 '22 at 19:54
  • 1
    @Sterling it seems you have found the cause of the error and the solution, at least for your situation (which may well be the general case, however I can imagine there are other possible causes as well). Maybe you can write down your findings about UTF-8 vs UTF-16 in a real answer below? This is more visible than buried in the comments. – Marijn Nov 09 '22 at 19:55

1 Answers1

1

Note: For visibility, in this answer I'm summarizing my comments on the question.

This seems to be an issue with latexdiff on Windows creating a UTF-16 LE encoded file instead of a UTF-8 encoded file. To fix, create a new file in TeXStudio and copy-paste the text contents into the new file or run latexdiff using Windows Command Prompt or Windows Subsystem for Linux (WSL). A PowerShell command to convert to UTF-8 produced strange results for me (see comments in linked issue). Maybe iconv handles this better, but I'll probably stick with running latexdiff in WSL. Note that I checked the encodings in VS Code.

enter image description here

There is also a GitHub issue that discusses this. This is also discussed officially as a FAQ in the latexdiff file https://github.com/ftilmann/latexdiff/pull/276/files.

Sterling
  • 171