5

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):

\RequirePackage{myparameters}
\input{myfile}

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?

Denis Bitouzé
  • 9,652
  • 4
  • 27
  • 85
  • 4
    try pdflatex -jobname myfile "\input{myparameters.sty}\input{myfile}" –  Jan 06 '14 at 18:42
  • 3
    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 06 '14 at 18:58
  • @Herbert It doesn't work with \input{myparameters.sty} (and that would probably be not easy to debug) but it does with \RequirePackage{myparameters}. Now, I just have to see how to include this command line in a latexmk process. – Denis Bitouzé Jan 06 '14 at 19:52
  • @PeterGrill In fact I have only one alternative: either the parameters are passed or they don't. But my use case is a bit particular: myfile.tex is a sample file using a class I'm working on and is intended 1) to be screenshots for the class doc (this involves parameters in order to extract the relevant pages, thanks to zref package and this method); 2) to be compiled by users who want to try the class (and, for this, it is required to not disturb the file with strange parameters). – Denis Bitouzé Jan 06 '14 at 20:18
  • or you could simply do: \def\myfile{parameters}\input{file} and in file do: \ifdefined\myfile\input{\myfile}\fi – nickpapior Jan 06 '14 at 20:23
  • @zeroth Well, I'm not sure to understand. To precise what I told @PeterGrill, myfile.tex is in .../texmf/doc/latex/myclass/sample/ and, with a symlink, in .../texmf/source/latex/myclass/sample/. I want to let myfile.tex intact in .../texmf/source/latex/myclass/sample/ but apply in this directory some parameters useful for the class documentation whose source is in .../texmf/source/latex/myclass/. – Denis Bitouzé Jan 06 '14 at 20:43
  • 1
    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 06 '14 at 20:45
  • 1
    @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 07 '14 at 03:49
  • @PeterGrill Okay, I've understood. But I prefer to work with only one file (the original one). Hence I'm happy with pdflatex -jobname myfile "\RequirePackage{myparameters}\input{myfile}". I don't know f I can answer my question myself with that answer. – Denis Bitouzé Jan 07 '14 at 14:48
  • @DenisBitouzé: Yes, self answers are perfectly acceptable. But, with your solution you are still working with two files. – Peter Grill Jan 07 '14 at 19:49
  • @PeterGrill I don't see your point when you say that I'm still working with two files: only the myfile.tex file (okay, twice, but via a symlink) is involved, and not the two files myfile.tex and supermyfile.tex. – Denis Bitouzé Jan 14 '14 at 08:02
  • The two files being: myfile.tex and the required package myparameters.sty. – Peter Grill Jan 14 '14 at 18:19
  • @PeterGrill Oh, yes, of course! I meant I prefered to work with only one .tex file (the original one). – Denis Bitouzé Jan 14 '14 at 18:59
  • 1
    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
  • @PeterGrill OK, understood now. – Denis Bitouzé Jan 14 '14 at 19:07

1 Answers1

1

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
Denis Bitouzé
  • 9,652
  • 4
  • 27
  • 85
  • 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