Compile XeLaTeX tex file with latexmk
Asked Answered
G

5

32

How can one compile a XeLaTeX tex document using latexmk on Mac OS X?

At present I am running latexmk job.tex and getting an error:

! 
 ********************************************
 * XeTeX is required to compile this document.
 * Sorry!
 ********************************************.
\RequireXeTeX ...********************************}
                                                  \endgroup \fi 
l.18 \RequireXeTeX

? ^D
! Emergency stop.
\RequireXeTeX ...********************************}
                                                  \endgroup \fi 
l.18 \RequireXeTeX

The first line of my tex file is (as suggested by this post):

% !TEX TS-program = xelatexmk

and I've tried others (e.g. program=xelatex), but to no avail.

latexmk describes its commands as follows:

$ latexmk -commands xelatex job
Commands used by latexmk:
   To run latex, I use "latex %O %S"
   To run pdflatex, I use "pdflatex %O %S"
   ...

There doesn't appear bo be any logical mechanism for selecting a tex program from the command line, and it's not clear from the source how one would do this, either.

I've also looked atrubber, but it doesn't seem to work either.

I appreciate any insight you may be able to provide.

Brian

Gerontocracy answered 26/6, 2010 at 14:50 Comment(1)
Which version of latexmk are you using? Besiedes the original, there is the Texshop version of latexmk maintained by Herbert Schulz, or the Texlive default version by John Collins? Look at the output to latexmk -v to see which. Only the Texshop version comes packaged with xelatexmk and recognises !TEX directives; with the jcc version you will have to write an RC file to invoke xelatex and how to handle xdv files.Logger
C
11

That's my quick fix, so that latexmk works with XeLaTeX:
Add

`elsif (/^-xelatex$/) { $pdf_mode = 1; $pdflatex = 'xelatex %O %S'; $pdf_previewer =
'start evince %O %S';}`

above (or near) the line

`elsif (/^-pdf$/) { $pdf_mode = 1; }`

.

Then you can call latexmk -xelatex file.tex. Works, but I didn't test it extensively. Should work similarly with lualatex.

Comb answered 29/7, 2010 at 12:29 Comment(2)
I'll add an -xelatex option to latexmk in the next version (4.31). This will work like the modification given here (except for the setting of the previewer to evince).Incept
Notably, as of version 4.24, you can get this same effect by doing latexmk -pdflatex='xelatex %O %S' -pdf [...] instead of modifying the latexmk script. It's a bit verbose, but it gets the job done. If/when a flag is added, I'd prefer it if were based on a variable $xelatex. That way we can define the variable in ~/.latexmkrc in order to pass flags etc like we do now with $latex and $pdflatex.Rallentando
S
19
latexmk -v
Latexmk, John Collins, 16 January 2010. Version 4.13a

I put

$pdflatex = 'xelatex --shell-escape %O %S';

in my .latexmkrc file. This is a workaround, of course. But it works for me when I call

latexmk -pvc -pdf MyXetexFile
Sihun answered 13/6, 2011 at 12:14 Comment(0)
C
11

That's my quick fix, so that latexmk works with XeLaTeX:
Add

`elsif (/^-xelatex$/) { $pdf_mode = 1; $pdflatex = 'xelatex %O %S'; $pdf_previewer =
'start evince %O %S';}`

above (or near) the line

`elsif (/^-pdf$/) { $pdf_mode = 1; }`

.

Then you can call latexmk -xelatex file.tex. Works, but I didn't test it extensively. Should work similarly with lualatex.

Comb answered 29/7, 2010 at 12:29 Comment(2)
I'll add an -xelatex option to latexmk in the next version (4.31). This will work like the modification given here (except for the setting of the previewer to evince).Incept
Notably, as of version 4.24, you can get this same effect by doing latexmk -pdflatex='xelatex %O %S' -pdf [...] instead of modifying the latexmk script. It's a bit verbose, but it gets the job done. If/when a flag is added, I'd prefer it if were based on a variable $xelatex. That way we can define the variable in ~/.latexmkrc in order to pass flags etc like we do now with $latex and $pdflatex.Rallentando
C
9
$ latexmk -v
Latexmk, John Collins, 27 July 2010. Version 4.18

I run with the command:

latexmk -pdf -e '$pdflatex=q/xelatex %O %S/' foo.tex

which is basically the same as the answers from andre-r and Kay, but only from the command-line.

Cooksey answered 17/7, 2011 at 21:56 Comment(0)
J
9

In version: 4.65 (18 June 2019), there is a difference between using the -xelatex option and setting -pdflatex as suggested by one of the comments.

Option 1: -xelatex

$ latexmk -xelatex file.tex

With the -xelatex option, or the -pdfxe option, the tex file is first typeset to an xdv (extended DVI) file. Then, xdvipdfmx is called to convert the xdv file to a pdf file.

In latexmk, $xelatex_default_switches is set to -no-pdf (line 395) to have xelatex produce an xdv file instead of the default PDF file.

Hence the -xelatex option is equivalent to:

$ xelatex -no-pdf file.tex  # called one or more times to produce file.xdv
$ xdvipdfmx file.xdv        # called only once in the end

Option 2: -pdflatex=xelatex

A second option is to set pdflatex as follows along with turning on the -pdf option:

# %O is a substitution for options and %S is for source file
$ latexmk -pdflatex='xelatex %O %S' -pdf file.tex

In this approach, xelatex is used to generate the PDF file directly, without generating an intermediate output file. Note that, today, xelatex first generates an xdv stream and internally pipes it to xdvipdfmx to produce a PDF file.

Hence this approach is equivalent to:

$ xelatex file.tex     # called one or more times to produce file.pdf

Updated 2019.08.31 from user36296's comment.

Jeanne answered 31/8, 2019 at 1:13 Comment(1)
In the second option the intermediate file will be generated internally and converted to pdf on every run. Therefore this option is slightly slower than the first option where the conversion to pdf is only done once in the endCalliper
G
7

latexmk --xelatex job.tex Now the argument is passable in this simple form.

Godsend answered 25/5, 2018 at 10:19 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.