[Tex/LaTex] How to switch between pdfLaTeX and XeLaTeX with some lines of commands in the preamble


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?

Best Answer

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

% !TEX TS-program = xelatex


% !TEX TS-program = pdflatex

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

Related Question