I have a bunch of tables saved in separate files and folders which I have compiled with a master file, commenting the name of each file in the master file one by one and tediously renaming the resulting PDF output.
I have over one hundred tables produced over several months. Now I would like to recompile them all in a different style, so I'm looking for a way to automate the process.
Below is an unsuccessful attempt that builds on several suggestions found on this site, particularly this question.
To summarise in words what I tried to do in the code below:
- create files
a.texandb.texto be used as inputs (these are my tables); - define a command to store the file names as a
list,
aandb(no need to automate file naming); - a
foreachloop (packagepgffor) to call each input filea.texandb.texinside a basic document header/preamble (standaloneclass) and save it with the nametemp.tex; - followed by a call to
\immediate\write18{pdflatex...to run pdflatex ontemp.tex; - the intended output is two PDF files
named
a.pdfandb.pdf. I'm running this withshell-escapeenabled.
Needless to say it's not working and help is appreciated!
% !TeX TXS-program:compile = txs:///pdflatex/[--shell-escape]
\documentclass{article}
\usepackage{pgffor}% \foreach
\usepackage{filecontents}
\begin{filecontents*}{a.tex}
First file (a table without preamble)
\end{filecontents*}
\begin{filecontents*}{b.tex}
Second file (a table without preamble)
\end{filecontents*}
\newcommand*{\ListOfFiles}{a,b}
\foreach \x in \ListOfFiles{%
\begin{filecontents*}{temp.tex}%
\documentclass{standalone}%
%\usepackage{stylesforalltables}
\begin{document}%
\input{\x}
\end{document}%
\end{filecontents*}%
\immediate\write18{pdflatex -jobname=\x\space temp}
}%
for i in *.tex; do pdflatex $i;doneand get a directory full of pdf. (That's bash but you could do the same in any commandline . – David Carlisle Mar 17 '17 at 18:55for file in table*.tex; do ln -s $file temp.tex; pdflatex template.tex; mv template.pdf $(file%.tex).pdf; done. This assumes that names of all table source files start withtable, and that thetemplate.texfile sets up the desired document format and contains\input{temp}in the document body. – Michael Palmer Mar 17 '17 at 20:36filecontentsas argument of a command 2) don't use%at the end of line with\begin{filecontents*}{temp.tex}%3) try\input{\jobname}instead of\input{\x}. – touhami Mar 17 '17 at 22:34\jobnameinstead of\x, but it's easy enough to remember. Is there a short explanation for the layman for why a loop overfilecontentswouldn't work? – PatrickT Mar 18 '17 at 06:41filecontentswritesverbatimso intemp.texwe get\input{\x}and\xis undefined. – touhami Mar 18 '17 at 07:36