From b77f9a32996b6b705d97327b856f4b4b8042c19d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Ke=C3=9Fler?= Date: Fri, 10 Sep 2021 09:43:26 +0200 Subject: [PATCH] add options to vocab class for providing index or not. give index an internal name and provide \printvocabindex command --- mkessler-vocab.sty | 48 ++++++++++++++++++++++++++++++++-------------- 1 file changed, 34 insertions(+), 14 deletions(-) diff --git a/mkessler-vocab.sty b/mkessler-vocab.sty index 4df83f3..7de937e 100644 --- a/mkessler-vocab.sty +++ b/mkessler-vocab.sty @@ -3,22 +3,42 @@ %%%%%%%%%%%%%%%%%% %%Provides a \vocab<[name in index]>{vocabulary} command to print vocabulary in bold blue and automatically index it. -\newif\ifenglish\englishtrue -\DeclareOption{german}{\englishfalse} -\DeclareOption{english}{\englishtrue} +\newif\ifmkessler@vocab@english\mkessler@vocab@englishtrue +\DeclareOption{german}{\mkessler@vocab@englishfalse} +\DeclareOption{english}{\mkessler@vocab@englishtrue} + +\newif\ifmkessler@vocab@index\mkessler@vocab@indexfalse +\DeclareOption{index}{\mkessler@vocab@indextrue} +\DeclareOption{noindex}{\mkessler@vocab@indexfalse} + \DeclareOption*{\PackageWarning{mkessler-vocab}{Unknown '\CurrentOption'}} \ProcessOptions\relax %%%%Management of vocabulary and corresponding index -\RequirePackage{imakeidx} -\makeindex[columns=2, title=\ifenglish Index\else Stichwortverzeichnis\fi, intoc] - -%Emphasize \vocabulary \RequirePackage{xparse} -\RequirePackage{expl3} -\ExplSyntaxOn -\NewDocumentCommand{\vocab}{O{} m}{ - \textbf{\color{blue} #2} - \ifthenelse{\isempty{#1}}{\index{\text_titlecase_first:n{#2}}}{\index{#1}} -} -\ExplSyntaxOff +\RequirePackage{xcolor} +\ifmkessler@vocab@index + \RequirePackage{imakeidx} + \makeindex[name=mkessler@vocab@indexname, columns=2, title=\ifmkessler@vocab@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[mkessler@vocab@indexname]{\text_titlecase_first:n{#2}} % true branch: #1 was empty + \else + \index[mkessler@vocab@indexname]{#1} % false branch: #1 was supplied + \fi + } + \ExplSyntaxOff + \newcommand\printvocabindex{ + \printindex[mkessler@vocab@indexname] + } +\else + \NewDocumentCommand{\vocab}{O{} m }{ + \textbf{\color{blue} #2} + } +\fi +