# Index entries with capitalised letters for each word

TLDR; I'd like an index (like) command that fully expands before executing, so that \newcommand{\words}{Some important Words}\indexCMD{\words}

is exactly like \indexCMD{Some important Words} - as if \words has fully expanded before \index does anything

I have a serious problem, which I can't get my head around how to fix:

I'd like to use splitidx to create several indexes at the end of my Bachelor's thesis, however, in order to consolidate and automate some part of the indexing I'm writing a macro, that automatically adds something to the appropriate index if I use an equivalent of \gls (glossaries-extra) or \ac (acro). My problem is, that every index entry shall have capitalised words, since I'm mixing German and English, and be correctly sorted. I'd like to have a command that makes \index{some Words here AND there} equivalent to \index{Some Words Here AND There}

Example:

\documentclass{article}

\usepackage{splitidx}\makeindex
\newindex[Stichwortverzeichnis]{stw}

\newcommand{\inindex}[1]{#1\sindex[stw]{#1}}

\begin{document}
\inindex{Words are} not as important as other \inindex{words are}.

\printindex[stw]
\end{document}


\newcommand{\inindex}[1]{#1\sindex[stw]{#1@\protect\capitalisewords{#1}}} is working only superficially since they are sorted how they are called so "some Words here AND there" gets a different entry from "Some Words Here AND There} and they appear twice but identically. I only know LaTeX and only little TeX and would like an answer I can fully understand (by explaining each step) and learn from. I tried \expandafter, \expanded and \noexpand in all shapes but never successfully.

Identical problem, different scenario:

\Acl and \Acs are from the acro package

\DeclareAcronym{cfd}{
short = CFD,
long = numerische Strömungsmechanik
}
\newcommand{\newglossaryentryac}[2]{
\newglossaryentryacKeyCommand[
id = {#1},
description = {#2},
longName = \Acl{#1},
shortName = \Acs{#1}
]
}
\newglossaryentryac{cfd}{Beschreibung}


How do I need to modify this, in order for it to be equivalent to

\newcommand{\newglossaryentryac}{
\newglossaryentryacKeyCommand[
id = {cfd} ,
description = {Beschreibung},
longName = Numerische Strömungsmechanik,
shortName = CFD
]
}
\newglossaryentryac

• Welcome! I'm afraid that it's not possible: \Acl is not expandable and just prints the acronym. Do you need two separate commands? Wouldn't it be easier to use just the \newglossaryentryac command, with more keys to perform also the \DeclareAcronym command? Jun 18 '20 at 20:04
• I've tried and tried but either biblatex breaks, it is not compilable, or whatnot. I've tried , using the keycommand package, to define everything separately but due to umlauts (äüö) or \cite it just won't work. It seems I need to do everything manually. Jun 18 '20 at 20:31

My proposal is to define a single command that does both the \DeclareAcronym and the \newglossaryentry business.

\documentclass{article}
\usepackage{acro,glossaries}
\makeglossaries

\ExplSyntaxOn

\keys_define:nn { learex/glossac }
{
short .tl_set:N = \l__clearex_glossac_short_tl,
long  .tl_set:N = \l__clearex_glossac_long_tl,
}
\tl_new:N \l__clearex_glossac_Short_tl
\tl_new:N \l__clearex_glossac_Long_tl

\NewDocumentCommand{\newglossaryentryac}{mmm}
{% #1 = key, #2 = options, #3 = description
\keys_set:nn { learex/glossac }
{% clear all keys
short={},long={},
% assign the values
#2,
}
\tl_set:Nx \l__clearex_glossac_Short_tl
{
\text_titlecase_first:V \l__clearex_glossac_short_tl
}
\tl_set:Nx \l__clearex_glossac_Long_tl
{
\text_titlecase_first:V \l__clearex_glossac_long_tl
}
\use:x
{
% acro
\DeclareAcronym{#1}
{
short = \text_expand:n {\l__clearex_glossac_short_tl},
long = \text_expand:n {\l__clearex_glossac_long_tl},
}
% glossaries
\exp_not:N \newglossaryentry {#1}
{
name = \text_expand:n {\l__clearex_glossac_Long_tl},
\exp_not:n { description = #3\glslink{#1s} },
}
\exp_not:N \newglossaryentry{#1s}
{
name = \text_expand:n {\l__clearex_glossac_Short_tl},
\exp_not:n { description = {siehe~\gls{#1}} },
}
}
}
\cs_generate_variant:Nn \text_titlecase_first:n { V }

\ExplSyntaxOff

\newglossaryentryac{cfd}{
short = CFD,
long = numerische Strömungsmechanik
}{Beschreibung}

\newglossaryentryac{tst}{
short = TST,
long = test
}{Test}
\newglossaryentryac{ubr}{
short = übr,
long = über
}{Über}

\begin{document}

\Acl{cfd} \Acl{cfd} \acl{cfd} \Acs{cfd} \acs{cfd}

\gls{cfd} \gls{cfds}

\Acl{tst} \Acs{tst}

\gls{tst} \gls{tsts}

\Acl{ubr} \Acs{ubr} \acl{ubr} \acs{ubr}

\gls{ubr} \gls{ubrs}

\printglossaries

\end{document}


Uppercasing the initial is obtained by using \text_titlecase_first:n. The \use:x part is because we want the value of the variables, not the variables. With \text_expand:n we are sure that special characters are not mangled.

• I was able to get it to work, I'll only need to expand it to cope with the occasionally appearing foreign form Jun 18 '20 at 21:32
• What would be a good resource to learn the syntax you used in your answer? I’m very unfamiliar with it. Jun 18 '20 at 22:09