2

I want to make a command such that, if that command is called, the compiler is set to LuaTeX, but if it isn't the compiler is PDFTeX. Something like:

\newcommand{\mul}[2]{
% If used, set compiler to LuaTeX
\directlua{tex.sprint{#1*#2}}
}

Thanks in advance!

  • related: http://tex.stackexchange.com/questions/342656 – Marijn Apr 10 '17 at 17:29
  • 1
    @Marijn: Well, isn't this a question to change the compiler internally while being compiled (which is not possible, as far as I know)? –  Apr 10 '17 at 17:32
  • 1
    Are you looking for the iflua package? –  Apr 10 '17 at 17:32
  • @ChristianHupfer the question is indeed phrased to check during compile, but the OP may be willing to use a two step strategy as in the linked question, first preprocess the file to see if the command is used (with grep or something similar) and then the actal compilation with the required engine. – Marijn Apr 10 '17 at 17:39
  • @ChristianHupfer I not really looking for iflua, but I'll take a look (it looks usefull). I was hoping that there would be ('magic'?) commands that were checked before the actual compiler started, or indeed a way to change compiler mid-document. Please excuse me if this is trivially impossible; I don't know anything about compilers. – Pepijn de Maat Apr 10 '17 at 18:39
  • @PepijndeMaat: No, I think this is not possible. What should the compiler do with a 'half' document and then glueing the other 'half' to the other one? You can apply a different strategy however, with the \write18 method (i.e. shell-escape) –  Apr 10 '17 at 19:31
  • 3
    tex itself can not do what you ask as by the time it has started it is already pdftex or luatex, but presumably you are starting the command from some editor (as on the command line the question does not really arise) and most editors will let you do such things eg with a magic comment %!TEX luatex at the top to make it use luatex. But it is editor specific and you have not said which you are using. – David Carlisle Apr 10 '17 at 20:10
  • this is perhaps a duplicate of http://tex.stackexchange.com/questions/78101/when-and-why-should-i-use-tex-ts-program-and-tex-encoding – David Carlisle Apr 10 '17 at 20:23
  • 2
    The usual question: Why would you want to do this? – Martin Schröder Apr 10 '17 at 21:54
  • @MartinSchröder In my student commision there are several LaTeX files that are commonly used. One of them is an invoice package. Now there was the request to add multiplication, like one could say they bought 20 beers and the price of a single beer in order to get the price of 20 beers. This is bothersome in PDFTeX, however, so we `need' Lua. But for backwards compatability we can't assume everyone who uses the package has LuaTeX. So yeah, that's why I wanted some kind of conditional. – Pepijn de Maat Apr 11 '17 at 14:19
  • @PepijndeMaat: AFAIK LaTeX3/expl3 has some packages for easy arithmetic that use LuaTeX in the backend if it's available. – Martin Schröder Apr 11 '17 at 15:50

1 Answers1

1

As written in the comments to your question, the pdf/xe/luatex engine does not parse the file to find any hint for the needed TeX-engine.

But your editor can do this. Well, if you are using Emacs, e.g.

Emacs comes with a "mode" called AUCTeX. This mode checks for local variables. If you write this code at the end of your file, AUCTeX will use LuaTeX to compile:

%%% Local Variables: 
%%% TeX-engine: luatex
%%% TeX-master: t 
%%% End:

So as soon as you are writing something like \directlua{...}, add the local variables to your file.

Keks Dose
  • 30,892
  • 1
    If using vim and the vimtex plugin, the equivalent would be %! TEX program = lualatex at the top of your file. – Aubergine Nov 18 '22 at 22:08