Based on the macro defined here, I would like to use it to create a glossary with a variable in the description. Here is my MWE:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{glossaries}
\makeglossaries
\newcommand\referenceSente{}
\newcommand{\defReferenceSente}[1]
{\gdef\referenceSente{#1}}
% MACRO FOR DEFINITION
\newcommand{\keyDef}[2]{%
%CREATE THE GLOSSARY ENTRY
\newglossaryentry{#1}{name={#1},description={%
#2\\(\referenceSente)
}}
% PRINT THE DEFINITION
\textbf{\gls{#1}} : \textit{#2}\par\vspace{.3cm}
}
\newenvironment{myEnvironment}[1]{\defReferenceSente{#1}}{\par}
\begin{document}
\begin{myEnvironment}{firstReference}
\keyDef{first term}{first definition}
\end{myEnvironment}
\begin{myEnvironment}{secondReference}
\keyDef{second term}{second definition}
\end{myEnvironment}
\printglossaries
\end{document}
With the result :
The command \keyDef{<term>}{<definition>}
serves to create a definition which is 1) printed in the document, and 2) added to the glossary, followed with the current value of the variable referenceSente
, in parentheses.
The problem is that for the first entry of the glossary, the content inside the parentheses should (firstReference) instead of (secondReference). It seems that when the code is compiled, the glossary uses the last very value of the variable for all the items, instead of the value it had when the definition was declared.
I have no idea how to "ask the glossary" to use the correct value, instead of the last recorded in the document.
glossaries
are you using? If it's recent (v4.0 onwards), you need to adjust the expansion setting when defining the entry. See the section called "Expansion" in the user manual.\glssetexpandfield{description}
as well as\glssetnoexpandfield{description}
just before the creation of my entry (so in the\keyDef
macro) but it didn't change anything.