5

I write both English and Persian documents. I work with Texstudio and TeXLive. I have to compile Latin documents in pdfLatex and Persian documents in XeLatex. But I'd rather to change the configuration of LaTeX with some lines of code in the preamble of documents, instead of changing it every time and through the menus and manually.

Is there a command for switching between pdfLaTeX and XeLaTex?

Ali
  • 363
  • 2
  • 6
  • 11
  • 1
    There is an answer to your question, but I'm curious why you need pdfTeX specifically for your Latin documents, and cannot just always use XeTeX. – ShreevatsaR Oct 16 '17 at 03:29
  • you can put comments in your preamble which may be understood by some editors to say which command to use but obviously you can not make this switch with any tex commands as you are asking which tex engine to use so you need to decide that before the document processing starts. – David Carlisle Oct 16 '17 at 06:49
  • 1
    I'm calling in my editor (winedt) the engines with keyboard keys (e.g. ctrl+shift+p for pdflatex) and I'm rather confident that you could setup texstudio in a similar way. Beside this you could use a tool like arara. – Ulrike Fischer Oct 16 '17 at 07:11
  • @ShreevatsaR I have the feeling that pdfTeX is faster than XeTeX but it cannot handle Xepersian package which I'm using for writing in Persian. – Ali Oct 17 '17 at 06:43

1 Answers1

4

Texstudio understands "magic comments", so you can specify the engine by using

% !TEX TS-program = xelatex
\documentclass{...}

or

% !TEX TS-program = pdflatex
\documentclass{...}

If you then call "build & view" texstudio will process your file with the engine you specified in the magic comment.

  • Is there a generic solution that works in the compilation stage, and thus independent of the editor used? – Marian Feb 14 '18 at 15:55
  • @Marian This cannot work at compilation stage, how should the tex engine be chosen if the tex engine itself would be responsible for the choice? However you could use automation tools like arara: https://github.com/cereda/arara – samcarter_is_at_topanswers.xyz Feb 14 '18 at 16:18
  • Ah sorry I read the whole question wrong. What I wanted is something like \ifxetex { ... } \ifpdftex{}. I'll go on searching. Thanks for the quick reply and nevermind :) – Marian Feb 14 '18 at 19:45
  • @Marian Oh, there is a package for that - wait a sec – samcarter_is_at_topanswers.xyz Feb 14 '18 at 20:10
  • @Marian There are the ifluatex and ifxetex packages. With these packages you can check all major cases `\ifluatex code for luatex \fi

    \ifxetex code for xetex \else remaining possibility contains pdflatex \fi `

    – samcarter_is_at_topanswers.xyz Feb 14 '18 at 20:10
  • Thanks. Just found it, too: https://tex.stackexchange.com/questions/15142/can-i-write-a-document-that-is-compilable-with-both-latex-and-xetex – Marian Feb 14 '18 at 20:13