Search code examples
latexcshxelatexlatexmk

latexmk and xelatex from shell script


I have asked this question at TeX - LaTeX Stack Exchange, but I fear it is closer to a programming question than to a TeX question, hence I'm asking it here. I hope this is alright. (The original question is Passing arguments to xelatex using latexmk.)

I have a single XeLaTeX source file which can generate two versions of the document depending on whether a certain command sequence testcs exists. I typically do this via a csh shell script which generates both versions and which looks like this:

set file = "Document"
xelatex -jobname="${file}-v1" "\def\testcs{1} \input{${file}.tex}"
xelatex ${file}.tex

My document now has an index and typesetting it now requires several passes through xelatex. I would typically use latexmk, such as

latexmk -pdfxe Document

and this works fine, but I now would like to generate the two versions of the document using the script.

In other words, I would like to modify the shell script to use latexmk, but I seem unable to pass the arguments to xelatex. I can pass the -jobname but I've had no such luck passing the \def\textcs{1} via any of the options: -xelatex, -pdfxelatex, -pretex,...

Question Is there a simple way to do that?


Solution

  • A slight modification from https://stackoverflow.com/a/57111010. The trick is that the -usepretex option is necessary to tell latexmk to actually do what you specified in -pretex

    set file = "Document"
    latexmk -pdfxe -jobname=${file}"-v1" -pretex="\def\testcs{1}" -usepretex ${file}