Instantly share code, notes, and snippets.

# henrikh/only-figures.sh Created Apr 15, 2012

What would you like to do?
Take all figures from a LaTeX document and make a new document with only them.
 #It's a shell script that should work on all Unix systems with pdflatex and pdfpages installed. You use by giving it the file name of the tex file (no .tex ending!) and the offset in pages (caused by front matter) as the second argument: # # ./only-figures.sh document 1 # # #First we load the .aux and prepare to store it in a variable. STR=$(cat$1.aux |\ #We only care about the lines with figures. grep figure |\ #And of these lines we only care about the number referring to unique pages. sed 's/.*}}{$$[1-9]*$$}}/\1/' | uniq |\ #We then add the offset to the page numbers. awk '{print $0+'$2'}' |\ #And finally pack them all up in a comma-separated list. sed ':a;N;$!ba;s/\n/,/g') #A template file is used for the new temporary document. cat template.tex | sed s/@@@/$STR/ > only-figures-tmp.tex #We call pdfLaTeX on the temporary file, move the new PDF and cleans up. pdflatex only-figures-tmp mv -f only-figures-tmp.pdf \$1-only-figures.pdf rm only-figures-tmp.*
 \documentclass{article} \usepackage{pdfpages} \begin{document} \includepdf[pages={@@@}]{document} \end{document}