[texhax] Passing Command Line Arguments to a Latex document

Oleg Katsitadze olegkat at gmail.com
Thu Jul 12 09:53:11 CEST 2007

On Thu, Jul 12, 2007 at 02:56:55AM +0200, Reinhard Kotucha wrote:
> The following script allows you to pass command-line arguments to TeX.
> You can say:
>     pdflatex pdfselect '[pages={3,5}]{my_pdf_file}' 
> _____ pdfselect.tex ____________________
> \documentclass{minimal}
> \usepackage{pdfpages}
> \pagestyle{empty}
> \DeclareGraphicsRule{.PDF}{pdf}{.PDF}{}
> \DeclareGraphicsExtensions{.pdf,.PDF}
> \def\doit#1 {\begin{document}%
> \includepdf#1
> \end{document}}
> \everypar{\setbox0\lastbox\doit}
> ________________________________________

Ok, I see what you mean.  But this is a rather specialized
application, I don't think it's possible to generalize it so that
pdfselect.tex could continue in the usual manner after obtaining the
command line arguments.  This is what actually happens:

tex concatenates non-option arguments into one line, with spaces
between the arguments, and uses that as the first input line.  If the
first line begins with `&', tex takes what follows as the name of a
format file to load; after this, if what remains doesn't begin with
`\', tex inserts \input.  (In reality this is a little trickier, see
`man 1 tex'.)

Thus the call

  $ pdflatex pdfselect '[pages={3,5}]{my_pdf_file}'

is equivalent to

  $ pdflatex 'pdfselect\relax [pages={3,5}]{my_pdf_file}'

(\relax prevents the whole argument being treated as a filename -- for
some reason, it is required on the command line, but not when you
_enter_ the commands at the tex prompt), which is equivalent to

  $ pdflatex '\input pdfselect [pages={3,5}]{my_pdf_file}'

So, basically you don't get anything with several arguments that you
didn't have with one argument (maybe ease of use in some cases).

But thanks for the nice \everypar trick.


More information about the texhax mailing list