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
@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
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.
You can create a .sh
file using any text editor or the Terminal:
touch script.sh
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}
To run the script, you need to make it executable:
chmod +x script.sh
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.