% \iffalse meta-comment
%
% Copyright (C) 2024 by finga <finga@onders.org>
% ---------------------------------------------------------------------------
% This work may be distributed and/or modified under the
% conditions of the LaTeX Project Public License, either version 1.3
% of this license or (at your option) any later version.
% The latest version of this license is in
%   http://www.latex-project.org/lppl.txt
% and version 1.3 or later is part of all distributions of LaTeX
% version 2005/12/01 or later.
%
% This work has the LPPL maintenance status `maintained'.
%
% The Current Maintainer of this work is finga.
%
% This work consists of the files dictionary.dtx and dictionary.ins
% and the derived filebase dictionary.sty.
%
% \fi
%
% \iffalse
%<*driver>
\ProvidesFile{dictionary.dtx}
%</driver>
%<package>\NeedsTeXFormat{LaTeX2e}[1999/12/01]
%<package>\ProvidesPackage{dictionary}
%<*package>
    [2024/11/24 v0.1.0 dictionary]
%</package>
%
%<*driver>
\documentclass{ltxdoc}
\usepackage{dictionary}[2024/11/24]
\EnableCrossrefs
\CodelineIndex
\RecordChanges
\begin{document}
  \DocInput{dictionary.dtx}
  \PrintChanges
  \PrintIndex
\end{document}
%</driver>
% \fi
%
% \CheckSum{34}
%
% \CharacterTable
%  {Upper-case    \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
%   Lower-case    \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z
%   Digits        \0\1\2\3\4\5\6\7\8\9
%   Exclamation   \!     Double quote  \"     Hash (number) \#
%   Dollar        \$     Percent       \%     Ampersand     \&
%   Acute accent  \'     Left paren    \(     Right paren   \)
%   Asterisk      \*     Plus          \+     Comma         \,
%   Minus         \-     Point         \.     Solidus       \/
%   Colon         \:     Semicolon     \;     Less than     \<
%   Equals        \=     Greater than  \>     Question mark \?
%   Commercial at \@     Left bracket  \[     Backslash     \\
%   Right bracket \]     Circumflex    \^     Underscore    \_
%   Grave accent  \`     Left brace    \{     Vertical bar  \|
%   Right brace   \}     Tilde         \~}
%
%
% \changes{v0.1.0}{2024/11/24}{Initial version}
%
% \DoNotIndex{\newcommand,\newenvironment}
%
% \providecommand*{\url}{\texttt}
% \GetFileInfo{dictionary.dtx}
% \title{Create a \textsf{dictionary} in \LaTeX}
% \author{finga}
% \date{\fileversion~from \filedate}
%
% \maketitle
% \tableofcontents
%
% \begin{abstract}
% A \LaTeX\ style to print a dictionary.
% \end{abstract}
%
% \section{Introduction}
%
% This package uses datatool to build a database of entries
% andprovides macros to insert and ouput them.
%
% \section{Usage}
%
% Put text here.
%
%
% \DescribeMacro{\entry}
%
%
% \DescribeEnv{dictionary}
%

%
% \StopEventually{}
%
% \section{Implementation}
%
% \iffalse
%<*package>
% \fi
%
%    \begin{macrocode}
\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}
%    \end{macrocode}
%
% \begin{macro}{\entry}
%    \begin{macrocode}
\newcommand{\entry}[2]{%
  \DTLnewrow{dictionary}%
  \DTLnewdbentry{dictionary}{word}{#1}%
  \DTLnewdbentry{dictionary}{translation}{#2}%
}
%    \end{macrocode}
% \end{macro}
%
%
% \begin{environment}{dictionary}
%    \begin{macrocode}
\newenvironment{dictionary}{%
  \DTLifdbexists{dictionary}
                {\DTLcleardb{dictionary}}{\DTLnewdb{dictionary}}%
}{%
  \DTLsort{word}{dictionary}%
  \scriptsize%
  \DTLforeach*{dictionary}{\word=word,\translation=translation}{%
    \foreignlanguage{\@dictionary@primary}{\textbf{\word:}}
    \foreignlanguage{\@dictionary@secondary}{\translation}\\}%
  }
%    \end{macrocode}
% \end{environment}
%

%
% \iffalse
%</package>
% \fi
%
% \Finale
\endinput
