[Tex/LaTex] \if(username == foo) … \else .. \fi


I think the pseudo code in the title says it all: How can TeX (or LaTeX) find out the $USER who is running pdflatex?

I'm collaborating want the output to look very slightly different when I run latex as opposed to when my collaborator does.

Best Answer

A method that should work on all operating system (but is basically the same as David's) and needs also -shell-escape:


% #1 = control sequence to define
% #2 = variable to get the value of
  \CatchFileEdef#1{"|kpsewhich -var-value #2"}{\endlinechar=-1 }%



\ifx\me\usrtest ME \else IMPOSTER\fi


With kpsewhich we can avoid quotes and dollars or %; the program should work the same on TeX Live and on MiKTeX. Of course the name of the variable to set might be different on the various operating systems: it's USER on Unix ones and USERNAME on Windows.