Arara problem with xelatexmk rule
Update below:
The error occurs of two reasons
- The argument of
latexmk
doesn't like spaces. (This can be solved) - You can't pass options to
latexmk
. I guess the perl interpreter can handle this. The author ofarara
mentioned that expansion is being done correctly byarara
, the tricky part relies on the replacement code that is submitted to the Perl interpreter via-e
flag forlatexmk
.
The complete explanation why it works with Windows and not with Unix/Mac can be found in the documentation of latexmk
page 5
Some care is needed to deal with proper quoting of special characters in the code on the command line. For example, suppose you want to set the latex command to use its
-shell-escape
option, then under UNIX/LINUX you could use the linelatexmk -e '$latex=q/latex %O -shell-escape %S/' file.tex
Note that the single quotes block normal UNIX/LINUX command shells from treating the characters inside the quotes as special. (In this example, the
q/.../
construct is a Perl idiom equivalent to using single quotes. This avoids the complications of getting a quote character inside an already quoted string in a way that is independent of both the shell and the operating-system.) The above command line will NOT work under MS-Windows withcmd.exe
orcommand.com
or4nt.exe
. For MS-Windows with these command shells you could uselatexmk -e "$latex=q/latex %O -shell-escape %S/" file.tex
or
latexmk -e "$latex='latex %O -shell-escape %S'" file.tex
The last two examples will NOT work with UNIX/LINUX command shells.
You can use a simple latexmk
rule like the example below or you combine some basic rules like xelatex
, makeindex
and clean
.
Please use the following rule:
!config
# Simple LaTeXmk with XeLaTeX rule for arara
# author: Marco Daniel
identifier: xelatexmk
name: XeLaTeXmK
command: 'latexmk -e "$pdflatex=q/xelatex%O%S/" -pdf @{file}.tex'
arguments: []
In the new version 4.31 (or newer) of latexmk
John Collins provides some extra options. John Collins wrote:
By the way, since v. 4.31, latexmk supports as options most of the options to pdflatex and friends, including
-synctex=...
and-interaction=....
It also has an-xelatex
option. So there is much less need now to use complicated constructs to get the desired command line to pdflatex. Unfortunately I didn't (yet) get this into the documentation. Runlatexmk --showextraoptions
to see which options it currently supports, beyond the ones listed bylatexmk --help
. – John Collins 4 hours ago
Based on this information you can use the following rule with all options inside the tex-file.
!config
# LaTeXmk with XeLaTeX rule for arara
# author: Brent Longborough
# last edited by: Brent Longborough
# made to work by: Paulo Cereda
identifier: xelatexmk
name: XeLaTeXmKFixed
command: 'latexmk -e "$pdflatex=q/xelatex%O%S/" @{ action == "" ? "" : " -interaction=" + action } @{ synctex == "" ? "--synctex=1" : synctex } @{shell} @{expandoptions} @{ist} -pdf @{file}.tex'
arguments:
- identifier: action
flag: '@{value}'
- identifier: shell
flag: '@{value.toLowerCase() == "yes" || value.toLowerCase() == "true" || value.toLowerCase() == "on" ? " -shell-escape" : " -no-shell-escape" }'
- identifier: synctex
flag: '@{value.toLowerCase() == "no" || value.toLowerCase() == "false" || value.toLowerCase() == "off" ? " -synctex=0" : " -synctex=1" }'
- identifier: expandoptions
flag: ' @{value}'
- identifier: ist
flag: ' -e "$makeindex=q/makeindex %O -s @{value}.ist -o %D %S/"'
The practical answer is given by Marco, I'll just complement with some excuse explanation. :)
First of all, thank you very much for this case study. :)
I'll surely take a deep look into this curious behaviour and try to get some answers.
For now, I'll simply complement Marco's answer, which gives you a practical solution and it's indeed the right way to go.
As the great John Collins mentions in the latexmk
manual, it's quite complicated to make things work cross-platform exactly the way we expect them to work. Each system has its own features, limitations and annoyances.
arara
relies on a library to make system calls. This is needed because not every operating system behaves the same - even amongst the Unix-like, we can have limited buffer sizes which lead to deadlocks. This core component of arara
works very well, but sadly there might be tricky entries which mislead the algorithm.
Just an example: arara
doesn't allow subshells or concatenation of commands. This behaviour is actually good, IMHO. It's a way of forcing users to write more concise rules.
For latexmk
, a simple plain rule works fine. Now, with a more sophisticated structure, things might become confusing. Thanks to the SystemUtils
orb tag, we can add conditional expressions regarding specific commands according to the underlying operating system; we could easily replace double quotes by single quotes, as the latexmk
manual says so. But we are dealing with a more complex command, which involves deliberately altering a Perl variable from a latexmk
call.
The -e
flag from latexmk
allows us to inject an arbitrary value to the execution flow. From arara
, we can see - through the generated .log
- that the expansion of the directives into a command is concise - the command is actually correct, if we copy/paste it in the terminal and run it. The real issue is how the arara
execution component is parsing the whole command into executable + arguments. It appears there are problems with treating the whole value from the -e
flag as only one string.
Sadly I have no way of testing it right now. Thankfully, in a few days, I'll have my Mountain Lion and TeX Live 2012 up and running, so I can report back. For now, writing a simple rule, as Marco suggests, it's the only way I see.
Neither latexmk
or arara
are culprits here. Or at least, we can't blame arara
for guessing the wrong parsing of a complex command. It usually gets everything right, but you know, we always have a few exceptions. I'll see what I can do, maybe for the next release.
An update to the excellent but outdated earlier answers:
With Arara 4.0, it is now possible to use xelatex with the latexmk rule % arara: latexmk: { engine: xelatex }
. See page 116 of the official manual.