1

I'm trying to use latexdiff on two versions of a document. These are encoded in UTF8 and have the \usepackage[utf8]{inputenc} statement as first line within the preamble.

I processed the files then using

latexdiff --encoding=utf8 file1.tex file2.tex > out.tex

but when I try to open out.tex with TexMaker again and I specify UTF8 as encoding, all the characters like äöüé show up as some gibberish characters. I assume this means that latexdiff does not use UTF8 as output encoding, but what encoding does it use?

This is on Windows 10 using MikTex and TexMaker and Strawberry Perl (doesn't work with Active State Perl either).


EDIT: Due to the observations below I have to conclude that latexdiff OR texmaker do not use the correct UTF8 encoding.

I now made two new toy documents in TexMaker (without any umlauts or other special characters), which is set to UTF8 in the settings:

\documentclass[10pt]{report}
\usepackage[utf8]{inputenc}
\title{Test1}
\begin{document}
\maketitle
\chapter{intro}
what is love?
\begin{itemize}
\item item
\end{itemize}
\end{document}

document2:

\documentclass[10pt]{report}
\usepackage[utf8]{inputenc}
\title{Test2}
\begin{document}
\maketitle
\chapter{intro}
what is hate?
\begin{itemize}
\item item2
\end{itemize}
\end{document}

Running the command latexdiff .\doc1.tex .\doc2.tex > diff.tex results in following diff.tex (when opened with TexMaker, selecting UTF8 when asked in the popup). (When I try to paste the text here, nothing is pasted, hence the image.)

The document does however look correct when I open it with the UTF16 setting:

\documentclass[10pt]{report}
%DIF LATEXDIFF DIFFERENCE FILE
%DIF DEL .\doc1.tex   Mon Sep 11 13:46:31 2017
%DIF ADD .\doc2.tex   Mon Sep 11 13:46:26 2017
\usepackage[utf8]{inputenc}
\title{\DIFdelbegin \DIFdel{Test1}\DIFdelend \DIFaddbegin \DIFadd{Test2}\DIFaddend }
%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}
\maketitle
\chapter{intro}
what is \DIFdelbegin \DIFdel{love}\DIFdelend \DIFaddbegin \DIFadd{hate}\DIFaddend ?
\begin{itemize}
\item \DIFdelbegin \DIFdel{item
}\DIFdelend \DIFaddbegin \DIFadd{item2
}\DIFaddend \end{itemize}
\end{document}

But as soon as I try to compile it using pdflatex I get the error

line 1 ! Undefined control sequence. \
  • @egreg How can you check whether you get the correct format? – flawr Sep 10 '17 at 13:02
  • I've never had a problem and I don't even specify the encoding option. (Unless I stuck it in a config file.) And all my files use UTF8 and include at least some non-ASCII characters (curly quotes, if nothing else). – cfr Sep 10 '17 at 13:05
  • I simply opened the file with a UTF-8 editor. Not Notepad++, of course, which I cannot run and is known to add a BOM all around. – egreg Sep 10 '17 at 13:06
  • On a UNIX-ish system, you can say file <path> to get the encoding (and other information) about the file at <path>. Not sure on Windows, though. – cfr Sep 10 '17 at 13:06
  • Unfortunately the "solution" above does not work for my real documents. The outputs with and without the --e=utf8 are identical. – flawr Sep 10 '17 at 13:30
0

Ok, this is not really a solution, just a workaround to make get it going, but very cumbersome to use it that way. But perhaps someone can see an issue. So this is the sequence of actions that made it working:

  1. Replace all special characters and umlauts with ASCII characters (in my case ÄÖÜäöü with ae,oe,ue, and é with e)
  2. Remove all \left and \right which is another issue of latexdiff
  3. Comment out all tikz pictures (in my case it was enough to comment all \tikzsetnextfilename as well as %\usetikzlibrary{external} and \tikzexternalize[prefix=tikz/]), see also here.
  4. Run latexdiff .\doc1.tex .\doc2.tex > diff.tex
  5. Open diff.tex with NotePad++. The current encoding is UCS2-Little-Endian, but we need to use Convert to UTF8-without-BOM, and save the document.
  6. Open the diff.tex in TexMaker, now no dialog box about encoding should pop up, and the document should compile fine.
  • The answer is confusing because points 2-3 are unrelated issues not part of the original question. I suggest deleting those points (and raise them as a separate issue if needed). I still find it very confusing to see this behaviour and wonder whether you have something unusual about your setup; where does the UCS2-Little-Endian encoding come from, for example? – frederik Sep 11 '17 at 16:26
  • Regarding 2. This issue was fixed some time ago - which version of latexdiff are you using. – frederik Sep 11 '17 at 16:28
  • Regarding 3. Why did you not use the suggestion suggested in the post you linked - seems less cumbersome once it's set up. – frederik Sep 11 '17 at 16:28
  • I thought to include them in case someone has the same setup and similar problems. I'm not sure about the UCS2-LE, I read somewhere that NP++ sometimes displays this encoding insted of some other one it does not recognize. The latexdiff is version 1.1903 which came with the most recent MikTex package. – flawr Sep 11 '17 at 22:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.