Skip to content
Create a gist now

Instantly share code, notes, and snippets.

Embed URL


Subversion checkout URL

You can clone with
Download ZIP
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:
# ./ 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.*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.