0

I've looked at both these related topics, but my situation is a little bit different.

improper alphabetic constant with-glossaries

improper alphabetic constant

The first thing I found in the glossaries manual was to activate this

\glssetexpandfield{name}
\glssetexpandfield{sortvalue}

But even that was not solving the case. Here is an extract of the code in my custom class

% Define Special
\tl_new:N  \l_character_firstname_tl
\tl_new:N  \l_character_lastname_tl
\tl_new:N  \l_character_desc_tl
\tl_new:N  \l_character_sound_tl

\int_new:N \l_character_age_int


\keys_define:nn { Character/Identity } {
    firstname .tl_set:N = \l_character_firstname_tl
    , lastname .tl_set:N = \l_character_lastname_tl
    , age      .int_set:N = \l_character_age_int
    , glosEntry .tl_set:N = \l_character_desc_tl
    , prononciation .tl_set:N = \l_character_sound_tl
    , unknown  .code:n = {}
}

% #1 * girl
% #2 - shorten
% #3 [options] - lastname, age, description, etc
% #4 < shortRefName >
% #5 { first name }
\NewDocumentCommand{\createCharacter}{s t- o D<>{#5} m}{
    
    % we don't want that the unset keys are carried over from the previous ones
    \group_begin:
    \IfValueT{#3}{\keys_set:nn{Character/Identity}{#3}}
    
    \cs_new_protected:cpx { #4 Age } { \int_eval:n { \l_character_age_int } }
    
    \cs_new_protected:cpn { #4 Name }  { #5 }
    \cs_new_protected:cpx { #4 FName }  { \use:c { #4 Name } ~ \exp_not:V \l_character_lastname_tl }
    \cs_new_protected:cpx { #4 LName }  { \exp_not:V \l_character_lastname_tl }
    
    %glossary
    \cs_new_protected:cpx { #4 gdsc }  { \exp_not:V \l_character_desc_tl }
    \cs_new_protected:cpx { #4 gpro }  { \exp_not:V \l_character_sound_tl }
    \cs_new_protected:cpx { #4 glbl }  { p: \use:c {#4} }
    
    
    \newglossaryentry{ 
        p:#4 
    }{
        \exp_not:f {
            type={ perso }, 
            name={ \use:c { #4 FName }  }, 
            description={ \use:c { #4 Age } \nobreakspace years.~\use:c { #4 gdsc }  }, 
            symbol={ \use:c { #4 gpro } }
        }
    }
    
    
    \group_end:
    
}

So my question is, how can I make it work with the right expansion level (I try to put \exp_not:f before the glossary entry command, but it didn't seems to change anything.

Thanks in advance.

EDIT 1:

Here's a little working example. Since it's missing a couple of things, there is a weird behaviour in the appendix where the names are repeating themselves, but I belived it's because the package is directly in the document which change the behaviour because I don't have that weird thing happening in my actual document.

I use LuaLaTeX to compile.

\documentclass[10pt,french,titlepage,twoside,openright]{book}

\usepackage{xparse} %LaTeX3 enabled
\usepackage{fontspec}
\setmainfont{Noto Serif}
\setsansfont{Noto Sans}

\usepackage[section, nopostdot, nonumberlist]{glossaries}
\glssetexpandfield{name}
\glssetexpandfield{sortvalue}

\newglossarystyle{dictstyle}{%
    \setglossarystyle{listgroup}
    % alter the command that's different:
    \renewcommand*{\glossentry}[2]{% 
        \item[\glossentryname{##1}]
        \ifglshassymbol{##1}{\space[{\space\small\glossentrysymbol{##1}\space}]\space}{}% 
        \glossentrydesc{##1}
    }
}

\setglossarystyle{dictstyle}

\newglossary{perso}{p}{pers}{List of characters}
%\setglossarystyle{long-name-sym-desc}

\makenoidxglossaries

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Start of Class Abstract File   %%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\ExplSyntaxOn

% Define Special
\tl_new:N  \l_character_firstname_tl
\tl_new:N  \l_character_lastname_tl
\tl_new:N  \l_character_desc_tl
\tl_new:N  \l_character_sound_tl
\int_new:N \l_character_age_int


\keys_define:nn { Character/Identity } {
    firstname .tl_set:N = \l_character_firstname_tl
    , lastname .tl_set:N = \l_character_lastname_tl
    , age      .int_set:N = \l_character_age_int
    , glosEntry .tl_set:N = \l_character_desc_tl
    , prononciation .tl_set:N = \l_character_sound_tl
    , unknown  .code:n = {}
}

% #1 * if girl
% #2 - (flag for another function not present in this sample)
% #3 [options] - lastname, age, description, etc
% #4 < shortRefName >
% #5 { first name }
\NewDocumentCommand{\createCharacter}{s t- o D<>{#5} m}{
    
    % we don't want that the unset keys are carried over from the previous ones
    \group_begin:
    \IfValueT{#3}{\keys_set:nn{Character/Identity}{#3}}
    
    \cs_new_protected:cpx { #4 Age } { \int_eval:n { \l_character_age_int } }
    
    \cs_new_protected:cpn { #4 Name }  { #5 }
    \cs_new_protected:cpx { #4 FName }  { \use:c { #4 Name } ~ \exp_not:V \l_character_lastname_tl }
    \cs_new_protected:cpx { #4 LName }  { \exp_not:V \l_character_lastname_tl }

    %glossary related
    \cs_new_protected:cpx { #4 gdsc }  { \exp_not:V \l_character_desc_tl }
    \cs_new_protected:cpx { #4 gpro }  { \exp_not:V \l_character_sound_tl }
    \cs_new_protected:cpx { #4 glbl }  { p: \use:c {#4} }
    
    
    \newglossaryentry{ 
        p:#4 
    }{
        type={ perso }, 
        name={ \use:c { #4 FName }  }, 
        description={ \use:c { #4 gdsc }  }, 
        symbol={ \use:c { #4 gpro } }
    }
    

    
    \group_end:
    
}

\ExplSyntaxOff

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% END OF Class Abstract File     %%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% START of Character Setup File  %%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\createCharacter[lastname=Doe, prononciation={dʒɑn do}, glosEntry={Private Detective who is the main character of this sample}, age=35]<hero>{John} 


\createCharacter[lastname=Doe, prononciation={dʒen do}, glosEntry={The wife of our private detective}, age=33]<herowife>{Jane} 

\createCharacter[lastname=Smith, prononciation={magi smiθ}, glosEntry={The client}, age=41]<client>{Maggie} 

\createCharacter[lastname=Maggot, prononciation={lari magot}, glosEntry={The suspect \#1}, age=48]<sus>{Larry} 

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% END of Character Setup File    %%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\title{Character glossary sample}

\author{me ^_^}


\makeindex

\glsaddall

\begin{document}
    
\chapter {sample}
Some story of a detective named \heroFName\ who tries to help his client, Mrs. \clientFName , to find the murderer of her husband.


\appendix
\chapter{To check}
    
\printnoidxglossaries
    
\end{document}

EDIT 2:

first list is the obtained result and 2nd is what I would like to acheive

obtained vs wanted

2
  • 4
    posting fragments of code makes it very hard to debug, show a small complete document that gives the error, and show the full error message from the log file Nov 14, 2023 at 21:25
  • I put a "working" example. Since a lot of the setup is missing, there are weird behaviors around the glossary, but you will still be able to see the error where Instead of putting the right letter and put them all in alphebetical order, it just throw them all in order of creation under a "Symbols" group. As explained, I would like to be able to bypass that limitation (I would prefer not to create individual glossary entries and autogenerate them instead since I have a lot of entries. Nov 15, 2023 at 14:16

1 Answer 1

1

Thanks to David Carlisle for his explanation that helped me discover the issue with the function itself. Here is the definitive answer:

the problem was really with that little chunk for glossary automation

\newglossaryentry{ 
    p:#4 
}{
    type={ perso }, 
    name={ \user:c { #4 FName} }, 
    description={ \use:c { #4 gdsc }  }, 
    symbol={ \use:c { #4 gpro } }
}

As he mentioned, the glossary receive a weird version of the variable because it was not correctly expanded. His fix was removing the warning, but was not correcting the behaviour. In my case, I could have use this code instead

\newglossaryentry{ 
    p:#4 
}{
    type={ perso }, 
    name={ #5 ~ \exp_not:V \l_character_lastname_tl }, 
    description={ \use:c { #4 gdsc }  }, 
    symbol={ \use:c { #4 gpro } }
}

or

\newglossaryentry{ 
    p:#4 
}{
    type={ perso }, 
    name={ \exp_not:V \l_character_lastname_tl,~ #5 }, 
    description={ \use:c { #4 gdsc }  }, 
    symbol={ \use:c { #4 gpro } }
}

which both do the trick even without the little proposed fix. This is because the \use:c do convert into \csname ... \endcsname and this is how it is sent to glossary that throw the error.

but for an even cleaner solution if I still want to use the \use:c, I can do this:

\newglossaryentry{ 
    p:#4 
}{
    type={ perso }, 
    name={ \exp_not:f {\use:c {#4 FName}} }, 
    description={ \use:c { #4 gdsc }  }, 
    symbol={ \use:c { #4 gpro } }
}

(I could also do the same expand for description and symbol, but it does not affect the result in my case since I sort by sortvalue / name)

1
  • ah good, I think it's probably best if I delete my answer then Nov 15, 2023 at 19:09

You must log in to answer this question.

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