8

Can the LaTeX executable receive arguments from the command line to be used as internal variables?

That is, can a command like ./latex document.tex a=3 b=rational c=-17.2 d=true be used to pass values that will be used to compile document.tex?

2

1 Answer 1

14

The command line design for running TeX is very old, so you can find it very atypical. The command switchers (like -ini, -jobname) are read first. If next object is not - nor \ then it is assumed that this is first letter of main file name. This is typical case, for example:

tex -ini plain.tex '\dump'

After file name is read, the file is read and if tex doesn't finish its job by \end or \dump primitive, then the rest of the command line is read and next input is from terminal console. Example above finishes TeX job by \dump given at command line.

If here is \ instead of the "normal first letter of file name", then the command line is interpreted. Typically there can be \def or \let and, of course, \input file. For example

tex '\def\name{b} \input filename'

Note that there is '...' because we don't want to interpret the \ by command shell.

The Unix implementations of TeX propagates its arg0 to the running program and it is converted to -fmt arg0. For example there is symbolic link latex -> pdftex. When you run

latex document

then the pdftex is called (due to the symbolic link) and the arg0 of the command line is propagated, so the result is:

pdftex -fmt latex document

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .