Convert sty to dtx and create an install file [WIP]

To have a proper LaTeX package convert the `dictionary.sty` to
`dictionary.dtx` and create the install file `dictionary.ins`.
This commit is contained in:
finga 2025-03-02 19:08:24 +01:00
parent cc886096f2
commit 094b2a4f8e
5 changed files with 245 additions and 30 deletions

12
.gitignore vendored Normal file
View file

@ -0,0 +1,12 @@
*.aux
*.dvi
*.glo
*.gls
*.hd
*.idx
*.ilg
*.log
*.out
*.pdf
*.sty
*.toc

View file

@ -5,10 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [Unreleased]
## v0.1.0 [Unreleased]
### Added
- Convert `dictionary.sty` to `dictionary.dtx` and create the install
file `dictionary.ins`.
- Set the languages of the dictionary by using the package options
`primary` and `secondary`.
- Create the `dictionary` environment where the

173
dictionary.dtx Normal file
View file

@ -0,0 +1,173 @@
% \iffalse meta-comment
%
% Copyright (C) 2024 by Fabian Nedoluha <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 Fabian Nedoluha.
%
% 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{Fabian Nedoluha}
% \date{\fileversion~from \filedate}
%
% \maketitle
% \tableofcontents
%
% \begin{abstract}
% The \textsf{dictionary} \LaTeX\ package provides utility macros
% helping to typeset a dictionary. With the help of the datatool
% package it can build a database of words and their translation. Such
% a database can then be used to create a dictionary like text.
% \end{abstract}
%
% \section{Introduction}
%
% Currently only an environment and a macro are provided.
%
% \section{Usage}
%
% To use the \textsf{dictionary} package both package options
% (\texttt{primary} and \texttt{secondary}) have to be passed before
% using the package macros.
%
% \subsection{Package options}
%
% The package options \texttt{primary} and \texttt{secondary} have to
% be passed to \textsf{dictionary}. The \texttt{primary} option sets
% the language first part of each dictionary's entry and the
% \texttt{secondary} option sets the language of the second part,
% typically the translation, of each dictionary's entry.
%
% \DescribeMacro{\entry}
%
% The \texttt{\textbackslash entry} macro is used inside the
% \texttt{dictionary} environment in order to add entries to the
% dictionary. It expects two parameters, the primary part and the
% secondary part.
%
% \DescribeEnv{dictionary}
%
% The \texttt{dictionary} environment represents a dictionary. It is
% empty at the beginning but can be filled with the
% \texttt{\textbackslash entry} macro.
%
%
% \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

57
dictionary.ins Normal file
View file

@ -0,0 +1,57 @@
%% Copyright (C) 2024 by Fabian Nedoluha <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 Fabian Nedoluha.
%%
%% This work consists of the files dictionary.dtx and dictionary.ins
%% and the derived filebase dictionary.sty.
%%
\input docstrip.tex
\keepsilent
\usedir{tex/latex/dictionary}
\preamble
This is a generated file.
Copyright (C) 2024 by Fabian Nedoluha <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.
\endpreamble
\generate{\file{dictionary.sty}{\from{dictionary.dtx}{package}}}
\obeyspaces
\Msg{*************************************************************}
\Msg{* *}
\Msg{* To finish the installation you have to move the following *}
\Msg{* file into a directory searched by TeX: *}
\Msg{* *}
\Msg{* dictionary.sty *}
\Msg{* *}
\Msg{* To produce the documentation run the file dictionary.dtx *}
\Msg{* through LaTeX. *}
\Msg{* *}
\Msg{* Happy TeXing! *}
\Msg{* *}
\Msg{*************************************************************}
\endbatchfile

View file

@ -1,29 +0,0 @@
\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}{%
\foreignlanguage{\@dictionary@primary}{\textbf{\word:} }\foreignlanguage{\@dictionary@secondary}{\translation}\\}%
}