4

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?

4
  • 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. Oct 16, 2017 at 3: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. Oct 16, 2017 at 6: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. Oct 16, 2017 at 7: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, 2017 at 6:43

1 Answer 1

3

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.

6
  • Is there a generic solution that works in the compilation stage, and thus independent of the editor used?
    – Marian
    Feb 14, 2018 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: github.com/cereda/arara Feb 14, 2018 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, 2018 at 19:45
  • @Marian Oh, there is a package for that - wait a sec Feb 14, 2018 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 Feb 14, 2018 at 20:10

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .