I'm trying to store the text output of a shell command mktemp
and reuse it later in another latex command. I'm attempting to do this using \savebox
and \usebox
as below. When using \usebox
outside a command, the saved text is printed correctly. However, when used inside other commands like \write18
and \includegraphics
, the \usebox
command appears to not be macroexpanded correctly:
\newcommand{\mktemp}[0]{
\input{|"mktemp"}
}
\newcommand{\hrefqr}[2]{%
\tracingall
\newsavebox{\tmp}
\savebox{\tmp}{\mktemp}
%% verify that \tmp is the same file and not repeated mktemp calls
\usebox{\tmp} \\
\usebox{\tmp} \\
\immediate\write18{qrencode #1 -o \usebox{\tmp}}
\href{#1}{#2 \includegraphics[]{\usebox{\tmp}}}
}
\begin{document}
\hrefqr{www.example.com}{This is example.com}
\end{document}
From the logs:
\write->qrencode www.example.com -o \usebox {\tmp }
\usebox ->\protect \usebox
\usebox #1->\leavevmode \copy #1\relax
#1<-\tmp
\leavevmode ->\unhbox \voidb@x
runsystem(qrencode www.example.com -o \protect \unhbox \voidb@x \copy \tmp \rel
ax )...executed safely (allowed).
And later:
! LaTeX Error: File `\usebox {\tmp }' not found.
from the expansion of:
#1<-This is example.com \includegraphics []{\usebox {\tmp }}
What am I doing wrong?
\includegraphics{\mbox{example-image}}
what would you want the box to do here?