Some academic journals, like PLoS One, require that you submit a final document as a single self-contained LaTeX file. All figures need to be submitted as separate image files, with any figures having multiple panels merged into a single image.
If you have a complex LaTeX source with a lot of \include
s and figures, this is a pain to do by hand. It is possible to do this automatically.
.tex
file
Assume your paper is called paper.tex
and currently has many \include
or \input
elements (e.g. \include{intro.tex}
, \include{theory.tex}
, ...)
First:
latex paper.tex
bibtex paper.tex
to generate paper.bbl
.
To make sure the bibliography is included in the source, change your source of paper.tex
to replace \bibliography{...}
with
\input{paper.bbl}
.
Then use latexpand to include all \input{}
and \include{}
files, as well as the bibliography into one file.
latexpand paper.tex > paper_merged.tex
latexpand
to work.The following is based on this StackOverflow answer by John Kormylo.
We can use the endfloat
package to split out all floats into a separate file. In the preamble of paper_merged.tex
, just after \documentclass
, add:
\usepackage{endfloat}
\usepackage{graphicx}
\makeatletter
\efloat@openpost{fff}
\efloat@iwrite{fff}{\string\textwidth=\the\textwidth}
\makeatother
Run pdflatex paper_merged
and you will get a new file paper_merged.fff
that has all the code for floating figures in it.
Create a new, blank document figures_separated.tex
with the following contents:
\documentclass[multi=figure]{standalone}
\usepackage{graphicx}
\usepackage{amsmath} % packages I used in figures
\usepackage{subfig}
%% Include all custom macros used in figures here
\renewenvironment{figure}{\ignorespaces}{\unskip}
\renewcommand{\caption}[2][]{\ignorespaces}
\newcommand{\Figure}[1]{\ignorespaces}
\let\efloatseparator=\empty
\newcommand{\titlecaption}[2]{}
\begin{document}
\input{paper_merged.fff}
\end{document}
If you've used any custom macros or packages inside your floats, you'll need to include the relevant packages and add any of your own macros from paper_merged.tex
into the preamble of separated_figures.tex
.
Then:
pdflatex separated_figures.tex
to produce separated_figures.pdf
which has each figure as a separate page.
PLoS One recommends all figures to be submitted as TIFF (unfortunately EPS is the only vector format PLoS support and it is not recommended...). imagemagick can convert this multi-page PDF to individual TIFF files in one go — if you configure it correctly!
output_images
magick convert -density 700 -scene 1 -background white -alpha remove \
-alpha off separated_figures.pdf "output_figures/fig%d.tiff"
%%d
instead of %d
to avoid shell escaping
You should now have one TIFF file per figure, named output_images/fig1.tiff
etc. You may need to adjust density
if the images are too high or too low resolution — density 700
looked about right for my configuration.
That's it, you're done!
John H Williamson