latex-dictionary/dictionary.sty
finga 01849f4046 Set languages via package options
To define the languages for the dictionary the package options primary
and secondary have to be set.
2025-02-28 12:19:42 +01:00

30 lines
867 B
TeX

\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{dictionary}[2024/11/24 Dictionary]
\RequirePackage{babel}
\RequirePackage{datatool}
\DeclareKeys[dictionary]{
primary.store = \@dictionary@primary,
secondary.store = \@dictionary@secondary
}
\ProcessKeyOptions[dictionary]
\PassOptionsToPackage{\@dictionary@primary,\@dictionary@secondary}{babel}
\newcommand{\entry}[2]{%
\DTLnewrow{dictionary}%
\DTLnewdbentry{dictionary}{word}{#1}%
\DTLnewdbentry{dictionary}{translation}{#2}%
}
\newenvironment{dictionary}{%
\DTLifdbexists{dictionary}{\DTLcleardb{dictionary}}{\DTLnewdb{dictionary}}%
}{%
\DTLsort{word}{dictionary}%
\scriptsize%
\DTLforeach*{dictionary}{\word=word,\translation=translation}{%
\selectlanguage{\@dictionary@primary}\textbf{\word:} \selectlanguage{\@dictionary@secondary}\translation\\}%
\selectlanguage{\@dictionary@primary}%
}