latex-packages/packages/misc/vocab.pysty
2021-10-07 10:06:23 +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_X__
__NEW_IF__(index,false)
\DeclareOptionX{index}{__SET_IF__(index,true)}
\DeclareOptionX{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