1

I stumbled upon this question regarding accessing environment variables from latex and have problems properly escaping variables containing special tex symbols (e.g. LANG=en_US.UTF-8)

My closest attempt can be found below but it still replaces the underscore with a weird dot:

environment variable with superscript dot instead of underscore

\documentclass{article}
\usepackage{xparse}

\ExplSyntaxOn

\NewDocumentCommand{\getenv}{om}
{
  \sys_get_shell:nnN{ kpsewhich ~ --var-value ~ #2 }{}#1
}


\begin{document}

\getenv[\LANG]{LANG}

\tl_to_str:N\LANG

\end{document}

Furthermore this also does not correctly handle other special symbols like @

Septatrix
  • 408
  • \usepackage[T1]{fontenc}. This is a duplicate. Your definition is wrong, as I explained in a comment to your answer in the linked thread. What do you mean by the last paragraph? – egreg Jun 03 '20 at 21:19
  • I tried defining AB='@' in the shell and then \getenv[\AB]{AB}\AB prints the expected @. – egreg Jun 03 '20 at 21:25
  • Yes without the \show your definition worked and adding fontspec whilst using lualatex resolved the weird dot problem. I am so accustomed to lualatex that I forgot to add it whilst experimenting with the code. Thank you – Septatrix Jun 03 '20 at 21:31

0 Answers0