LaTeX is beautiful, yet exporting a PDF file including track changes is painful. This repository explains how to export a PDF file with track changes with LaTeX.
Latex's way of introducing track changes into a PDF is to use a function inside the text that indicates which lines of text were removed in favor for other text. Packages such as \usepackage{changes}
provide functions which can be used as follows:
\documentclass{article}
\usepackage{changes}
\begin{document}
This is \deleted{the best} \added{some example} text.
\end{document}
While we could, theoratically, insert all revisions using these functions, this is ridiculously effortful. Instead, we want LaTeX to compare two .tex files and create a new .tex file in which LaTeX, for us, inserts the functions wherever the two compared files differ (both where text was deleted and where text was added).
- Install perl
- Install MikTeX
- Install
latexpand
andlatexdiff
package - Download source .tex file (e.g., from overleaf) with and without revisions.
- Merge hierarchical .tex files using
latexpand
(only necessary when main.tex files impots other .tex files, which is highly recommended). - Compare merged files using
latexdiff
. - Upload the created .tex file to overleaf to compile a PDF file with track changes.
- Enjoy the PDF file with track changes.
Following this tutorial, the LaTeX scripts we will use later require the installation of perl. Install it from here. Make sure you use the strawberry installation when on windows.
Install MikTeX from here.
Once MikTeX is installed, open the MikTeX console
, navigate to packages
and look for the packages latexpand
and latexdiff
. Install them.
When you work in Overleaf, download the source file of the two versions that you want to compare. While overleaf offers the option to insert track changes, to date, it does not provide an option to export a PDF that includes track changes. In Overleaf, navigate to Menu
> Source
. This will download the source file. Unzip the source file. Do this for both the version with and without the revisions. You can open an earlier version of your document by navigating to History
. If you labelled the earlier version, open the labeled earlier version. Otherwise browse through the history.
I personally liked it best to push the version without ad with track changed to github. For that, navigate to Menu
> GitHub
and commit + push the version without and with track changes to GitHub. Then clone the repository. Using github desktop
, you can easily switch between commits, that is, the two versions of your file. Copy both versions to a seperate folder.
To date, latexdiff
cannot handle .tex files that import other .tex files. This is why we first need to build one big .tex file in which the text of all imported files is simply copied. Instead of doing that manually (we want to avoid human errors), we let latexpand
do this for us. In the MiKTeX console, open the command window
(the black screen on the left). In the command window, navigate the current folder to the folder in which the .tex source file without track changes lies, by using cd C:\path\to\your\source\files
. Then type latexpand main.tex > without_tc.tex
.
Then change the current directory to the folder with the .tex source file with track changes. Type latexpand main.tex > with_tc.tex
. This will create two new merged .tex files. Copy them into a new folder.
In the command window
, change the current directory to the folder in which the merged .tex file lie. Then type latexdiff without_tc.tex with_tc.tex > track_changes.tex
. This will create a new .tex file in which all differences betwen without_tc.tex
and with_tc.tex
are marked with function calls.
Upload track_changes.tex
to into your original project in overleaf and compile the .tex file. First change the main file in overleaf by navigating to menu
> main_document
> track_changes.tex
. Then compile the file.
Enjoy your PDF file with track changes