The MWE below creates a \savebox within a group which results in several blank lines:
If I comment out the\begingroup and \endgroup I get the desired results:
My thinking was that adding the \global should have fixed this issue.
So, how do I create and define \savebox within a group and yet be able to use the outside of the group?
Notes:
- While the MWE here does not need grouping my actual use case does, so I would really prefer to not have to eliminate the grouping.
Code:
\documentclass{article}
\usepackage{etoolbox}
\newcommand{\MyLink}[2]{%
\begingroup
\ifcsdef{MyBox #1-#2}{%
}{%
\typeout{** Defined savebox for #1-#2}%
\global\expandafter\newsavebox\csname MyBox #1-#2\endcsname%
\global\expandafter\savebox\csname MyBox #1-#2\endcsname{#2: #1}%
}%
\expandafter\usebox\csname MyBox #1-#2\endcsname%
\endgroup
}%
\begin{document}
\MyLink{http://www.wikipedia.org}{W}
\MyLink{http://www.wikipedia.org}{W}
\MyLink{http://www.apple.org}{A}
\MyLink{http://www.google.com}{G}
\MyLink{http://www.wikipedia.org}{W}
\MyLink{http://www.wikipedia.org}{W}
\end{document}



\global\saveboxis definitely not going to work. – egreg Dec 16 '15 at 12:13\xdef177718, using your\setboxsolution 54390. Not sure what the time units are. – Peter Grill Dec 16 '15 at 12:53