latex-packages/packages/misc/vocab.pysty
2021-10-07 08:38:30 +02:00

41 lines
1.1 KiB
Text

__HEADER__(Package for emphasizing vocabulary)
%%Provides a \vocab<[name in index]>{vocabulary} command to print vocabulary in bold blue and automatically index it.
\RequirePackage{xkeyval}
__LANGUAGE_OPTIONS__
__NEW_IF__(index,false)
\DeclareOption{index}{__SET_IF__(index,true)}
\DeclareOption{noindex}{__SET_IF__(index,false)}
__END_OPTIONS_X__
%%%%Management of vocabulary and corresponding index
\RequirePackage{xparse}
\RequirePackage{xcolor}
__IF__(index)
\RequirePackage{imakeidx}
\makeindex[name=vocabindex, columns=2, title=__IF__(english) Index\else Stichwortverzeichnis\fi, intoc]
%Emphasize \vocabulary
\RequirePackage{expl3}
\ExplSyntaxOn
\NewDocumentCommand{\vocab}{O{} m}{
\textbf{\color{blue} #2}%
\if\relax\detokenize{#1}\relax%
\index[vocabindex]{\text_titlecase_first:n{#2}} % true branch: #1 was empty
\else
\index[vocabindex]{#1} % false branch: #1 was supplied
\fi
}
\ExplSyntaxOff
\newcommand\printvocabindex{
\printindex[vocabindex]
}
\else
\NewDocumentCommand{\vocab}{O{} m }{
\textbf{\color{blue} #2}
}
\fi