3

I am trying to achieve the same goal as this thread: How can my LaTeX files detect if they're being compiled on Overleaf?.

However, the \homepath kept throwing the error as follows:

Undefined control sequence.
C:\Users\USER

How can I resolve this issue on Windows? I believe some modifications need to be made in the following code block but have no ideas what to do...

\makeatletter
\begingroup\endlinechar=-1\relax
       \everyeof{\noexpand}%
       \edef\x{\endgroup\def\noexpand\homepath{%
         \@@input|"kpsewhich --var-value=HOME" }}\x
\makeatother

1 Answers1

4

You could use \ifwindows from the ifplatform package to skip the path lookup on Windows and just assign some dummy path. This package needs shell escape for detecting the difference between Linux and Mac but not for the \ifwindows command.

\documentclass{article}
\usepackage{ifplatform}
\makeatletter
\ifwindows\def\homepath{windows}\else
\begingroup\endlinechar=-1\relax
       \everyeof{\noexpand}%
       \edef\x{\endgroup\def\noexpand\homepath{%
         \@@input|"kpsewhich --var-value=HOME" }}\x
\fi
\makeatother

\def\overleafhome{/home/whatever}% change as appropriate

\begin{document} Homepath: \homepath

\ifx\homepath\overleafhome Overleaf. \else Not Overleaf. \fi

\end{document}

Marijn
  • 37,699