GeneralUsinng \usebox inside \newenvironment

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
jdege
Posts: 6
Joined: Sun Nov 02, 2008 4:38 am

Usinng \usebox inside \newenvironment

Post by jdege »

What I'm trying to do is pretty simple - to combine ntheorem.sty and glossaries.sty in an environment that will take a word and a definition and to display then as a definition at the current location in the text and to display them in a glossary in the endmatter.

What I have so far (and thanks to the folks who got me this far) is:

Code: Select all

\documentclass{article}

\usepackage{ntheorem}
\usepackage{glossaries}
\makeglossaries

\newtheoremstyle{mydefinition}%
 {\item[\hskip\labelsep \theorem@headerfont ##1\ ##2\theorem@separator]}%
 {\item[\hskip\labelsep {\theorem@headerfont ##1\ ##2}\ ##3
\theorem@separator]}
\newtheorem{definition}{Definition}

\newsavebox{\wordbox}
\newsavebox{\defbox}

\newenvironment{glossdef}[1]{%
\savebox{\wordbox}{#1}%
\begin{lrbox}{\defbox}}{\end{lrbox}%
\begin{definition}[\usebox{\wordbox}]%
\usebox{\defbox}%
\newglossaryentry{word}{name={word},description={This is a definition.}}%
\end{definition}%
}

\begin{document}

\begin{glossdef}{snafu}
A snafu is is \ldots
\end{glossdef}

This is \gls{word}, used in a sentence.

\printglossary

\end{document}
The above works fine. The definition appears where it should, and the glossary entry appears in the glossary. The problem is that the glossary entry is the hardcoded text I entered for testing, not the text of the definition. What I want to do is to insert the content of the two \savebox's into the glossary entry, and to wrap the \gls{} around the use of the word in the definition.

Something like this:

Code: Select all

\newenvironment{glossdef}[1]{%
\savebox{\wordbox}{#1}%
\begin{lrbox}{\defbox}}{\end{lrbox}%
\begin{definition}[\gls{\usebox{\wordbox}}]%
\usebox{\defbox}%
\newglossaryentry{\usebox{\wordbox}}{name={\usebox{\wordbox}},description={\usebox{\defbox}}}%
\end{definition}%
}
But the above does not work. If I use \usebox in name or description, the glossary entry is blank. If I use \usebox in the key argment of \glossaryentry, I get errors:

Code: Select all

! Missing \endcsname inserted.
<to be read again> 
                   \unhbox 
l.29 \end{glossdef}
Any ideas?

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

Post Reply