8

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
    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 Jul 1, 2021 at 7:07
  • How about git? Best change-tracking tool there is!
    – SRSR333
    Jul 1, 2021 at 14:41

2 Answers 2

13

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. 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? 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. 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. 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. Jul 6, 2021 at 3:36
10

(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.

5
  • 2
    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
    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? Jan 20 at 15:26
  • 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
    Jul 6 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. Jul 30 at 19:26
  • @UtkanGezer as long as you include \documentclass{dummy} at the end, you shan't need to change the Main document setting. That's because Overleaf's compiler scans the currently open file for the documentclass, and if it finds it, it compiles this file rather than the file specified in the Menu. If you have a different experience, can you please reach me at [email protected] with a URL of a project where this doesn't work? I can then chek what's going on...
    – yo'
    Jul 31 at 7:08

You must log in to answer this question.

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