public
Created

Take all figures from a LaTeX document and make a new document with only them.

  • Download Gist
only-figures.sh
Shell
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
#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.*
template.tex
TeX
1 2 3 4 5
\documentclass{article}
\usepackage{pdfpages}
\begin{document}
\includepdf[pages={@@@}]{document}
\end{document}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.