TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is there a way to detect that the MiKTeX TeX LaTeX executable is used? Something like \ifmiktex or even \IfFileExists{<some file only present in MiKTeX>}{}{}?

The reason is that in one of my packages I have to re-execute LaTeX internally on an different .tex file, which of course requires the shell escape aka. write18 feature to be enabled by the user. However, I want to support this feature recursively, i.e. the other .tex file can itself call an own LaTeX sub-process. For this to work I have to add the correct command line option to the internally call of the (pdf)latex executable. Now this option is -shell-escape for TeXLive, but --enable-write18 for MiKTeX.

Here some example code how I plan to implement this feature. The missing part is the definition of \ifmiktex.

   \def\latexcmd{pdflatex }%
   \def\latexcmd{latex }%  

   \immediate\write18{\latexcmd --enable-write18 \options \file}%
   \immediate\write18{\latexcmd -shell-escape \options \file}%
share|improve this question
MiKTeX should also understand -shell-escape if I am right at 2.8. Did you test it? – Herbert Jan 27 '11 at 12:41
@Herbert: I still have an old MikTeX 2.4 and it also understands -shell-escape. – Philippe Goutet Jan 27 '11 at 13:04
@Herbert, honestly no, not yet. I first need to install Windows again on one of my computers ... I had a look at the official list of MikTeX command line arguments and there the support of -shell-escape wasn't mentioned. – Martin Scharrer Jan 27 '11 at 13:40
would passing both options to pdflatex do any harm? – Martin H Jan 27 '11 at 17:13
@Martin H: Good idea. A quick test with TeXLive under Ubuntu Linux shows that it works. Also, TeXLive seems to accept --enable-write18 as well! – Martin Scharrer Jan 27 '11 at 17:26
up vote 12 down vote accepted

MiKTeX supports both optional arguments --enable-write18 and also --shell-escape

a possible Test for MiKTeX




\ifMiKTeX we use MiK\TeX \else we use \TeX Live\fi

share|improve this answer
The resulting text is "we use MiKTeX". Note that there is a \@nil missing at the end of the parameter text of \testMiKTeX@ii. – Martin Scharrer Feb 2 '11 at 20:18
thanks, than I can sue it ... – Herbert Feb 2 '11 at 20:22
Thanks for pointing out this way. I'm going to build on it and might publish the results later. – Martin Scharrer Feb 3 '11 at 11:33
While -shell-escape works fine with both TeX Live (under Linux and Windows) and MiKTeX, the required quotes used in the \write18 call may be different (e.g. think \write18{pdflatex -jobname '<name>' '<file>'} I used single quotes which do not work with MiKTeX, but with TeX Live under Windows. However, if I use double quotes per default then file names with spaces are no longer supported. If I assume only filenames and other input without spaces than this isn't a problem, but I like to support as much as possible. – Martin Scharrer May 5 '12 at 18:21

Here a general proof-of-concept solution which provides \ifmiktex and \iftexlive switches. It is based on Herberts suggestion to use the output of \pdftexbanner. Once finished, it could be published as, say ifdist package or similar.

Please note that the \pdftexbanner expands to text with catcode "other", therefore \@onlevel@sanitze is used to also give the macro parameter text the same catcode.

Update 2012/05/05:

Reworked and tested the code for Tex Live Linux, TeX Live Windows and MiKTeX. Provided warning for XeLaTeX which is not supported. I put it in the form of a package. Will Robertson might integrate it into ifplatform.

\ProvidesPackage{ifdistro}[2012/05/05 v1.0 Provides if-switches for MiKTeX and TeX Live]


\def\TeXLive{TeX Live}

% Test if \pdftexbanner exists, which is the case for latex, pdflatex and lualatex
% but not xelatex.
\expandafter\ifx\csname pdftexbanner\endcsname\relax
        {Primitive \string\pdftexbanner\space not found!\MessageBreak
         Switches \expandafter\string\csname ifmiktex\endcsname\space 
         and \expandafter\string\csname iftexlive\endcsname\space 
         will not be set\@gobble}% gobbles the "on line X" part

% Scans for 'MiKTeX' string with catcode 12 (other)
% Scans for 'TeX Live' string with catcode 12 (other)
% Scans for 'Web2C' string with catcode 12 (other)
% This string is used by TeX Live under MS Windows


share|improve this answer
Looks good! Would it make sense to incorporate this inside ifplatform.sty? I'd be happy to add you as an author to the package if you like. – Will Robertson Feb 2 '11 at 3:47
It won't work for XeTeX though. – AlexG Feb 2 '11 at 8:01
@Will: I also think ifplatform would be a good place. However, I like to extract the version number as well. Give me some time to refine it first. – Martin Scharrer Feb 2 '11 at 13:52
@WillRobertson: I found myself in need again for this. I didn't do any work on it since last time, but might rework it now. For XeTeX it would be possible to scan the first line of the log file. – Martin Scharrer May 5 '12 at 15:57
For some reason TeX Live does use Web2C 2011 not TeX Live 2011 under Windows. – Martin Scharrer May 5 '12 at 15:57

One good approach is to test whether a particular application exist or not. For example, if Yap (dvi viewer of MiKTeX) exists, you know that you are using MiKTeX. This approach has a good advantage that works with any other engine but the disadvantage is that write18 should be enabled.

share|improve this answer
you can have MiKTeX and TeXLive installed on the same machine and you can use Yap for TeXlive and ... – Herbert Feb 2 '11 at 10:58
I just gave an example. Of course, you can make it much smarter by considering various possibilities! – IRAN Feb 2 '11 at 11:17

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.