2

I am trying to create a glossary entry for math symbols with extra parameter that have long and short forms. I tried following Glossary entry with extra parameter for creating the extra parameter.

I used the first key to hold the long format and text to hold the short format.

this is not fully working, since if i try to use the long format with \glsfirst{}[] the index is not properly caught.

Any help on how to fix / implement better would be greatly appreciated.

my code so far:

\documentclass{article}

\usepackage[unicode, colorlinks=true]{hyperref}
\usepackage[automake, nonumberlist,acronym,nopostdot, style=super, shortcuts]{glossaries}
\setlength{\glsdescwidth}{0.9\textwidth}
\makeglossaries

\glsnoexpandfields

\newcommand*{\providedIndex}{} % default index

\newglossaryentry{Vertex}{
name = \ensuremath{V_{i}},
text = \ensuremath{V_{\providedIndex}},
description = Vertex $i$
}
\newglossaryentry{volt}{
name = \ensuremath{ v(V_i), v_{i}},
text = \ensuremath {v_{\providedIndex}},
first = \ensuremath {v(\gls{Vertex})},
description = Voltage of vertex $i$
}

% modify the entry's format
\defglsentryfmt{%                   
    \let\orgprovidedIndex\providedIndex
    \ifdefempty\glsinsert
    {}%
    {%
    \let\providedIndex\glsinsert
    \let\glsinsert\relax
    }%
    \glsgenentryfmt
    \let\providedIndex\orgprovidedIndex
}

\begin{document}
\printglossary
\section{Main}

my use cases:

$\gls{Vertex} = V$

$\gls{Vertex}[k] = V_k$

$\gls{volt}[k] = v(V_k)$ - working long form (actual first use)

$\gls{volt}[k] = v_k$ - working short form

$\glsfirst{volt}[k] \neq v(V_k)$ - not working long form, index is messed up

\end{document}

and the results: enter image description here

2
  • I think you miss understood the problem. I believe the problem is that the \glsfirst command is bypassing the modified glsentryfmt and therefore [k] is not intercepted and embedded in the result but appended to it. if what you had said to be the problem was correct than the first use of \gls{volt}[k] wouldn't have worked as well. Nov 15, 2017 at 17:43
  • You're right (I now think after some tests and investigation). I'll update my answer.
    – Skillmon
    Nov 15, 2017 at 18:40

1 Answer 1

2

You could define another command, which you use if you want to use the first appearance of volt:

\documentclass{article}

\usepackage[unicode, colorlinks=true]{hyperref}
\usepackage[automake, nonumberlist,acronym,nopostdot, style=super, shortcuts]{glossaries}
\setlength{\glsdescwidth}{0.9\textwidth}
\makeglossaries

\glsnoexpandfields

\newcommand*{\providedIndex}{} % default index

\newglossaryentry{Vertex}{
name = \ensuremath{V_{i}},
text = \ensuremath{V_{\providedIndex}},
description = Vertex $i$
}
\newglossaryentry{volt}{
name = \ensuremath{ v(V_i), v_{i}},
text = \ensuremath {v_{\providedIndex}},
first = \ensuremath {v(\gls{Vertex})},
description = Voltage of vertex $i$
}
\newcommand*{\glsfirstvolt}[1][]{%
  \glslink{volt}{\ensuremath{v(V_#1)}}}

% modify the entry's format
\defglsentryfmt{%                   
    \let\orgprovidedIndex\providedIndex
    \ifdefempty\glsinsert
    {}%
    {%
    \let\providedIndex\glsinsert
    \let\glsinsert\relax
    }%
    \glsgenentryfmt
    \let\providedIndex\orgprovidedIndex
}

\begin{document}
\printglossary
\section{Main}

my use cases:

$\gls{Vertex} = V$

$\gls{Vertex}[k] = V_k$

$\gls{volt}[k] = v(V_k)$ - working long form (actual first use)

$\gls{volt}[k] = v_k$ - working short form

$\glsfirst{volt}[k] \neq v(V_k)$ - not working long form, index is messed up

$\glsfirstvolt[k] = v(V_k)$ - working

\end{document}

enter image description here

Without the declaration of a \glsfirstvolt command, you might redefine \glsfirst as follows. The implementation I provide here is minimal and neither supplies the starred version nor the plus-variant of \glsfirst. If you need those I can supply them.

\RequirePackage{xparse}

\RenewDocumentCommand{\glsfirst}{O{} m o}{%
  \bgroup%
  \glslocalreset{#2}%
  \IfNoValueTF{#3}%
    {\gls[#1]{#2}}%
    {\gls[#1]{#2}[#3]}%
  \egroup}

You're problem might result from a bug (or unprecise description in the package documentation) you should perhaps contact the package author.

2
  • Hi, thank you for your answer, but your solution has 1 major flaw. i would need to create a different command for each long glossary entry. that is, if I where to add another glossary like volt for vertex current, I would need to create a long format command for that glossy as well. Nov 15, 2017 at 17:36
  • You could create a command which creates your commands as well as your glossary-definitions...
    – Skillmon
    Nov 15, 2017 at 18:18

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .