Recently I need to submit to a journal that does NOT accept the final PDF but requires all LaTex sources so that they can compile the PDF on their own. Given that any LaTex projects with reasonable size would have multiple *.tex, *.bib and figure files. It'll be nice to flatten the LaTex project so that we have as few as files to upload. Here is how.

## latexpand

There is a latexpand utility that comes with the TexLive package in Ubuntu. It does almost exactly what we need: expand latex files. I used it as follows:

 1 $latexpand --expand-bbl main.bbl main.tex -o all-in-one.tex The --expand-bbl option will replace the \bibliography command with a list of bibitem so that the main.bib does not need to be uploaded. The all-in-one.tex will be the ONLY LaTex file we need to upload. ## Figures We still need to upload all the included figures. Often times we generate more figures than we actually include in the final manuscript. We can get the list of actually included figures using this command:  1$ grep "includegraphics" all-in-one.tex | cut -d \{ -f 2 | cut -d \} -f 1

One caveat is that if all figures are put in a dedicated directory, e.g., ./figures, you'll have to use Latex's \graphicspath command to specify the path, and use only the file name in includegraphics. In other words, \includegraphics{./figures/abc.pdf} will not work in the all-in-one.tex unless you create that directory structure in the submission site. So instead, do this:

 1 2 3 4 5 6 7 \usepackage{graphicx} % note the path must ends with "/" \graphicspath{{./figures/}} \begin{figure} \includegraphics{abc.pdf} \end{figure}

With the above organization, this Makefile snippet will generate the all-in-one.tex file and also copy all included figures into a separate directory (submitted).

 1 2 3 4 5 submit: @mkdir -p submitted @latexpand --expand-bbl main.bbl main.tex -o submitted/all-in-one.tex @$(foreach fig,$(shell grep "includegraphics" submitted/all-in-one.tex | cut -d \{ -f 2 | cut -d \} -f 1), /bin/cp -rfv ./figures/\$(fig) submitted/;) # note the final semi-colon in the last command

The files in submitted directory is all the files you need to upload.