0

I have a pdfLaTeX/XeLaTeX file with iftex for compilation with either engine. I want to use latexmk to compile the source with -pdf/-pdflatex or -pdfxe/-xelatex options.

The goal is to get PDF output with different names <basename>-pdftex.pdf or <basename>-xetex.pdf via setting $jobname in latexmkrc. How can I check engine option used in latexmk invocation?

It seems that the command-line option does not set $pdf_mode. If I call latexmk -pdf, I still get $pdf_mode = 0. The documentation describes variable $rule but it is uninitialized when used in latexmkrc.

The solution can be to set -jobname in $pdflatex/$xelatex variables, but I wanted a somewhat more general approach with modification of the intended variable:

if ($pdf_mode == 0) { $jobname = "%A-tex"; }
elsif ($pdf_mode == 1) { $jobname = "%A-pdftex"; }
elsif ($pdf_mode == 2) { $jobname = "%A-ps2pdf"; }
elsif ($pdf_mode == 3) { $jobname = "%A-dvipdf"; }
elsif ($pdf_mode == 4) { $jobname = "%A-luatex"; }
elsif ($pdf_mode == 5) { $jobname = "%A-xetex"; }
else { $jobname = "%A-UNKNOWN"; }

1 Answer 1

0

The problem is that the code in latexmkrc is executed before the command line arguments are obeyed. You need something that is obeyed after the command line options setting the pdfmode are obeyed.

The only way I can see to do this within latexmk is to put your code in another rc file, say latexmkrc-jobname, and then invoke latexmk by, say

latexmk -pdflua -r latexmkrc-jobname file.tex

The contents of latexmkrc-jobname would be

if ($pdf_mode == 0) { $jobname = "%A-tex"; }
elsif ($pdf_mode == 1) { $jobname = "%A-pdftex"; }
elsif ($pdf_mode == 2) { $jobname = "%A-ps2pdf"; }
elsif ($pdf_mode == 3) { $jobname = "%A-dvipdf"; }
elsif ($pdf_mode == 4) { $jobname = "%A-luatex"; }
elsif ($pdf_mode == 5) { $jobname = "%A-xetex"; }
else { $jobname = "%A-UNKNOWN"; }
1
  • Well, I guess then it will be easier to set jobname in each engine call. Thanks for the hack!
    – Alekh
    Mar 31, 2022 at 12:10

You must log in to answer this question.

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