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

conditionalsenvironment-variables

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:

\documentclass{article}
\usepackage{catchfile}

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

\def\me{enrico}
\getvar{\usrtest}{USER}

\begin{document}

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

\end{document}

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.