3

With the glossaries package, the group names can be changed using the commands \newcommand*{\Agroupname}{}, \newcommand*{\Bgroupname}{}, etc, as shown for example here.

Here, I am obliged to use \printnoidxglossary, for which none of the previous commands seems to work, although \renewcommand{\glssymbolsgroupname}{} does work.

Any suggestion ?

\documentclass{article}
\usepackage{hyperref}
\usepackage[nogroupskip]{glossaries}

\newglossaryentry{Almond}{ name=Almond,  description={A fruit},
  sort={Almond}  }
\newglossaryentry{Berry}{ name=Berry,  description={Another fruit},
  sort={Berry}  }
\newglossaryentry{Cherry}{ name={Cherry},  description={Yet another fruit},
  sort={Cherry}  }
\newglossaryentry{Tomato}{ name={Tomato},  description={Again another fruit},
  sort={Tomato}  }
\newglossaryentry{Strawberry}{ name={Strawberry},  description={Not a fruit},
  sort={Strawberry}  }


\makenoidxglossaries

\begin{document}
\gls{Almond}, \gls{Berry}, \gls{Cherry} and \gls{Tomato} are fruits, unlike \gls{Strawberry}.

%\renewcommand{\glssymbolsgroupname}{Non-fruits}
\newcommand*{\Agroupname}{a A}
\newcommand*{\Bgroupname}{b B}
\printnoidxglossary[sort=standard,style=listhypergroup]
\end{document}
HcN
  • 1,274
  • 9
  • 25

1 Answers1

3

I have identified the issue, but I'm still working on a proper solution.

Internally, glossaries seems to store the titles as the unicode number so that 'A' is 65, 'B' is 66, etc. The function which retrieves the title and check is the appropriate \Xgroupname command is set is (indenting mine):

\@gls@getgrouptitle=macro:
#1#2->\DTLifint {#1}{%
  \edef #2{\char #1\relax }%
}{%
  \ifcsundef {#1groupname}{%
    \def #2{#1}%
  }{%
    \letcs #2{#1groupname}%
  }%
}

From this command, it seems like #2 is a char (A, B, ...) when using xindy or makeindex, but is an integer when using noidx.

The 'simple' thing to do is to redefine it so that it is an integer, it still checks if the appropriate \Xgroupname is defined.

The following is nearly what you want:

\def\@gls@getgrouptitle#1#2{
  \DTLifint {#1}{%
    \def\@tmp@char{\char#1}%
  }{%
    \def\@tmp@char{#1}%
  }%
  \ifcsundef {\@tmp@char groupname}{%
    \def #2{\@tmp@char}%
  }{%
    \letcs #2{\@tmp@char groupname}%
  }%
}

The only issue seems to be that \def\@tmp@char{\char#1} doesn't do what I want (comment on how to fix this would be appreciated).

Update

After being unable to get \def\@tmp@char{\char#1} to do what I want, I asked others. The following uses Heiko's solutions:

\begingroup
  \catcode0=12 %
  \gdef\chrdef#1#2{%
    \begingroup%
      \lccode0=\numexpr(#2)\relax%
    \lowercase{\endgroup%
      \def#1{^^@}%
    }%
  }%
\endgroup

\def\@gls@getgrouptitle#1#2{%
  \DTLifint {#1}{%
    \chrdef\@tmp@char{#1}%
  }{%
    \def\@tmp@char{#1}%
  }%
  \ifcsundef {\@tmp@char groupname}{%
    \def #2{\@tmp@char}%
  }{%
    \letcs #2{\@tmp@char groupname}%
  }%
}

If you paste this in your preamble after loading the glossaries package (and inside \makeatletter ... \makeatother), then the glossary will use the names defined in \Agroupmame, \Bgroupname, ...

Here's a full MWE (which also includes the answer to your other question)

\documentclass{article}
\usepackage[
  hmargin=8cm,
  showframe
]{geometry}
\usepackage{hyperref}
\usepackage[
  style=listhypergroup,
]{glossaries}
\renewcommand{\glossaryheader}{\item \parbox{0.9\textwidth}{\glsnavigation}}

\newglossaryentry{A}{name=A, description={Letter of the alphabet}}
\newglossaryentry{B}{name=B, description={Letter of the alphabet}}
\newglossaryentry{C}{name=C, description={Letter of the alphabet}}
\newglossaryentry{D}{name=D, description={Letter of the alphabet}}
\newglossaryentry{E}{name=E, description={Letter of the alphabet}}
\newglossaryentry{F}{name=F, description={Letter of the alphabet}}
\newglossaryentry{G}{name=G, description={Letter of the alphabet}}
\newglossaryentry{H}{name=H, description={Letter of the alphabet}}
\newglossaryentry{I}{name=I, description={Letter of the alphabet}}
\newglossaryentry{J}{name=J, description={Letter of the alphabet}}
\newglossaryentry{K}{name=K, description={Letter of the alphabet}}
\newglossaryentry{L}{name=L, description={Letter of the alphabet}}
\newglossaryentry{M}{name=M, description={Letter of the alphabet}}
\newglossaryentry{N}{name=N, description={Letter of the alphabet}}
\newglossaryentry{O}{name=O, description={Letter of the alphabet}}
\newglossaryentry{P}{name=P, description={Letter of the alphabet}}
\newglossaryentry{Q}{name=Q, description={Letter of the alphabet}}
\newglossaryentry{R}{name=R, description={Letter of the alphabet}}
\newglossaryentry{S}{name=S, description={Letter of the alphabet}}
\newglossaryentry{T}{name=T, description={Letter of the alphabet}}
\newglossaryentry{U}{name=U, description={Letter of the alphabet}}
\newglossaryentry{V}{name=V, description={Letter of the alphabet}}
\newglossaryentry{W}{name=W, description={Letter of the alphabet}}
\newglossaryentry{X}{name=X, description={Letter of the alphabet}}
\newglossaryentry{Y}{name=Y, description={Letter of the alphabet}}
\newglossaryentry{Z}{name=Z, description={Letter of the alphabet}}

\makenoidxglossaries

\makeatletter
\begingroup%
  \catcode0=12 %
  \gdef\chrdef#1#2{%
    \begingroup%
      \lccode0=\numexpr(#2)\relax%
    \lowercase{\endgroup%
      \def#1{^^@}%
    }%
  }%
\endgroup

\def\@gls@getgrouptitle#1#2{%
  \DTLifint {#1}{%
    \chrdef\@tmp@char{#1}%
  }{%
    \def\@tmp@char{#1}%
  }%
  \ifcsundef {\@tmp@char groupname}{%
    \def #2{\@tmp@char}%
  }{%
    \letcs #2{\@tmp@char groupname}%
  }%
}
\makeatother

\newcommand\Agroupname{Alpha}
\newcommand\Bgroupname{Bravo}
\newcommand\Cgroupname{Charlie}

\begin{document}
\glsaddall
\printnoidxglossary
\end{document}

output

JP-Ellis
  • 8,929
  • 2
  • 33
  • 49
  • Thanks a lot indeed. Although, in your example, there is a unwanted space before each letter. Is it possible to remove it ? – HcN Feb 27 '16 at 14:19
  • 1
    @HcN I have update the answer to fix the extra whitespace. It was actually because I had forgotten a couple of % at the end of lines. – JP-Ellis Feb 27 '16 at 14:38