答案1
如果你想摆脱全部连字符进行排序,您可以这样做,\index{firstlove@first-love}
当输入时,它基本上会自动执行\Index{first-love}
。
\documentclass{article}
\usepackage{imakeidx}
\usepackage{xparse}
\ExplSyntaxOn
\NewDocumentCommand{\Index}{om}
{
\str_set:Nn \l_tmpa_str { #2 }
\str_if_in:NnTF \l_tmpa_str { - }
{
\str_set_eq:NN \l_tmpb_str \l_tmpa_str
\str_remove_all:Nn \l_tmpb_str { - }
\use:x
{
\exp_not:N \index
\IfValueT { #1 } { [ #1 ] }
{ \str_use:N \l_tmpb_str @ \str_use:N \l_tmpa_str }
}
}
{
\use:x
{
\exp_not:N \index
\IfValueT { #1 } { [ #1 ] }
{ \str_use:N \l_tmpa_str }
}
}
}
\ExplSyntaxOff
\makeindex[columns=1]
\begin{document}
Test
\Index{firstaid}
\Index{first-love}
\printindex
\end{document}
如果你想保留\index
:
\documentclass{article}
\usepackage{imakeidx}
\usepackage{xparse}
\AtBeginDocument{%
\let\originalindex\index
\let\index\newindex
}
\ExplSyntaxOn
\NewDocumentCommand{\newindex}{om}
{
\str_set:Nn \l_tmpa_str { #2 }
\str_if_in:NnTF \l_tmpa_str { - }
{
\str_set_eq:NN \l_tmpb_str \l_tmpa_str
\str_remove_all:Nn \l_tmpb_str { - }
\use:x
{
\exp_not:N \originalindex
\IfValueT { #1 } { [ #1 ] }
{ \str_use:N \l_tmpb_str @ \str_use:N \l_tmpa_str }
}
}
{
\use:x
{
\exp_not:N \originalindex
\IfValueT { #1 } { [ #1 ] }
{ \str_use:N \l_tmpa_str }
}
}
}
\ExplSyntaxOff
\makeindex[columns=1]
\begin{document}
Test
\index{firstaid}
\index{first-love}
\printindex
\end{document}