Skip to content

Instantly share code, notes, and snippets.

@SHDShim
Last active June 9, 2024 03:29
Show Gist options
  • Save SHDShim/3c987e4a7428957b59570ca68a9258cf to your computer and use it in GitHub Desktop.
Save SHDShim/3c987e4a7428957b59570ca68a9258cf to your computer and use it in GitHub Desktop.
latex, latexdiff

Revising Overleaf/LaTeX articles using latexdiff

Preparation

  1. Go to the Overleaf website and move your original files in a new folder. For example, I would first make a folder: org and copy all the originally submitted files there. Or if you already have originally submtted files in a separate folder, I would rename it to org. These files should be not be changed, because these files will be compared with your revised files for making track changes in PDF.

  2. Make a folder for revised files. For example, I would make a new folder, named rev.

  3. Copy the files in the org folder to the rev folder. I found no straightforward way to copy files between different folders in Overleaf. So I download original files from the org folder to my hard drive, and then upload those files to the rev folder.

  4. Go back to Overleaf. In the Menu, change the Main document to the main tex file in your new rev folder.

Note that we will not change any files in the org folder. We will revise files in the rev folder.

Setup your new main document tex file.

The changes I describe below should be made for the main tex file (for example, my_main.tex) in the rev folder. Do not change any files in the org folder.

  1. Go to the top of the document and add the lines below if they do not already exist.
\usepackage{lineno}
\usepackage[usenames, dvipsnames]{color}
  1. Find \end{spacing} or \end{document} in your main file. Copy and paste the following lines right before these two. Depending on your document \end{spacing} may not exist, but \end{document} should exist.
