(有点像是后续问题这个。)以下示例包含一个需要额外注意的缩写定义:[Śatika-]Kālajñāna 应该在缩写列表和索引中按 Kālajñāna 排序。 (顺便说一句,我确实有一个 xindy 文件来处理所有变音符号,但这当然在这里没有帮助。)可能为这样的例外创建一个额外的 xindy 文件可能是解决问题的一种方法,但我希望有一种更简洁的方法来做到这一点?
\documentclass{memoir}
\usepackage{polyglossia}
\setdefaultlanguage{english}
\setotherlanguage{sanskrit}
\setotherlanguage{german}
\setotherlanguage{french}
\newfontfamily\sanskritfont{Latin Modern Roman}[Ligatures=TeX]
\newrobustcmd{\skti}[1]{\emph{\textsanskrit{#1}}}
\usepackage[abbreviations,xindy]{glossaries-extra}
\GlsSetQuote{+}
\GlsXtrSetEscChar{+}
\makeglossaries
\makeindex
\glssetcategoryattribute{abbreviation}{dualindex}{true}
\glssetcategoryattribute{general}{glossname}{firstuc}
\GlsXtrEnableIndexFormatOverride
\renewcommand*{\glsxtrautoindexentry}[1]{\string\glsentryfirst{#1}}
\renewcommand*{\glsxtrautoindexassignsort}[2]{%
\ifglshaslong{#2}%
{\glsletentryfield{#1}{#2}{long}}%
{\glsletentryfield{#1}{#2}{sort}}%
}
\setabbreviationstyle{long-short}
\newabbreviation{yh}{YH}{\skti{Yoginīhṛdaya}}
\newabbreviation{śkj}{{}[Ś]KJ}{\skti{[Śatika-]Kālajñāna}}
\makeatletter
\renewcommand*{\glsxtrautoindexassignsort}[2]{%
\glsxtrifhasfield*{long}{#2}%
{%
\let\orgskti\skti
\let\skti\@firstofone
\protected@edef#1{\glscurrentfieldvalue}%
\let\skti\orgskti
}%
{\glsletentryfield{#1}{#2}{sort}}%
}
\makeatother
\begin{document}
\gls{yh}
\gls{śkj}
\printglossaries
\printindex
\end{document}
答案1
我认为,最简单的方法就是使用密钥sort
:
\newabbreviation[sort={Kālajñāna}]{śkj}{{}[Ś]KJ}{\skti{[Śatika-]Kālajñāna}}
这处理词汇表。索引的排序值是通过字段long
(Within \glsxtrautoindexassignsort
) 在文档中获取的,因此处理该问题的一种方法是提供一个格式化方括号材料的命令:
\newrobustcmd{\squarebracket}[1]{[#1]}
(我建议为该命令选择一个更好的名称。)然后缩写可以定义为:
\newabbreviation[sort={Kālajñāna}]{śkj}{{}[Ś]KJ}{\skti{\squarebracket{Śatika-}Kālajñāna}}
可以本地重新定义此自定义命令以在获取排序值时忽略其参数:
\makeatletter
\renewcommand*{\glsxtrautoindexassignsort}[2]{%
\glsxtrifhasfield*{long}{#2}%
{%
\let\orgskti\skti
\let\orgsquarebracket\squarebracket
\let\skti\@firstofone
\let\squarebracket\@gobble
\protected@edef#1{\glscurrentfieldvalue}%
\let\skti\orgskti
\let\squarebracket\orgsquarebracket
}%
{\glsletentryfield{#1}{#2}{sort}}%
}
\makeatother
完整的 MWE:
\documentclass{memoir}
\usepackage{polyglossia}
\setdefaultlanguage{english}
\setotherlanguage{sanskrit}
\setotherlanguage{german}
\setotherlanguage{french}
\newfontfamily\sanskritfont{Latin Modern Roman}[Ligatures=TeX]
\newrobustcmd{\skti}[1]{\emph{\textsanskrit{#1}}}
\usepackage[abbreviations,xindy]{glossaries-extra}
\GlsSetQuote{+}
\GlsXtrSetEscChar{+}
\makeglossaries
\makeindex
\newrobustcmd{\squarebracket}[1]{[#1]}
\glssetcategoryattribute{abbreviation}{dualindex}{true}
\glssetcategoryattribute{general}{glossname}{firstuc}
\GlsXtrEnableIndexFormatOverride
\renewcommand*{\glsxtrautoindexentry}[1]{\string\glsentryfirst{#1}}
\renewcommand*{\glsxtrautoindexassignsort}[2]{%
\ifglshaslong{#2}%
{\glsletentryfield{#1}{#2}{long}}%
{\glsletentryfield{#1}{#2}{sort}}%
}
\setabbreviationstyle{long-short}
\newabbreviation{yh}{YH}{\skti{Yoginīhṛdaya}}
\newabbreviation[sort={Kālajñāna}]{śkj}{{}[Ś]KJ}{\skti{\squarebracket{Śatika-}Kālajñāna}}
\makeatletter
\renewcommand*{\glsxtrautoindexassignsort}[2]{%
\glsxtrifhasfield*{long}{#2}%
{%
\let\orgskti\skti
\let\orgsquarebracket\squarebracket
\let\skti\@firstofone
\let\squarebracket\@gobble
\protected@edef#1{\glscurrentfieldvalue}%
\let\skti\orgskti
\let\squarebracket\orgsquarebracket
}%
{\glsletentryfield{#1}{#2}{sort}}%
}
\makeatother
\begin{document}
\gls{yh}
\gls{śkj}
\printglossaries
\printindex
\end{document}
缩写词汇表文件 ( .glo-abr
) 包含:
(indexentry :tkey (("YH" "\\glossentry{yh}") ) :locref "{}{1}" :attr "pageglsnumberformat" )
(indexentry :tkey (("Kālajñāna" "\\glossentry{śkj}") ) :locref "{}{1}" :attr "pageglsnumberformat" )
该部分的第一个参数:tkey
是排序值。索引文件包含:
\indexentry{Yoginīhṛdaya@\glsentryfirst{yh}}{1}
\indexentry{Kālajñāna@\glsentryfirst{śkj}}{1}
之前的部分@
是排序值。因此在这两种情况下,括号内的部分都被删除了。
(顺便说一下,我会用bib2gls
而不是xindy
对于这种类型的文档,对于词汇表和索引,因为像这样的命令\squarebracket
可以在本地重新定义以供bib2gls
使用,但我意识到在现有文档中切换并不简单。)