Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

It is possible to pass some parameters when compiling a myfile.tex file:

pdflatex "\some\parameters\input{myfile}"

But, if the number of parameters increase, this is not very practicable. So I'd like to store them in a file (possibly a personal package), say myparameters.sty, and load them at the compilation time. Of course:

pdflatex "\input{myparameters.sty}\input{myfile}"

doesn't work as the compiled file is myparameters.sty. But, whereas the following file (say supermyfile.tex):


compiles like a charm with:

pdflatex supermyfile

the following:

pdflatex "\RequirePackage{myparameters}\input{myfile}"

doesn't work as the compiled file is myparameters.sty here as well.

Hence my question: how to pass (a lot of) parameters to a file at compilation time?

share|improve this question
try pdflatex -jobname myfile "\input{myparameters.sty}\input{myfile}" –  Herbert Jan 6 '14 at 18:42
I would recommend defining flags for the various compiles that you have. Assuming you don't have hunderds of different possible combinations, I would recommend have conditionals in your standard myparameters.sty and defining the parameters based on flags that you set on the command line. For example \ifdefined\DebugMode ... \else ... \fi, \ifdefined\VerboseMode ... \else ... \fi., etc. –  Peter Grill Jan 6 '14 at 18:58
I managed to include the command line pdflatex -jobname myfile "\RequirePackage{myparameters}\input{myfile}" in a latexmk process with latexmk -pdf -jobname=myfile -pdflatex="pdflatex %O '\RequirePackage{myparameters}\input{%S}'" myfile.tex –  Denis Bitouzé Jan 6 '14 at 20:45
@DenisBitouzé: What I meant is that since you say pdflatex supermyfile works, place all your code in myparameters, and on the command line say something line pdflatex "\def\ModeA{}\input{supermyfile}", and in myparameters define all the conditions required for ModeA, etc. I think if you provided a more detailed example of exactly what you want things might be simpler. If it is a list of pages you could define a list on the command line as well. –  Peter Grill Jan 7 '14 at 3:49
That was what I was suggesting: One .tex file and one myparameters.sty file that had the conditionals defined for all the various settings that you desire to control form the command line. –  Peter Grill Jan 14 '14 at 19:06

1 Answer 1

up vote 1 down vote accepted

Thanks to Herbert's suggestion, here is the (at least an) answer to my question. It is possible to pass (a lot of) parameters to a .tex file (say myfile.tex) at compilation time, by storing them in a personal package (say myparameters.sty) and by running:

pdflatex -jobname myfile "\RequirePackage{myparameters}\input{myfile}"

Moreover, this can be included in a latexmk process with:

latexmk -pdf -jobname=myfile -pdflatex="pdflatex %O '\RequirePackage{myparameters}\input{%S}'" myfile.tex
share|improve this answer
I can't see why \input{myparameters} shouldn't work, if the file is myparameters.tex; or \input{myparameters.sty} if you prefer this name. –  egreg Jan 14 '14 at 21:41
Indeed, except extra \makeatletter and \makeatother may be needed in case of \input instead of \RequirePackage. –  Denis Bitouzé Jan 21 '14 at 14:03

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.