\nolinenumbers
\clearpage{}
\setcounter{equation}{0}
\setcounter{figure}{0}
\setcounter{table}{0}
\setcounter{page}{1}
\setcounter{section}{0}
\makeatletter
\renewcommand{\theequation}{L\arabic{equation}}
\renewcommand{\thefigure}{L\arabic{figure}}
\renewcommand{\thetable}{L\arabic{table}}
\renewcommand{\thesection}{L\arabic{section}}
\renewcommand{\thepage}{L\arabic{page}}
\renewcommand{\bibnumfmt}[1]{[L#1]}
\renewcommand{\citenumfont}[1]{L#1}
%NewInRevision
\newenvironment{reviewer}{\par\addvspace{\baselineskip}\small\color{BlueViolet}}{\par\addvspace{\baselineskip}} %\fontfamily{cmvtt}\selectfont

{\Huge Rebuttal Letter}

How to revise the new main tex file.

  1. Revise. Do not worry about preserving old parts, they are all kept in the files you stored in the org folder.

  2. If you need to cite certain parts of your paper by line number do the following.

\linelabel{ln:revised:begin:LMILdiamond} I revised this part. \linelabel{ln:revised:end:LMILdiamond}

To cite these parts by line numbers,

Lines \ref{ln:revised:begin:LMILdiamond}--\ref{ln:revised:end:LMILdiamond}. We added this new sentence in this revision.

How to write a rebuttal letter

In the provided template, your rebuttal letter is included in the main tex file together with other parts. Go to the line below:

{\Huge Rebuttal Letter}
  1. Below these lines, you begin writing your rebuttal letter.

  2. Copy the following lines to the area and then start writing rebuttal letter.

\section{Editor}

\begin{reviewer}
Copy reviewers comments here.
\end{reviewer}

Write your answers here.

\begin{reviewer}
Copy reviewers comments here.
\end{reviewer}

Write your answers here.

\section{Reviewer \# 1}

\begin{reviewer}
Copy reviewers comments here.
\end{reviewer}

Write your answers here.

\begin{reviewer}
Copy reviewers comments here.
\end{reviewer}

Write your answers here.

\section{Reviewer \# 2}

\begin{reviewer}
Copy reviewers comments here.
\end{reviewer}

Write your answers here.

\begin{reviewer}
Copy reviewers comments here.
\end{reviewer}

Write your answers here.

Latexdiff tutorial for Mac OSX

We will make a new tex file with tracking information. The tracked tex files will be saved in diff folder.

(Warning) The following workflow was tested only for Ubuntu and Mac OSX.

Almost perfect one, works without an error or a fewer errors

Source: https://www.reddit.com/r/LaTeX/comments/2o98fq/latexdiff_frustration/

  1. latexdiff from MacTeX, TeX Live, and homebrew could make different results, particularly types of errors. Try all three and find the best working one for you. MacTex's version is typically in /Library/TeX/texbin/latexdiff. TeX Live is in /usr/local/texlive/2019/bin/x86_64-darwin. homebrew should be in /usr/local/bin. To setup for one of these, you can add path. For example, export PATH=/usr/local/texlive/2019/bin/x86_64-darwin:$PATH.

  2. Download of your org folder from Overleaf.

  3. Dowload of your rev folder from Overleaf. Of course you may use whatever name you want. Y

(Warning) Your original submission files and new revision files must exist in separate folders. Those separate folders must have all the necessary files, such as *.aux, *.blb, figure pdfs, etc. If you mix old and new files in the same folder, you will get a lot of errors.

  1. It is not absolutely necessary, but you may want to separately compile the main tex files in the org folder and rev folder to pdf's.

  2. Open a terminal and go to the newly made folder containing both org and rev folders. You can now execute latexdiff through one of the followings.

latexdiff -p diff-pre.tex --flatten --disable-citation-markup --replace-context2cmd="\author" --exclude-safecmd="in" ./org/main.tex ./rev/main.tex > ./diff/main.tex

--flatten : this option is not necessary anymore even when \include, \input, or \includegraphics exist in latex file.

--subtype=“SAFE” : this option does not seem to change anything

--disable-citation-markup : this option make no tracking for citation. OK option to avoid confusion because latexdiff does not distinguish new and old citations.

--appendsafecmd="nu.*,v.*,such.*{,}" : this option is not recognized by latexdiff anymore (as of 2024-05-13).

For PNAS, add the following option to latexdiff

--replace-context2cmd="significancestatement" 
  1. Then finally pdflatex diff.tex.

Only problem here is that this procedure does not take care of citation changes. But so far this is the best I could find.

Tips

  • If bibunits and normal bibliography citations are mixed, then latexdiff can fail. In this case, remove either one of the two and simplify.
  • You need to have a diff-pre.tex file in the current folder. If you had errors and try to recompile, make sure you delete all the files including aux, blg, and bbl.

diff-pre.tex file (preamble for latexdiff)

(2024-06-08) It appears that latest latexdiff no longer has problem with strike through text. Use one below instead:

\RequirePackage[normalem]{ulem}
\RequirePackage{color}
\definecolor{light-gray}{gray}{0.6}
\definecolor{lblue}{rgb}{0.6,0.6,1}
%DIF PREAMBLE
\RequirePackage[stable]{footmisc} %DIF PREAMBLE

%\RequirePackage{changebar} %DIF PREAMBLE
%\providecommand{\DIFadd}[1]{#1} %DIF PREAMBLE
\providecommand{\DIFadd}[1]{\textcolor{blue}{#1}} %DIF PREAMBLE
%\providecommand{\DIFdel}[1]{{\protect\color{red} [..\footnote{removed: #1}]}\xspace}

\providecommand{\DIFdel}[1]{{\protect\color{lblue}\sout{#1}}}

%DIF PREAMBLE in the line above, strike through often has issues with math and others. So I am trying color differences for removed.
%DIF PREAMBLE
%DIF SAFE PREAMBLE %DIF PREAMBLE
\providecommand{\DIFaddbegin}{} %DIF PREAMBLE
\providecommand{\DIFaddend}{} %DIF PREAMBLE
\providecommand{\DIFdelbegin}{} %DIF PREAMBLE
%\providecommand{\DIFaddbegin}{\protect\color{blue}} %DIF PREAMBLE
%\providecommand{\DIFaddend}{\protect\color{black}} %DIF PREAMBLE
%\providecommand{\DIFdelbegin}{\protect\cbdelete} %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

This file will decide the format for tracking. Currently striking through text creates a lot of problem, likely with Math text. Therefore, the file below make light-gray color for the deleted parts. The added parts will be in blue and the unchanged part will bein black.

\RequirePackage{color}
\definecolor{light-gray}{gray}{0.6}
%DIF PREAMBLE
\RequirePackage[stable]{footmisc} %DIF PREAMBLE
%\RequirePackage{changebar} %DIF PREAMBLE
%\providecommand{\DIFadd}[1]{#1} %DIF PREAMBLE
\providecommand{\DIFadd}[1]{\textcolor{blue}{#1}} %DIF PREAMBLE
%\providecommand{\DIFdel}[1]{{\protect\color{red} [..\footnote{removed: #1}]}\xspace}
\providecommand{\DIFdel}[1]{\textcolor{light-gray}{#1}} %DIF PREAMBLE
% in the line above, strike through often has issues with math and others.  
% So I am trying color differences for removed.
%DIF PREAMBLE
%DIF SAFE PREAMBLE %DIF PREAMBLE
\providecommand{\DIFaddbegin}{} %DIF PREAMBLE
\providecommand{\DIFaddend}{} %DIF PREAMBLE
\providecommand{\DIFdelbegin}{} %DIF PREAMBLE
%\providecommand{\DIFaddbegin}{\protect\color{blue}} %DIF PREAMBLE
%\providecommand{\DIFaddend}{\protect\color{black}} %DIF PREAMBLE
%\providecommand{\DIFdelbegin}{\protect\cbdelete} %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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment