Somewhat in the similar vein as Getting Texlive version in pdflatex?, now I want to obtain the currently running executable inside a *tex run.
Thanks to Write18: capturing shell (script) output as command/variable?, I can run a shell command and obtain the output with -shell-escape
. So, if we're on a Unix/Linux system, first we can try and see what gets reported for echo $0
(note: the below apparently must be typed/pasted as a single line):
pdflatex -shell-escape '\documentclass{minimal} \begingroup\makeatletter\endlinechar=\m@ne\everyeof{\noexpand} \edef\x{\endgroup\def\noexpand\TeXcmdout{\@@input|"echo $0" }}\x \begin{document} \typeout{>>is: \TeXcmdout} \end{document}'
This produces:
>>is: sh
So, pdflatex
on my system runs the dash
shell upon the \@@input
pipe. So, we can now try inspecting the parent process ID ($PPID
) of this shell; say by running cat /proc/$PPID/status | grep Name
in that shell:
pdflatex -shell-escape '\documentclass{minimal} \begingroup\makeatletter\endlinechar=\m@ne\everyeof{\noexpand} \edef\x{\endgroup\def\noexpand\TeXcmdout{\@@input|"cat /proc/$PPID/status | grep Name" }}\x \begin{document} \typeout{>>is: \TeXcmdout} \end{document}'
This produces:
>>is: Name: pdflatex
So, if I use write18 (-shell-escape
), and a Linux shell, and am willing to run some system commands, I can find the currently running executable. However, I'd like to not run -shell-escape
, and I'd preferably like a cross-platform solution.
As from the first link (and Is there a way to detect from inside a package that MiKTeX is used?), one could hope that \pdftexbanner
could be used. So, first I try the following test for printouts, written in a bash
shell:
for iprog in {tex,pdftex,luatex,xetex,httex,latex,pdflatex,lualatex,xelatex,htlatex}; do \
echo "## >>$iprog<<"; \
$iprog "\nonstopmode \
\immediate\write0{>> Testing terminal printout...} \
\end"; \
done
Note that htlatex
will call tex
at least two times. The problem here is that this code runs "properly" for the TeX-based engines, e.g. I'm getting for pdftex
this in terminal:
## >>pdftex<<
This is pdfTeX, Version 3.14159265-2.6-1.40.15 (TeX Live 2014) (preloaded format=pdftex)
restricted \write18 enabled.
entering extended mode
>> Testing terminal printout...
No pages of output.
Transcript written on texput.log.
... and I'm getting some error shown in the output for LaTeX based engines, like pdflatex
:
## >>pdflatex<<
This is pdfTeX, Version 3.14159265-2.6-1.40.15 (TeX Live 2014) (preloaded format=pdflatex)
restricted \write18 enabled.
entering extended mode
LaTeX2e <2014/05/01>
Babel <3.9l> and hyphenation patterns for 25 languages loaded.
>> Testing terminal printout...
! Emergency stop.
<*> ...e0{>> Testing terminal printout...} \end
! ==> Fatal error occurred, no output PDF file produced!
Transcript written on texput.log.
Nothing serious in this case; but: I guess, an \end
takes an argument in Latex (and is a "standalone" primitive in TeX), and a \stop
there would have taken care of this error -- but then, a \stop
, being a Latex macro, wouldn't be understood by Tex, so I'd get an error there.
This made me think - it would probably be useful to have a variable or switch that would inform whether the currently running engine is Latex-based or not; so I'll use this opportunity to ask if there is something like that out there?
Anyways, getting back to the \pdftexbanner
- we can stick it in the above shell code loop:
for iprog in {tex,pdftex,luatex,xetex,httex,latex,pdflatex,lualatex,xelatex,htlatex}; do \
echo "## >>$iprog<<"; \
$iprog "\nonstopmode \
\immediate\write0{>> is: \pdftexbanner} \
\end"; \
done
and see what we get; the code works for pdftex
, luatex
, latex
, pdflatex
, lualatex
; but for tex
, xetex
, xelatex
, I get:
! Undefined control sequence.
<write> >> is: \pdftexbanner
<inserted text>
}\endwrite
<*> ... \immediate\write0{>> is: \pdftexbanner}
\end
>> is:
(see the transcript file for additional information)
No pages of output.
Transcript written on texput.log.
... that is (as mentioned in above posts), \pdftexbanner
does not exist for these engines.
So, my question would be - is there anything out there, that can be used to determine the currently running executable of a *tex run, without resorting to write18
explicit queries to a shell?
pdflatex
is just a symbolic link topdftex
on Unix-type systems, at least. When you parseps
, for example, you are getting the name under which the executable is called. But it is the same executable.iftex
before, but I completely forgot about it in this context :) I found a nice usage example foriftex
here: tex.stackexchange.com/questions/44694/fontenc-vs-inputenc/… ... As far as the Latex macros go, I can see in new TexLive 2014 the executable banner emits "preloaded format=pdflatex
" or "preloaded format=pdftex
", but I don't think it's (yet) available from within a document... Cheers!