10

I use overleaf on Windows for my research papers and thesis and it works fine. However, I received reviews from a journal, and they require me to track changes in my old and final manuscript. Inspire by this answer, I decided to use latexdiff but it isn't working. I installed Perl v5.28.1 (I think it installed correctly because Perl -v returns the version), and downloaded latexdiff from here. I extracted and copied the files to C:\Perl64\bin as described here. Now, if I attempt to run the command in CMD, I get the following error:

'latexdiff' is not recognized as an internal or external command, operable program or batch file.

I have two questions.

  1. Why am I getting this error?

  2. The tutorials I found on YouTube all work with MikTex, but I want to stick to overleaf. How do you use latexdiff without having to install latex in your system?

3
  • Hopefully latexdiff is one of a Perl Script, it expects Perl should be install into your system..
    – MadyYuvi
    Commented Jul 1, 2021 at 6:38
  • you need (at least) whatever folder you placed latexdiff.bat or latexdiff.exe (however it ships on windows) to be in your PATH as set in your environment variables, or call it by explicit path so c:\perl64\bin\latexdiff myfile not just latexdiff myfile or perhaps simpler call it as perl c:\perl64\bin\latexdiff myfile Commented Jul 1, 2021 at 7:07
  • How about git? Best change-tracking tool there is!
    – SRSR333
    Commented Jul 1, 2021 at 14:41

3 Answers 3

16

As an alternative to running latexdiff locally and copying the file back to Overleaf you can run latexdiff at overleaf.

Here is a project with two versions of a tex file and a displayed diff

It is currently live on Overleaf but this link may not be good forever, but I show the files inline below.

https://www.overleaf.com/read/xhszmytdmqqg

enter image description here

main.tex (the old version)

\documentclass{article}


\title{ld}
\author{me}
\date{July 2021}

\begin{document}

\maketitle

\section{Introduction}
zzz
\end{document}

main2.tex (new version)

\documentclass{article}


\title{latexdiff}
\author{me\and you}
\date{July 2021}

\begin{document}

\maketitle

\section{Introduction}
zzz zzz

\section{Section}
zzz
\end{document}

latexmkrc (to instruct overleaf to show the diff)

$pdflatex = "latexdiff main.tex main2.tex > main-d.tex; pdflatex %O  main-d"

When you want to see the "normal" typeset version of main.tex without the diff marking, just add a # comment marker to the latexmkrc setting so it looks like

# $pdflatex = "latexdiff main.tex main2.tex > main-d.tex; pdflatex %O  main-d"

then recompiling main.tex or main2.tex will produce the normal typeset output.

7
  • 2
    This is exactly what I've been looking for for two days. Thank you so much. Commented Jul 1, 2021 at 9:40
  • Hi @David Carlisle, ever since I've started using it, the two buttons Go to PDF location in code and Go to code location in PDF have stopped working. I have tried another project, for which both the buttons were working perfectly, but when I added the file latexmkrc file, they stopped working. What could be the possible cause? Commented Jul 1, 2021 at 13:50
  • 3
    @ZainabIftikhar oh that's not that surprising actually, Overleak "thinks" it is typesetting main.tex but you (or I) have configured latexmk to ignore the supplied filename and make a new file main-d.tex and typeset that. So the source is not the source the overleaf pdf viewer thinks it is. Given that the diff tex file is not in the project but generated each time on demand it's not clear what you would want the source link from the displayed diff to go to. Commented Jul 1, 2021 at 13:53
  • That makes sense. I will just, as you mentioned, use # to comment it for now, because I need those buttons to work, but later before submitting final manuscript, I will show changes. Thank you. Commented Jul 1, 2021 at 14:22
  • sorry to bother you again and again. One last question, please. Is there any way that changes in the references are also shown using this latexmkrc script? It shows all other changes but references. I want to show the new references that I've added and old references that I've edited. I'm using an external bibliography file. Commented Jul 6, 2021 at 3:36
17

(Tom from Overleaf Support here.)

An alternative way to what David proposes is by using ShellEscape to run latexdiff. You can simply create a new file called e.g. diff.tex with the following contents:

\RequirePackage{shellesc}
\ShellEscape{latexdiff main.tex main2.tex > diff_result.tex}
\input{diff_result}
\documentclass{dummy}

If you Recompile with this file open in the editor, it will show a diff-ed PDF. If you Recompile with any of main.tex or main2.tex open, it will show the corresponding non-diff-ed document.

(Note that the line \documentclass{dummy} is necessary to trick Overleaf's compiler into believing this file is compilable. The compiler checks for \documentclass and if it doesn't find it, it compiles the Main file as chosen in the Menu; however, when it does fine it, it considers the current file to be main.)

In Overleaf, you can get the previous version of the file from the project's History, you can simply download the project at an earlier version, extract the file from it and upload it (under a different name) back to the project.

6
  • 4
    Thank you! Is there a way to retrieve the rendered diff_results.tex file from Overleaf? So that I cannot only download the PDF but the .tex instead?
    – xyz
    Commented Feb 28, 2022 at 18:49
  • Hey. When I run diff.text, Overleaf still shows me the compiled main.tex PDF. I have diff.tex, main.tex and main2.tex in the same folder. Any clues on how to solve this? Commented Jan 20, 2023 at 15:26
  • 1
    Can we also do some further editing to this diff-result.tex document using this method ? e.g., when I create this file it doesn't show the difference for the Bibliography between the main.tex and main2.tex
    – Ali Babar
    Commented Jul 6, 2023 at 21:22
  • 1
    @JoãoBravo Contrary to yo''s answer, I suspect that you might also have to change the "Main document" to "diff.tex" from the "Menu" (top left corner) before compiling. The file being open in the editor shouldn't be enough for the Overleaf to pick it for compilation. I personally like David's solution better to have single point of control. Commented Jul 30, 2023 at 19:26
  • 3
    @xyz, yes! When you go "Logs and output files" (small icon with warnings and errors next to the recompile button) there is a "Other logs and files" button in the right bottom corner. When you click on it, a menu folds out showing the diff_result.tex, click on the filename to download. You can upload the contents again if you also want it in overleaf or select the parts you need, e.g. for a response letter.
    – Adriaan
    Commented Mar 7 at 16:53
1

I've used the posted code and it works for me on overleaf. I just modified the diff.tex so that it also mark changes in bibliography and referencing and to support the update syntax of some packages I am using (chemnum and siunitx) with the append options. This is what I'm using (one has first to retrieve and upload the old versions of both .bbl and .tex files).

\RequirePackage{shellesc}
\ShellEscape{pdflatex new.tex}
\ShellEscape{bibtex new}
\ShellEscape{latexdiff old.bbl new.bbl > output.bbl}
\ShellEscape{latexdiff --append-safecmd="cmpd" --append-mboxsafecmd="qty,qtylist,qtyproduct,qtyrange,complexqty" old.tex new.tex > diff_result.tex}
\input{diff_result}
\documentclass{dummy}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .