# Change default compiler by drop-down button in WinEdt

I use PDFTeXify, PDFLaTeX and XeLaTeX usually. In WinEdt there is a drop-down button on toolbar that has all of these compile methods.

I am wondering whether one can define a button/hotkey or change the compile.edt in a way that when the button/hotkey is pressed or compile (Accessories->Compile) is executed, the compiler method selected in the drop-down button is executed?

To clarify, when XeLaTeX is required and is selected from the drop-down button, compile (Accessories->Compile) does not work and shows error. I have to press the drop-down button to compile the code.

I know that I can define hotkey for each of the compilers in the drop-down button, but It would be great to define just one hotkey or change the compile.edt that executes the selected compiler in the drop-down button.

I've implemented new compile macros for WinEdt 10.2 and the features you ask for, both in your question and in the comments, are now available in the default settings.

There are two new options in Options -> Execution modes -> TeX Options Tab -> Compile (Selected) Options, which let you achieve what you want.

"Compile" (F9) and "Compile Selected" (Shift+F9) commands now take these additional preferences into consideration.

• Option "Use Selected TeX Engine (drop-down button menu)"

With this option enabled, WinEdt will use the TeX accessory that is currently selected in the drop-down menu of the "TeX Compile" button in the toolbar to compile a document.

• Option "Use Pragma Comments in the Source Preamble"

With this option enabled, WinEdt will process the document preamble and, if it finds pragma comments defining !TeX program and (an optional) !BIB program, it will use the specified executable(s) to compile the document. Typical pragma comments for this purpose look like:

% !TEX program = lualatex
% !BIB program = biber

• !TEX program: pdflatex, xelatex, lualatex, or latex

• !BIB program: none, default, bibtex, bibtex8, or biber

The specification of !TeX program is required or else WinEdt resumes with default compiling. In the absence of the optional !BIB program specification WinEdt will execute the specified !TeX program accessory. The same applies if the !BIB program is specified as none. Otherwise WinEdt will execute "[PDF]TeXify" macro with the specified !TeX program as a TeX engine. A specification:

% !BIB program = default

uses the BibTeX executable as defined in the Execution Modes interface. This value can be used if there are no special requirements for BibTeX processing but one would still prefer to execute "[PDF]TeXify" macro in order to bring bibliography and/or index or glossary up-to-date.

• Please leave the tick where it is!!!!!!!! – karlkoeller Feb 19 '17 at 8:50
• I just upgraded to 10.2 and realised that the old macro doesn't work anymore. Then I tried your solution and it is working perfectly. Thank you! – NESHOM Mar 11 '17 at 3:35

Yes, this can be easily done. In (local copy of) Exec\TeX\Compile.edt insert these lines at the beginning:

// If the preamble contains a comment like:
// % !Compiler:: "foo"
// Then WinEdt will execute foo.edt compiler if it exists, eg.:
// TeXify,TeX,AMSTeX,LaTeX,PDFTeXify,PDFTeX,PDFLaTeX,XeTeX,XeLaTeX,LuaTeX,LuaLaTeX,...
PushTagsandRegisters;
GetPreamble("\begin{document}",0); // Get Preamble in Register 0
IfOK(!'Relax;',!'JMP(!"Current_Compiler");');
FindInString("%!0", !'!Compiler:: "$$*$$"', 1,1, 11);
IfOK(!'Relax;',!'JMP(!"Current_Compiler");');

// Try local instance of the macro first:
IfFileExists('%b\Exec\TeX\%#0.edt',!'Relax;',!'JMP(!"Global_Macro");');
Exe('%b\Exec\TeX\%#0.edt');
PopTagsandRegisters;
Exit;

:Global_Macro:: =====================================================
IfFileExists('%B\Exec\TeX\%#0.edt',!'Relax;',!'JMP(!"Current_Compiler");');
Exe('%B\Exec\TeX\%#0.edt');
PopTagsandRegisters;
Exit;

:Current_Compiler:: =================================================

// Execute the currently selected compiler in drop-down TeX Compile button
BtnClick('TeX Compile');
PopTagsandRegisters;
Exit;

This will execute the compiler as specified by a comment or simulate a click on the currently selected compiler in the absence of such comment.

Use Options Interface (Advanced section) to create a local copy of Compile.edt.

• Great! Thank you! Do you also know if there is anyway to retrieve the compiler type in WinEdt from the tex file itself so then one should not keep changing the compiler manually from for compiling one tex file to another? – NESHOM May 21 '14 at 1:19
• @M0HS3N: This, too, can be done if you are willing to insert a comment like % !Compiler:: "foo" somewhere in your preamble to let WinEdt know what compiler should be executed. If this is what you want let me know and I'll post WinEdt macro code that searches for such directive and acts accordingly. – alex May 22 '14 at 21:49
• yes, this is what I want please post the macro. Thanks – NESHOM May 23 '14 at 14:25
• @M0HS3N: I have just edited the original post with the expanded macro code. – alex May 26 '14 at 16:21