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?

  • Hopefully latexdiff is one of a Perl Script, it expects Perl should be install into your system.. – MadyYuvi Jul 01 '21 at 06: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 – David Carlisle Jul 01 '21 at 07:07
  • How about git? Best change-tracking tool there is! – SRSR333 Jul 01 '21 at 14:41

2 Answers2

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.

David Carlisle
  • 757,742
  • 2
    This is exactly what I've been looking for for two days. Thank you so much. – Zainab Iftikhar Jul 01 '21 at 09: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? – Zainab Iftikhar Jul 01 '21 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. – David Carlisle Jul 01 '21 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. – Zainab Iftikhar Jul 01 '21 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. – Zainab Iftikhar Jul 06 '21 at 03:36
  • @ZainabIftikhar I never use latexdiff, you'd need to check if it has options to diff the bib file, if it has you will be able to add those options on Overleaf – David Carlisle Jul 06 '21 at 05:51
  • @ZainabIftikhar: Did you figure out how to make changes to the bibliography? I have the same issue. Thanks. – Ali Babar Jul 06 '23 at 21:51
15

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

yo'
  • 51,322
  • 3
    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 '22 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? – João Bravo Jan 20 '23 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 Jul 06 '23 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. – Utkan Gezer Jul 30 '23 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 support@overleaf.com with a URL of a project where this doesn't work? I can then chek what's going on... – yo' Jul 31 '23 at 07:08
  • 2
    @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 Mar 07 '24 at 16:53