# Arara problem with xelatexmk rule

After many tests in Mac OS X and Ubuntu, I haven't been able to run arara with Brent Longborough's xelatexmk.yalm rule. No matter what I do, arara seems to run latexmk with pdflatex, not with xelatex. I've discussed the issue with Brent, who kindly gave me the assistance he could, but to no avail. (This issue doesn't happen to him, even when using my files!) I am not using any .latexmkrc file for the tests.

If I try to use other of arara's rules (e.g., xelatex.yalm), they work without problem. There's something with my system (systems!), or with my setup, which doesn't allow me to use Brent's xelatexmk.yalm rule.

Any ideas?

This is my MWE:

% arara: xelatexmk
\documentclass{article}
\usepackage{xltxtra}
\begin{document}
Testing . . .
\end{document}


Here is my compilation log file, for this run: http://pastebin.com/jXYPQhAz

Here is arara's log file: http://pastebin.com/VYMi4Xca

This is my xelatexmk.yalm 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: XeLaTeXmK
command: 'latexmk -e "$pdflatex=q/xelatex @{ action == "" ? "" : "--interaction=" + action } @{shell} @{ synctex == "" ? "--synctex=1" : synctex } @{expandoptions} %O %S/" @{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/"'


I'm using TeXLive 2012 (all updates) in Ubuntu 12.04 LTS Precise Pangolin (all updates). And MacTeX 2012 (all updates) in OS X Mountain Lion (all updates). Also, I'm using the latest versions of arara (v.2.0) and of latexmk (v.4.31).

-
Same results here in MacTeX, in OS X Lion. (It's strange, because I remember successfully using xelatexmk sometime ago... But I can be wrong.) – NVaughan Aug 10 '12 at 18:18

Update below:

The error occurs of two reasons

1. The argument of latexmk doesn't like spaces. (This can be solved)
2. You can't pass options to latexmk. I guess the perl interpreter can handle this. The author of arara mentioned that expansion is being done correctly by arara, the tricky part relies on the replacement code that is submitted to the Perl interpreter via -e flag for latexmk.

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 line

latexmk -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 with cmd.exe or command.com or 4nt.exe. For MS-Windows with these command shells you could use latexmk -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. Run latexmk --showextraoptions to see which options it currently supports, beyond the ones listed by latexmk --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/"'


-
Thanks, this worked indeed. However, I wonder why the former rule didn't work in *nix but did in Windows. Is it due to the parsing of spaces? But isn't that done by java, in this case? – Dwalsh Aug 11 '12 at 0:13
Actually, one of the annoying problems under UNIX/LINUX is that when a shell sees a string '$latex', it substitutes the value of an environment variable named 'latex', whereas with these command lines you want the string '$latex' to get through the shell to latexmk. – John Collins Aug 11 '12 at 2:22
@Dwalsh: Please see my update. – Marco Daniel Aug 11 '12 at 7:10

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.

-
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. Run latexmk --showextraoptions to see which options it currently supports, beyond the ones listed by latexmk --help. – John Collins Aug 11 '12 at 2:11
@JohnCollins: Great info. Now the rules works well. – Marco Daniel Aug 11 '12 at 7:10
@JohnCollins: That's really good news, John. Thank you. – Brent.Longborough Aug 11 '12 at 7:30
@JohnCollins: Thank you very much, John! :) – Paulo Cereda Aug 11 '12 at 9:56

By removing the double-quotes (") from the rule, it appears to work now. I've replaced the (")s with pairs of (')s, which appears to be the way to escape single quotes in the rule.

There is still more testing to do, but I understand this solves OP's problem.

The corrected rule is:

!config
# LaTeXmk with XeLaTeX rule for arara
# author: Brent Longborough
# last edited by: Brent Longborough
# made to work on Win by: Paulo Cereda
# and on Unix & Mac by: Marco Daniel
# and then by Brent Longborough again, maybe
identifier: xelatexmk
name: XeLaTeXmK
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/'''

-