我已经研究过这两个相关主题,但我的情况略有不同。
我发现的第一件事是词汇表手册是为了激活这个
\glssetexpandfield{name}
\glssetexpandfield{sortvalue}
但即便如此,案件也没能解决。下面是我自定义类中的代码摘录
% 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:
}
所以我的问题是,我怎样才能让它以正确的扩展级别工作(我尝试把它放在\exp_not:f
词汇表输入命令之前,但似乎没有改变任何东西。
提前致谢。
编辑1:
这是一个小例子。由于缺少了一些东西,附录中出现了一个奇怪的行为,名字重复出现,但我相信这是因为包直接在文档中,这改变了行为,因为我的实际文档中没有发生这种奇怪的事情。
我使用LuaLaTeX来编译。
\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}
编辑2:
第一个列表是获得的结果,第二个是我想要实现的
答案1
谢谢大卫·卡莱尔感谢他的解释,帮助我发现了函数本身的问题。以下是明确的答案:
问题实际上出在词汇表自动化的那一小部分
\newglossaryentry{
p:#4
}{
type={ perso },
name={ \user:c { #4 FName} },
description={ \use:c { #4 gdsc } },
symbol={ \use:c { #4 gpro } }
}
正如他提到的,词汇表收到的变量版本很奇怪,因为它没有正确扩展。他的修复方法是删除警告,但并没有纠正行为。就我而言,我可以使用以下代码代替
\newglossaryentry{
p:#4
}{
type={ perso },
name={ #5 ~ \exp_not:V \l_character_lastname_tl },
description={ \use:c { #4 gdsc } },
symbol={ \use:c { #4 gpro } }
}
或者
\newglossaryentry{
p:#4
}{
type={ perso },
name={ \exp_not:V \l_character_lastname_tl,~ #5 },
description={ \use:c { #4 gdsc } },
symbol={ \use:c { #4 gpro } }
}
即使没有建议的小修复,这两个方法也能解决问题。这是因为 do\use:c
转换为\csname ... \endcsname
,这就是它被发送到引发错误的词汇表的方式。
但如果我仍然想使用更清洁的解决方案\use:c
,我可以这样做:
\newglossaryentry{
p:#4
}{
type={ perso },
name={ \exp_not:f {\use:c {#4 FName}} },
description={ \use:c { #4 gdsc } },
symbol={ \use:c { #4 gpro } }
}
(我也可以对描述和符号进行相同的扩展,但这不会影响我的情况的结果,因为我按 sortvalue/名称排序)