2

I've implemented this solution to allow placing \lstinline code inside description \item command. I also want to automatically add the entire \item content as a glossary entry by placing it into name field of \newglossaryentry command. The \item content consists of text and \lstinline code.

Since the \item content is stored in a box register, when I try something like name={\usebox0} the entry name doesn't appear in the document glossary. I think this is because \usebox0 isn't being properly expanded in .glsdefs file (all entry names are stored literally as \usebox 0).

MWE:

\documentclass[letterpaper, 12pt, oneside]{memoir}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}

\usepackage{enumitem} \usepackage{etoolbox}

% Redefine \item command. \makeatletter \let\orig@item\item

\def\item{% @ifnextchar{[}% {\lstinline@item}% %@ {\orig@item}% }

\begingroup \catcode\]=\active \gdef\lstinline@item[{% \setbox0\hbox\bgroup \catcode]=\active \let]\lstinline@item@end } \endgroup

\def\lstinline@item@end{% \egroup \orig@item[\usebox0]% % Extra lines for adding entries to glossary. \stepcounter{mycount}% \newglossaryentry{\themycount}{name={\usebox0}, description={}}% \glsadd{\themycount}% } \makeatother

% Glossaries. \usepackage[automake]{glossaries} \glsnoexpandfields \glssetexpandfield{name} \makeglossaries % Counter for glossary labels. \newcounter{mycount} \setcounter{mycount}{0}

\begin{document}

\printglossary[style=index]

\chapter{Some chapter}

Some text.

\begin{description} \item[First] Description. \item[Second] Description. \end{description}

\end{document}

I already know how to put \lstinline code in the name field without causing any error. So I'm looking for some mechanism to store the \item content in a macro which can be expanded in the name field, as well as store it in the box register (which is already solved) to avoid the \lstinline inside \item problems.

I think could be something like \def\storedContent{...} but in the same way \setbox0\hbox\bgroup...\egroup works. I don't know, I've tried many things without success, so any solution will be welcome.

0 Answers0