If you want to get rid of all hyphens for sorting, you can do like this, which essentially does automatically \index{firstlove@first-love}
when the input is \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}
If you want to keep \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}