Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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.

\ifpdf
   \def\latexcmd{pdflatex }%
\else
   \def\latexcmd{latex }%  
\fi

\ifmiktex
   \immediate\write18{\latexcmd --enable-write18 \options \file}%
\else
   \immediate\write18{\latexcmd -shell-escape \options \file}%
\fi
share|improve this question
6  
MiKTeX should also understand -shell-escape if I am right at 2.8. Did you test it? –  Herbert Jan 27 '11 at 12:41
1  
@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
2  
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
show 10 more comments

3 Answers

up vote 12 down vote accepted

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

a possible Test for MiKTeX

\documentclass{article}

\newif\ifMiKTeX
\makeatletter
\def\testMiKTeX{\expandafter\testMiKTeX@i\pdftexbanner\@nil}
\def\testMiKTeX@i#1(#2)#3\@nil{\testMiKTeX@ii#2..\@nil}
\def\testMiKTeX@ii#1.#2.#3\@nil{\ifx\relax#2\relax\else\MiKTeXtrue\fi}
\makeatother
\testMiKTeX

\begin{document}

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

\end{document}
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
add comment

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]

\newif\ifmiktex
\newif\iftexlive

\begingroup
\makeatletter
\def\MiKTeX{MiKTeX}
\@onelevel@sanitize\MiKTeX
\def\TeXLive{TeX Live}
\@onelevel@sanitize\TeXLive
\def\WebIIC{Web2C}
\@onelevel@sanitize\WebIIC

% Test if \pdftexbanner exists, which is the case for latex, pdflatex and lualatex
% but not xelatex.
\expandafter\ifx\csname pdftexbanner\endcsname\relax
    \PackageWarning{ifdistro}
        {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
\else

% Scans for 'MiKTeX' string with catcode 12 (other)
\expandafter\def\expandafter\testmiktex\expandafter#\expandafter1\MiKTeX#2\relax{%
        \ifx\empty#2\empty
             \global\miktexfalse
        \else
             \global\miktextrue
        \fi
}
\expandafter\expandafter
\expandafter\testmiktex\expandafter\pdftexbanner\MiKTeX\relax\relax
\ifmiktex\else
% Scans for 'TeX Live' string with catcode 12 (other)
\expandafter\def\expandafter\testtexlive\expandafter#\expandafter1\TeXLive#2\relax{%
        \ifx\empty#2\empty
             \global\texlivefalse
        \else
             \global\texlivetrue
        \fi
}
\expandafter\expandafter
\expandafter\testtexlive\expandafter\pdftexbanner\TeXLive\relax\relax
\iftexlive\else
% Scans for 'Web2C' string with catcode 12 (other)
% This string is used by TeX Live under MS Windows
\expandafter\def\expandafter\testtexlive\expandafter#\expandafter1\WebIIC#2\relax{%
        \ifx\empty#2\empty
             \global\texlivefalse
        \else
             \global\texlivetrue
        \fi
}
\expandafter\expandafter
\expandafter\testtexlive\expandafter\pdftexbanner\TeXLive\relax\relax
\fi\fi

\fi

\endgroup
share|improve this answer
2  
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
1  
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
show 1 more comment

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
2  
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
add comment

Your Answer

 
discard

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.