3

I have a pgfplots main.tex file which plots a graph from an input file. I would like to run it on 100 input files and automate creating 100 PDF pictures. How can I do that?

The files are named as frame1, frame2, ..., frame100.

eli
  • 741
  • Inside main.tex \foreach \frame in {frame1,frame2,...,frame100}{<code that plots from a file where you substitute the file name with \frame>}. – Manuel Oct 02 '15 at 17:54
  • This draws each plot on previous plot, so that you get only one plot. I need 100 PDF plots, each cropped based on standalone class. – eli Oct 02 '15 at 18:07
  • I think standalone has an option multi={tikzpicture} so every tikzpicture gets its own page. – Manuel Oct 02 '15 at 18:20
  • see http://tex.stackexchange.com/questions/5228/can-one-tex-file-output-to-multiple-pdf-files or, http://tex.stackexchange.com/questions/74243/automatically-create-two-pdf-output-files-from-one-tex-file, or http://tex.stackexchange.com/questions/162042/multiple-pdf-generation-with-one-tex-file or http://tex.stackexchange.com/questions/31334/how-to-create-individual-chapter-pdfs – touhami Oct 02 '15 at 18:33

1 Answers1

9

The way to pass an argument to a TeX file is pdflatex "\\def{\\foo}{bar}\\include{filename}".

For example, say filename.tex contains the following.

\documentclass{article}
\begin{document}
The passed-in argument was ``\eggs.''
\end{document}

Then, if I compile it with pdflatex "\\def\\eggs{wine}\\include{filename}", the PDF says 'The passed-in argument was "wine." '

This allows you to pass arguments to a TeX file in a shell script, which to me is usually easier than trying to get one call to pdflatex to output multiple PDFs; it also doesn't need \write18.

#!/bin/bash

for i in {1..100}
do
    pdflatex "\\def\\inputname{frame$i}\\include{main}"
done
Arun Debray
  • 7,126
  • 2
  • 30
  • 54
  • 2
    Thanks! Works good. The braces around {1..100} should be removed though. Either "for i in 1 2 3" or "for (( i=0 ; i < 101 ; i++ )); do" – eli Oct 03 '15 at 13:03