TransWikia.com

Define a command on xelatex command line

TeX - LaTeX Asked on November 30, 2020

I would like to define the command qonly on the xelatex command line to be the string chapter07. Later in my LaTeX file I will have an ifdef that will provide the argument to an includeonly if qonly is defined.

This works if I am using latexmk:

$ latexmk -usepretex='defqonly{chapter07}' -pdfxe book.tex -bibtex

But this does not work with xelatex:

$ xelatex 'relaxdefqonly{chapter07}' book.tex

It gives me this error:

xelatex 'defqonly{chapter07}' book.tex
This is XeTeX, Version 3.14159265-2.6-0.999992 (TeX Live 2020) (preloaded format=xelatex)
 restricted write18 enabled.
entering extended mode
LaTeX2e <2020-02-02> patch level 5
L3 programming layer <2020-03-06>

! LaTeX Error: Missing begin{document}.

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.
 ...

<*> defqonly{chapter07} b
                           ook.tex
? ^D
! Emergency stop.
 ...

<*> defqonly{chapter07} b
                           ook.tex
No pages of output.
Transcript written on texput.log.
$ 

Is there any way do this?

EDIT: One of the posters was confused why I have the backquotes above. The reason is that I’m using MacOS and my shell is zsh, which interprets the backquotes as a quote mark, so it’s necessary to quote it. Here’s what happens if I don’t provide the backquote:

% xelatex defqonly{chapter07} book.tex
This is XeTeX, Version 3.14159265-2.6-0.999992 (TeX Live 2020) (preloaded format=xelatex)
 restricted write18 enabled.
entering extended mode
! I can't find file `defqonly{chapter07}'.
<*> defqonly{chapter07}
                        book.tex
(Press Enter to retry, or Control-D to exit)
Please type another input file name:

One Answer

You don't need to pass quoted commands to the compiler. Think of whatever follows a call to the compiler as code that should be within a regular TeX file (except if you're passing the tex file itself, as in xelatex book.tex). So, drop the use of the quotes and input your source:

xelatex defqonly{chapter07} input{book}

Since book.tex is at the end of the input stream, TeX just wants to set it as the character string book.tex, not reading in the file book.tex, hence the use of input{book}.

Correct answer by Werner on November 30, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP