In one of my last questions concerned the creation of a persons register Generating an name index with \index{name@name and surname}
Christian commented, to use Glossaries. I read about it and got a Proof of Concept working. Than I tried to code the POC into macros. The macro works, but unfortunately, every glossary entry, which is inserted using my macro, gets listet as a symbol, using the name of the last inserted person.
Inserting names "by hand" works as intended.
EDIT
I can't see the difference of the manual insertion versus the macro code. Please help me.
Nicola Talbot pointed out, that this question might be a duplicate to A dynamic variable as content of a glossary entry , which it kind of is. The answer to the above questions solves part of my problem, in that the person names are now inserted into the glossary (instead of only using the last name for all entries).
Since I will only collect names, I don't expect any fragile expression to be collected. Hence I decided (for simplicity reasons) to generally shut of the late expansion and added
\glsexpandfields
to my MWE.
Unfortunately, all automatically collected entries still reside below symbols and I still have no idea, why. I consider this to be a significant difference from the above linked question and hence no duplicate.
MWE:
\documentclass[12pt]{article}
\usepackage[ngerman]{babel}
\usepackage[T1]{fontenc}
\RequirePackage[final]{hyperref} % should be last package
\RequirePackage[nopostdot]{glossaries} % This is one of the seldom
% exceptions.
\makeatletter
%%% Any time, you call the persons name again, you can use the
%%% glossary command.
%%%
%%% Arguments
%%% #1: Lastname (mandatory)
%%%
%%% The book shall contain a list of all persons, which were
%%% mentioned. The register should be sorted alphabetically, which in
%%% turn requires Makeindex or Xindy. As I haven't used Xindy before,
%%% I will stay with Makeindex. Both programms have difficulties, to
%%% sort names, which contain special characters as is the case for
%%% Henrie Poincaré. Therefore, we must have a fool proof sorting
%%% entry. Glossries relies on the fact, that an entry for the
%%% register is defined, before it is used. Therefore, we can use the
%%% \initpers command, whenever a persons name is used for the first
%%% time. Any following usage can be done with the normal \pers
%%% command.
%%%
%%% Create the glossaries files.
\makeglossaries
%% UPDATED!!!
%% Protected fields like name have to be expanded before usage.
%% c.f. http://ctan.space-pro.be/tex-archive/macros/latex/contrib/glossaries/glossaries-user.html#sec:expansion
\glsexpandfields
%%% \initpers is the command, which is used, whenever a person is
%%% named in the document for the first time. It will a) define the
%%% glossary entry, b) insert an entry into the register and finally
%%% c) will print the name into the text. Makeindex/Glossaries does
%%% need the following arguments in a key=<value> manner:
%%% 1) label (uniqe identifier, used also for sorting purposes)
%%% must be ASCII only, may be identical to 2)
%%% 2) name (may be identical to the label), will be inserted into
%%% the document, may contain LaTeX specials and non ASCII
%%% characters.
%%% 3) description, i.e. the text, which should be printed into the
%%% register. The description can contain further information,
%%% which wasn't in the document before. IN our case, this will
%%% be the surname and any further information
%%% 4) sorting key (if not given by the label)
%%% Whenever a new name is introduced, its full name has to be
%%% inserted, but on the other hand, in some cases, only the last name
%%% has to be inserted into the document itself. Therefore, we must
%%%
%%% NEW:
%%% #1: Label (optional, only used, when Lastname contains non ASCII
%%% characters)
%%% #2: Lastname (mandatory
%%% #3: Surname (mandatory)
%%% #4: Additional Info (mandatory but may be empty)
\newcommand{\pers}[1]{%
\Gls{#1}}%
\newcommand{\initpers}[4][\@nil]{%
%% Reset the internal variables
\def\dntpers@label{}%
\def\dntpers@name{}%
%% Check, if the optional argument is in use and is the arguments
%% accordingly.
\def\@tmp{#1}%
\ifx\@tmp\@nnil
\def\dntpers@label{#2}%
\else
% use the optional argument as label, ...
\def\dntpers@label{#1}%
\fi
\def\dntpers@name{#2}%
%% Define the Glossar entry
\newglossaryentry{\dntpers@label}{%
name=\dntpers@name,
% sort=\dntpers@label,
description={#3 #4}}%
%% Print the name
#3 \gls{\dntpers@label}%
}%
\newcommand{\personenregister}{%
\glossarystyle{listgroup}
\printglossary[title=Personenregister]
}
\makeatother
\begin{document}
\newglossaryentry{Works}{
name=Works,
sort=Works,
description={I have no idea, where the fuking difference comes
from!}}
\gls{Works}
\initpers{Arrow}{Kenneth}{},
\initpers{Arthur}{Brian}{},
\initpers{Casti}{John}{},
\initpers{Gell-Mann}{Murray}{},
\initpers{Holland}{John}{},
\initpers[Help]{Kauffmann}{Stuart}{},
\initpers{Foo}{Bar}{Baz}
\personenregister
\end{document}%
EDIT
This is the output after having added the above mentioned code line \glsexpandfields. Now the Lastname is missing.





namefield doesn't get expanded on definition by default. See the section Expansion in theglossariesuser manual for details. Possibly a duplicate of A dynamic variable as content of a glossary entry. – Nicola Talbot Apr 05 '18 at 20:56\\glsexpandfieldsinto the preamble, which helped a bit. Still, the automatically created entries are located beneath Symbols. :-( – Jan Apr 06 '18 at 06:03\glssetexpandfield{name}to ensure thenamefield is expanded. Have a look at the.glofile. It should have lines in the form\glossaryentry{...?...}. The bit before?is the sort value. Does that look correct? You also may have problems because you're defining entries in thedocumentenvironment. (See Drawbacks With Defining Entries in the Document Environment). You'd be better off defining the people in the preamble and then reference them with\gls. – Nicola Talbot Apr 06 '18 at 12:05\usepackage[nopostdot]{glossaries}with\usepackage[docdef=restricted]{glossaries-extra}. That will remove the need for the.glsdefsfile, which will make the document more stable. (Thenopostdotoption is the default withglossaries-extraso it can be omitted.) – Nicola Talbot Apr 06 '18 at 14:59.glofile looks strange. I removed all my commands from the document into the preamble -- it didn't change the.glofile. Than I rearranged all the\initpers{<Name>}{<Surname>}{<Description>} commands into the\newglossaryentry{command. This help with regard to the.glo`. The entries are now sorted correct as names and not as symbols. BUT: I'd expected such a register in the form Name, Surname, but I do get Name , Surname, which isn't correct either