7
\documentclass[border=3pt]{standalone}

\newsavebox\temp
\newenvironment{definition}
{\begin{lrbox}{\temp}}
{\end{lrbox}\textit{\usebox\temp}}

\begin{document}
\begin{definition}
Hello World!
\end{definition}
\end{document}

produces a normal typeface as follows,

enter image description here

Why \textit does not produce the expected result when it works with \usebox?

12

Because the \usebox is a fixed entity, locked in concrete. It can be scaled, but its contents cannot be changed (other than by redefining it from scratch). The way you have it setup, the \textit tries to work on the already complete box. The \textit needs to go inside the box.

\documentclass{article}

\newsavebox\temp
\newenvironment{definition}
{\begin{lrbox}{\temp}\begin{itshape}}
{\end{itshape}\end{lrbox}{\usebox\temp}}

\begin{document}
\begin{definition}
Hello World!
\end{definition}
\end{document}
2
  • Is there any macro to remove the "shield" made by \usebox? Mar 9 '13 at 2:52
  • 3
    @GarbageCollector No: a box contains typeset material, that's the entire point. If you want to collect the content of an environment and typeset it at the end, look at the environ package.
    – Joseph Wright
    Mar 9 '13 at 10:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.