Skip to content

Instantly share code, notes, and snippets.

@FedericoTartarini
Last active March 7, 2025 07:54
Show Gist options
  • Save FedericoTartarini/1482d2230c670d4e97de379409e24d6b to your computer and use it in GitHub Desktop.
Save FedericoTartarini/1482d2230c670d4e97de379409e24d6b to your computer and use it in GitHub Desktop.
latexdiff commands YouTube video

Commands shown in the video

latexdiff -h

latexdiff main.tex revision.tex > diff.tex

latexdiff --flatten main.tex revision.tex > diff.tex

latexdiff --flatten -t CTRADITIONAL main.tex revision.tex > diff.tex

latexdiff --flatten -t CFONT main.tex revision.tex > diff.tex

Windows script

@echo off
setlocal

set "old_path=..\latex_diff\"
set "new_path=..\latex_diff_revision\"
set "doc_name_filename=main"

echo Generate %doc_name_filename%_flat.tex for %new_path%
cd %new_path%
latexpand %doc_name_filename%.tex > %doc_name_filename%_flat.tex

echo Generate %doc_name_filename%_flat.tex for %old_path%
cd %old_path%
latexpand %doc_name_filename%.tex > %doc_name_filename%_flat.tex

echo Generate diff
cd %new_path%
latexdiff %old_path%%doc_name_filename%_flat.tex %doc_name_filename%_flat.tex > diff.tex
pdflatex  --max-print-line=10000 -shell-escape -synctex=1 -interaction=nonstopmode -file-line-error -recorder  diff.tex 2>&1 > NUL
echo PDF generated in case of problems see diff.log

echo Cleaning up
del %doc_name_filename%_flat.tex
del %old_path%%doc_name_filename%_flat.tex

pause

MacOS/Linux script

On macOS, the equivalent of a .bat (batch) file in Windows is a shell script with a .sh extension. Shell scripts are written for a Unix-based shell, such as Bash or Zsh, and are used to automate tasks and execute commands.

Steps to Create and Run a Shell Script on macOS

1. Create the Shell Script File

You can create a .sh file using any text editor or the Terminal:

touch script.sh

2. Add Commands to the Script

Open the file in a text editor (e.g., nano or vi) and add commands, starting with the shebang (#!/bin/bash or #!/bin/zsh):

nano script.sh

Content:

#!/bin/bash
export old_path=/original/
export new_path=/revision/
export doc_name_filename=main
export flat_extension=_flat.tex

echo Generate ${doc_name_filename}_flat.tex for ${old_path}
cd ../${old_path}
latexpand ${doc_name_filename}.tex > ${doc_name_filename}${flat_extension}

echo Generate ${doc_name_filename}_flat.tex for ${new_path}
cd ../${new_path}
latexpand ${doc_name_filename}.tex > ${doc_name_filename}${flat_extension}

echo Generate diff
latexdiff ../${old_path}${doc_name_filename}${flat_extension} ${doc_name_filename}${flat_extension} > diff.tex

# Compile the document multiple times
pdflatex -shell-escape -synctex=1 -interaction=nonstopmode -file-line-error -recorder diff.tex 2>&1 > /dev/null
bibtex diff 2>&1 > /dev/null  # Include this if you are using BibTeX
pdflatex -shell-escape -synctex=1 -interaction=nonstopmode -file-line-error -recorder diff.tex 2>&1 > /dev/null
pdflatex -shell-escape -synctex=1 -interaction=nonstopmode -file-line-error -recorder diff.tex 2>&1 > /dev/null

echo PDF generated in case of problems see diff.log

echo Cleaning up
rm ${doc_name_filename}${flat_extension}
rm ../${old_path}${doc_name_filename}${flat_extension}

3. Make the Script Executable

To run the script, you need to make it executable:

chmod +x script.sh

4. Run the Script

Execute the script by typing:

./script.sh

Please note that you may need to run the command twice to make sure that all the acronyms and glossaries are compiled.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment