summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/dhua/dhua.sty
blob: 075b4e0eb36a04e65b055c4fd8593699e72baeb5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
\ProvidesPackage{dhua}[2011/09/19 v0.11 German phrase abbrevs (UL)]
%% copyright (C) 2011 Uwe Lueck, 
%% http://www.contact-ednotes.sty.de.vu 
%% -- author-maintained in the sense of LPPL below.
%%
%% This file can be redistributed and/or modified under 
%% the terms of the LaTeX Project Public License; either 
%% version 1.3c of the License, or any later version.
%% The latest version of this license is in
%%     http://www.latex-project.org/lppl.txt
%% We did our best to help you, but there is NO WARRANTY. 
%%
%% Please report bugs, problems, and suggestions via 
%% 
%%   http://www.contact-ednotes.sty.de.vu 
%%
%% \pagebreak
%% == Package Options ==
%% \label{sec:opt} 
%% === Idea ===
%% You may say ``I can \[`\newcommand{\ua}{u.\,a.\xspace}'\]
%% myself." Yes, you can. The point of \[`\newtwopartdhua{\ua}{u}{a}'\] 
%% is that you can use that same defining instruction for all of the 
%% following \emph{types of documents:} \ (i)~\emph{requiring} |\xspace| 
%% because in the source some `\ua' precedes a word without control space 
%% (`\ ', as in `\ua weil'); \ (ii)~\emph{not} using `\xspace'
%% (I use it with \CtanPkgRef{morehype}{blog.sty} 
%%  where `\xspace' does not work); 
%% \ (iii)~to be typeset for high-quality \emph{printing} 
%% (thin space strongly recommended)
%% \ (iv)~to be displayed as \HTML\ 
%% (\Wikienref{web typography} relevant, thin space somewhat dangerous). 
%% \
%% In order to use (almost) the \emph{same source} for (iii) and (iv), 
%% the \LaTeX\ document preamble just must load the |[web]| option 
%% for (iv) where it doesn't for (iii). 
%% 
%% === `web' ===
%% \begin{german}
%%    Paketoption |[web]| verwendet ein gesch\"utztes 
%%    Leerzeichen normaler Breite anstelle des empfohlenen 
%%    schmalen Festabstands.
%% \end{german}
%% In \wikienref{web typography}{web typography,} ` ' 
%% (\Wikienref{no-break space}) may be used instead of a thin space 
%% because some browsers do not support the latter 
%% (the non-breakable one---which is not a \emph{named} \HTML\ 
%%  entity, it is U+202F---and some even the breakable one---which 
%% is the named \HTML\ entity \verb+ +).
%% You can decide for this choice by package option |[web]|.
%% (Actually I use the package for direct \HTML\ generation 
%%  with 'blog.sty'.)
%%
%% === `xspace' ===
%% With option |[xspace]|, the package's setup commands equip all the 
%% single abbreviation macros with a final `\xspace' from the 
%% \ctanpkgref{xspace} package in the \LaTeX\ \ctanpkgref{tools} bundle. 
%% % (With 'blog.sty', `\xspace' does not work.)
%% \begin{german}
%%   Mit der Paketoption `[xspace]' verwenden alle Abk\"urzungsmakros 
%%   automatisch (\mbox{--} sie enden auf \mbox{--}) `\xspace'.
%% \end{german}
%%
%% === Implementations ===
%% |\dhuaspace| stores the dot plus the inner space
%% (TODO could be useful for Euro symbol without dot). 
%% The default setting is:
\newcommand*\dhuaspace{.\,}
%% |\DhuaSpace| is for getting a single token in 
%% \verb+\edef+s: 
\newcommand*{\DhuaSpace}{\noexpand\dhuaspace}
%% Option |[web]| uses the tilde (tie, `~') instead of `\,':
\DeclareOption{web}{\newcommand*\dhuaspace{.~}}
%% I reasoned as follows for this: \ (i)~\emph{Either} the \HTML\ is 
%% generated from \acro{DVI}, this is what 
%% \CtanPkgRef{tex4ht}{TeX4ht} does. I don't know exactly, 
%% but I assume that the combinatin of \pkg{TeX4ht} with a 
%% \TeX\ run finally converts the tilde into ` '.
%% \ (ii)~\emph{Or} the \HTML\ generator translates the \TeX\ code 
%% into \HTML\ in a more direct way. I don't know what all of these 
%% programs actually do, but they ``should" translate `~' into 
%% ` '. At least 'blog.sty' does, for sure. 
%%
%% |\dhuaxspace| stores what closes the entire 
%% abbreviation definition; by default it is a dot only. 
%% Because German text should be typeset using
%% `\frenchspacing', we do not care about the space factor:
\newcommand*{\dhuaxspace}{.}
\@ifdefinable{\DhuaXspace}{\let\DhuaXspace\dhuaxspace}
\DeclareOption{xspace}{%
    \AtEndOfPackage{\RequirePackage{xspace}}%%          %% 2011/09/09
    \renewcommand*{\dhuaxspace}{.\xspace}%
    \renewcommand*{\DhuaXspace}{\noexpand\dhuaxspace}}
%% ---That were all options, processed now:
\ProcessOptions
%%
%% == Setup Commands ==
%% \label{sec:setup}
%% The syntax |\newdhua{<new-macro>}{<replace>}| is the same 
%% as for \LaTeX's standard `\newcommand' etc. defining 
%% user macros \emph{without parameters}. 
%% However, `\newdhua' internally uses `\edef' in order to 
%% minimize the number of tokens in the actual internal 
%% replacement text. This additionally requires using 
%% `\DhuaSpace' for separating the one-word abbreviations 
%% in <replace>. 
\newcommand*{\newdhua}[2]{\@ifdefinable#1{%
%     \protected@edef#1{#2\DhuaXspace}%
    \let\protect\noexpand                       %% 2011/09/04
%% ... an unusual meaning of |\protect|, CARE! 
%% I.e., `\protect' is used here to prevent expansion 
%% in the setup macros. It is not stored for future expansion 
%% with its usual robustification purpose.
    \edef#1{#2\DhuaXspace}%
    \let\protect\@typeset@protect
}}
%% \begin{german}
%%   Um ein Makro <neu> f\"ur eine Abk\"urzung mit beliebig vielen 
%%   Gliedern zu definieren, trennt man die einzelnen Glieder 
%%   im <Ergebnis>-Argument der Definition 
%%   |\newdhua{<neu>}{<Ergebnis>}| 
%%   durch `\DhuaSpace' (Beispiel unten).
%%
%% \[|\newtwopartdhua{<neu>}{<B.-1>}{<B.-2>}|\]
%%   definiert dasselbe Makro <neu> wie 
%% \[`\newdhua{<neu>}{<B.-1>\DhuaSpace<B.-2>}'\]
%% \end{german}
%%
%% |\newtwopartdhua{<new>}{<letter-1>}{<letter-2>}|
%% results in the same macro <new> as 
%% `\newdhua{<new>}{<letter-1>\DhuaSpace<letter-2>}':
\newcommand*{\newtwopartdhua}[3]{\newdhua#1{#2\DhuaSpace#3}}
%%
%% == Single Abbreviation Macros ==
%% \label{sec:single}
%% The user may want to use 
%% (some of) the following single macro names   %% 2011/09/09
%% for a different purpose or so; to this end, a file 
%% `dhua.cfg' may contain a different set of definitions.
%% `\IfFileExists' works depending on whether a file 
%% `dhua.cfg' is found:
\IfFileExists{dhua.cfg}{% 
  \typeout{^^J * single definitions read from 
               \string`dhua.cfg\string'         %% 2011/09/19
               *^^J}%
  \input{dhua.cfg}}{% 
%% |\idR| exemplifies multi-part abbreviations, 
%% where \qtd{multi} means ``more than two":
  \newdhua{\idR}{i\DhuaSpace d\DhuaSpace R}
%   \show\idR
%% \begin{german}
%%   |\idR| erzeugt \qtd{\idR} -- ein Anwendungsfall 
%%   f\"ur |\newdhua|. Nachfolgend wird nur noch 
%%   |\newtwopartdhua| verwendet.
%% \end{german}
%%
%% \LaTeX\ actually defines |\dh| as something nordic 
%% (one of my earliest macro making experiences)
%% so we are \emph{re}defining it:
  \PackageWarning{dhua}{Redefining \string\dh}
  \let\dh\relax
  \newtwopartdhua{\dh}{d}{h}
%   \show\dh
%% \begin{german}
%%   |\dh| wird hier \emph{umdefiniert}, um \qtd{\dh} zu bekommen.
%%   Die \"ubrigen Makros sind \qtd{normale} Anwendungs\-f\"alle 
%%   von `\newtwopartdhua', man achte aber noch auf die 
%%   Verwendung von `\protect'.
%% \end{german}
%%
%% \dqtd{Normal} cases                          %% TODO catchdq
%% (|\oae|  for \qtd{\oae}, 
%%  |\so|   for \qtd{\so},  |\su|   for \qtd{\su}, %% 2011/09/19
%%  |\uae|  for \qtd{\uae}, 
%%  |\ua|   for \qtd{\ua},  |\vglu| for \qtd{\vglu},
%%  |\vglo| for \qtd{\vglo}, 
%%  |\zB|   for \qtd{\zB},   %% was |\qtd{\zB}| until 2011/09/19
%%  |\zT|   for \qtd{\zT}):
  \newtwopartdhua{\oae}{o}{\protect\"a} 
% \newtwopartdhua{\oae{o}{\"a} 
%   \show\oae
%% ---exemplifying use of |\protect| so the definition of `\oae'
%% has a single token `\"', not an expansion of `\"'. 
  \newtwopartdhua{\so}  {s}{o} 
  \newtwopartdhua{\su}  {s}{u} 
  \newtwopartdhua{\ua}  {u}{a} 
  \newtwopartdhua{\uae} {u}{\protect\"a} 
  \newtwopartdhua{\vglu}{vgl}{u} 
  \newtwopartdhua{\vglo}{vgl}{o} 
  \newtwopartdhua{\zB}  {z}{B}
  \newtwopartdhua{\zT}  {z}{T} 
}                                       %% Closes \IfFileExists
%%
%% == A Different Approach ==
%% \begin{german}
%%   Statt f\"ur 
%%   \qtd{\abkii AB} %%% `A.\,B.' 
%%   ein Makro zu definieren, 
%%   kann man auch \glqq`\abkii AB'\grqq\ tippen.
%% \end{german}
%%
%% I also thought that, instead of defining an abbreviation macro 
%% (perhaps `\<letter-1><letter-2>'), 
%% |\abkii <letter-1><letter-2>|  %% add. space rm. {} 2011/09/10
%% could be preferred to typing the 
%% the two dots and `\,':
\@ifdefinable\abkii{%               %% w/o `protected' 2011/09/09:
    \edef\abkii#1#2{#1\DhuaSpace#2\DhuaXspace}} 
%   \show\abkii
%% So `\abkii AB' results in \qtd{\abkii AB}, saving you from 
%% `A.\,B.'.---You may create 
%% your own shorter alias <shal> for `\abkii' by `\let<shal>\abkii'.
%% Perhaps `\II': \let\II\abkii 
%% `\let\II\abkii'---`\II AB'---\qtd{\II AB}. 
%% Is this better than `A.\,B.'?
%% 
%% == The End ==
\endinput
%%
%% == VERSION HISTORY ==
v0.1    2011/09/13  renamed `dhusw'->`dhua'
v0.1a   2011/09/14  doc. fix
        2011/09/16  doc. of options much extended
v0.11   2011/09/19  don't use \qtd with .cfg-\typeout; \so, \su; 
                    doc. fix \zB