Debian Codegraph @

texmf-dist/source/latex/dynamicnumber/dynamicnumber.dtx

raw
1 % \iffalse meta-comment
2 %
3 % Copyright (C) 2015 by Olivier Pieters
4 % -------------------------------------
5 %
6 % This file may be distributed and/or modified under the
7 % conditions of the MIT License, a version can be found
8 % in the GitHub repository:
9 %
10 % https://github.com/opieters/DynamicNumber
11 %
12 % \fi
13 %
14 % \iffalse
15 %<package>\NeedsTeXFormat{LaTeX2e}[1999/12/01]
16 %<package>\ProvidesPackage{dynamicnumber}
17 %<package> [2015/10/27 v0.1.3 Dynamic Number package]
18 %
19 %<*driver>
20 \documentclass{ltxdoc}
21 \usepackage{dynamicnumber}
22 \usepackage{hyperref}
23 \EnableCrossrefs
24 \CodelineIndex
25 \RecordChanges
26 \begin{document}
27 \DocInput{dynamicnumber.dtx}
28 \end{document}
29 %</driver>
30 % \fi
31 %
32 % \CheckSum{58}
33 %
34 % \CharacterTable
35 % {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
36 % 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
37 % Digits \0\1\2\3\4\5\6\7\8\9
38 % Exclamation \! Double quote \" Hash (number) \#
39 % Dollar \$ Percent \% Ampersand \&
40 % Acute accent \' Left paren \( Right paren \)
41 % Asterisk \* Plus \+ Comma \,
42 % Minus \- Point \. Solidus \/
43 % Colon \: Semicolon \; Less than \<
44 % Equals \= Greater than \> Question mark \?
45 % Commercial at \@ Left bracket \[ Backslash \\
46 % Right bracket \] Circumflex \^ Underscore \_
47 % Grave accent \` Left brace \{ Vertical bar \|
48 % Right brace \} Tilde \~}
49 %
50 %
51 % \changes{v0.1}{2015/10/04}{Initial version}
52 % \changes{v0.1.1}{2015/10/06}{Performance improvements (one call to newread)}
53 %
54 % \GetFileInfo{dynamicnumber.sty}
55 %
56 % \DoNotIndex{<list of control sequences>}
57 %
58 % \title{The \textsf{dynamicnumber} package\thanks{This document
59 % corresponds to \textsf{dynamicnumber}~\fileversion,
60 % dated \filedate.}}
61 % \author{Olivier Pieters \\ \texttt{me (at) olivierpieters (dot) be}}
62 %
63 % \maketitle
64 %
65 % \section{Introduction}
66 %
67 % Dynamic Number dynamically typesets values generated in different kinds of
68 % scripts in LaTeX through the use of symbolic links. The aim is to reduce
69 % errors resulting from out-of-date numbers by directly setting them in the
70 % number generating file and importing a symbolic link in the LaTeX source file.
71 %
72 % \textbf{Attention!} The name ``symbolic link'' is not related to UNIX symbolic
73 % links.
74 %
75 % \section{Usage}
76 %
77 % \DescribeMacro{\dndeclare}
78 % Declares a dynamic number (dn) list. \index{decare dn list|usage} By creating
79 % a list, variables can be saved and loaded for use in the document. The
80 % mandatory argument is the list name.
81 %
82 % \DescribeMacro{\dnsetcurrent}
83 % This environment does nothing. \index{decare dn list|usage} Sets the current
84 % dn list. The mandatory argument specifies the list name. This command is very
85 % useful if multiple lists are used, so you do not always have to specify the dn
86 % list if it is not the current one.
87 %
88 %% \DescribeMacro{\dncurrent}
89 % Returns the name of current dn list. \index{current dn list|usage} Returns
90 % the current dn list and takes no arguments. This can be useful for debugging
91 % purposes.
92 %
93 % \DescribeMacro{\dnload}
94 % Load dn list \meta{name}|.dnlist|. \index{load dn list|usage} Loads the dn
95 % list whose name is passed as mandatory argument. This argument should only
96 % include the list-name and \emph{not} the filename. It sets the current dn list
97 % to this list.
98 %
99 % \DescribeMacro{\dnget}
100 % Get symbolic link value. \index{get dn list entry|usage} Loads the symbolic link's value from the current dn list if no optional argument is present (optional argument is passed first). Otherwise, the optional argument specifies the dn list containing the symbolic link
101 %
102 % \StopEventually{\PrintIndex}
103 %
104 % \section{Implementation}
105 %
106 % Load all required packages.
107 % \begin{macrocode}
108 \RequirePackage{pgfkeys}
109 \RequirePackage{xparse}
110 % \end{macrocode}
111 %
112 % Create input stream
113 % \begin{macrocode}
114 \newread\dninstream
115 % \end{macrocode}
116 % \begin{macro}{\@IfNoValueOrEmptyTF}
117 % Tests if a parameter is empty using expl3.
118 % Performs a double check to make sure it really is empty.
119 % This is based on \href{http://tex.stackexchange.com/questions/63223/xparse-empty-arguments}{this}
120 % StackExchange post.
121 % \begin{macrocode}
122 \ExplSyntaxOn
123 \DeclareExpandableDocumentCommand{\@IfNoValueOrEmptyTF}{mmm}
124 {
125 \IfNoValueTF{#1}{#2}
126 {
127 % \end{macrocode}
128 % Order: |{argument}{if empty}{if not empty}|
129 % \begin{macrocode}
130 \tl_if_empty:nTF {#1} {#2} {#3}
131 }
132 }
133 \ExplSyntaxOff
134 % \end{macrocode}
135 % \end{macro}
136 %
137 % \begin{macro}{\dndeclare}
138 % The |\dndeclare| macro defines a list name and defines a |pgfkey| that stores
139 % all symbolic links and their values. It always is a subdirectory of |/dynamicnumber|:
140 % |/dynamicnumber/|\meta{name}|/|
141 % \begin{macrocode}
142 \DeclareDocumentCommand{\dndeclare}{m}{%
143 \pgfkeys{%
144 /dynamicnumber/#1/.is family,
145 /dynamicnumber/#1/.unknown/.style = {%
146 \pgfkeyscurrentpath/\pgfkeyscurrentname/.initial = ##1%
147 }
148 }%
149 }
150 % \end{macrocode}
151 % \end{macro}
152 %
153 % \begin{macro}{\dnsetcurrent}
154 % |\dnsetcurrent{|\meta{name}|}| sets the current dn list to \meta{name}.
155 % If no list was previously set, the |\dnsetcurrent| command is defined and
156 % set to \meta{name}.
157 % \begin{macrocode}
158 \DeclareDocumentCommand{\dnsetcurrent}{m}{%
159 \@ifundefined{dncurrent}{%
160 % \end{macrocode}
161 % \begin{macro}{\dncurrent}
162 % Stores the current dn list used in the |\dnget| command.
163 % \begin{macrocode}
164 \DeclareDocumentCommand{\dncurrent}{}{#1}%
165 % \end{macrocode}
166 % \end{macro}
167 % \begin{macrocode}
168 }
169 {%
170 \RenewDocumentCommand{\dncurrent}{}{#1}%
171 }%
172 }
173 % \end{macrocode}
174 % \end{macro}
175 %
176 % \begin{macro}{\dnload}
177 % Loads a dn list from file \meta{load}|.dnlist| and executes all commands in
178 % this file after a check if the file exists.
179 % \changes{v0.1.3}{2015/10/27}{Removed bug where the current list was reset.}
180 % \begin{macrocode}
181 \DeclareDocumentCommand{\dnload}{m}{%
182 \IfFileExists{#1.dnlist}{%
183 \immediate\openin\dninstream=#1.dnlist
184 \@whilesw\unless\ifeof\dninstream\fi{%
185 \immediate\read\dninstream to \@auxcommand
186 \@auxcommand
187 }%
188 \immediate\closein\dninstream%
189 }{}%
190 }
191 % \end{macrocode}
192 % \end{macro}
193 %
194 % \begin{macro}{\dnget}
195 % Get the value stored in a specific dn list entry. A dn list can be specified
196 % (hence optional argument), otherwise the current list will be used.
197 % \begin{macrocode}
198 \DeclareDocumentCommand{\dnget}{O{} m}{%
199 \@IfNoValueOrEmptyTF{#1}{%
200 \pgfkeysvalueof{/dynamicnumber/\dncurrent/#2}}{%
201 \pgfkeysvalueof{/dynamicnumber/#1/#2}}%
202 }
203 \endinput
204 }
205 % \end{macrocode}
206 % \end{macro}
207 %
208 % \Finale
209 \endinput