Skip to content

Instantly share code, notes, and snippets.

@martinchapman
Last active May 18, 2023 15:25
Show Gist options
  • Save martinchapman/d42c483771f89c6524b0b215da8e086c to your computer and use it in GitHub Desktop.
Save martinchapman/d42c483771f89c6524b0b215da8e086c to your computer and use it in GitHub Desktop.
Visualise a latex document git history
# Visualise a latex document git history
# loop through commits, create a PDF from your main file for each
# translate the pages of that PDF to a single image
# create GIF/mp4 from the folder of images created
# run within your local repository
# prerequisites: ImageMagick and FFmpeg
# create output folder
mkdir mosaic
# pull latest
git pull
echo "Processing commits..."
# move backwards through the commit history
# change branch name as necessary
for commit in $(git rev-list master)
do
# hard reset files to that commit
git reset --hard $commit
# assumes main file is 'main.tex'
# multiple passes for bib...
# skip any compilation failures
pdflatex -interaction=nonstopmode -halt-on-error main.tex
bibtex main.aux
pdflatex -interaction=nonstopmode -halt-on-error main.tex
pdflatex -interaction=nonstopmode -halt-on-error main.tex
# lay document out on (constant) suitably sized grid
# here, 4x3 for max 10 pages
# output as timestamped pdf to mosaic folder
montage -geometry 250x250+0+0 -tile 4x3 main.pdf mosaic/out-$(date +"%T").png
done
echo "Creating GIF..."
# create (reverse) GIF from mosaic folder (this can be time consuming; play with flags accordingly)
# modify delay as needed
convert -reverse -delay 3 -loop 0 -limit map 0 mosaic/*.png mosaic.gif
# output as video also, if needed
ffmpeg -i mosaic.gif -movflags faststart -pix_fmt yuv420p -vf "scale=trunc(iw/2)*2:trunc(ih/2)*2" mosaic.mp4
@martinchapman
Copy link
Author

To add, ImageMagick and FFmpeg are prerequisites. Not sure what support for them is like on Windows

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