z·eeki·sh

tech log on gentoo, linux, and random stuff

Posts Tagged ‘includegraphics

sed one-liner for extracting pictures included in a tex file

leave a comment »

When writing up tex manuscripts, I usually put related data/function plots under the same directory as the tex file, or some sub-dir like ‘figs/’. Often times though, many of them are never actually used in the tex file. while I have no problem with cluttering up my folders with unused plots, it is quite painful when you need to pick out those used plots, for example when tar-balling them to share with a colleague or submit it to some journal. Here is a one-liner to extract a list of used plots in a tex file:

sed -n 's/[^%]*includegraphics[^{]*{\([^}]*\)}.*/\1/p' draft.tex

NB:

  1. draft.tex is the desired tex file from which to extract the list of figures.
  2. The -n tells sed to suppress printing unless instructed to (which will be effected by the tailing /p.
  3. The [^%] will skip plots commented out.

Here is the shell command to generate a tarball containing all necessary files:
tar -cvvzf draft.tgz draft.tex *bbl *bst $(for f in `sed -n 's/[^%]*includegraphics[^{]*{\([^}]*\)}.*/\1/p' draft.tex`; do echo `basename $f .pdf`.pdf; done)

Advertisements

Written by zsh

January 20, 2013 at 11:42 am

Posted in /usr/bin

Tagged with , , ,