-
Notifications
You must be signed in to change notification settings - Fork 26
/
siunitx-symbol.dtx
329 lines (329 loc) · 9.79 KB
/
siunitx-symbol.dtx
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
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
% \iffalse meta-comment
%
% File: siunitx-symbol.dtx Copyright (C) 2018-2024 Joseph Wright
%
% It may be distributed and/or modified under the conditions of the
% LaTeX Project Public License (LPPL), either version 1.3c of this
% license or (at your option) any later version. The latest version
% of this license is in the file
%
% https://www.latex-project.org/lppl.txt
%
% This file is part of the "siunitx bundle" (The Work in LPPL)
% and all files in that bundle must be distributed together.
%
% The released version of this bundle is available from CTAN.
%
% -----------------------------------------------------------------------
%
% The development version of the bundle can be found at
%
% https://github.com/josephwright/siunitx
%
% for those people who are interested.
%
% -----------------------------------------------------------------------
%
%<*driver>
\documentclass{l3doc}
% Additional commands needed in this source
\ProvideDocumentCommand\email{m}{\href{mailto:#1}{\nolinkurl{#1}}}
% The next line is needed so that \GetFileInfo will be able to pick up
% version data
\usepackage{siunitx}
\begin{document}
\DocInput{\jobname.dtx}
\end{document}
%</driver>
% \fi
%
% \GetFileInfo{siunitx.sty}
%
% \title{^^A
% \pkg{siunitx-symbol} -- Symbol-related settings^^A
% \thanks{This file describes \fileversion,
% last revised \filedate.}^^A
% }
%
% \author{^^A
% Joseph Wright^^A
% \thanks{^^A
% E-mail:
% \email{[email protected]}^^A
% }^^A
% }
%
% \date{Released \filedate}
%
% \maketitle
%
% \begin{documentation}
%
% This sub-module exposes no API.
%
% \end{documentation}
%
% \begin{implementation}
%
% \section{\pkg{siunitx-symbol} implementation}
%
% Start the \pkg{DocStrip} guards.
% \begin{macrocode}
%<*package>
% \end{macrocode}
%
% Identify the internal prefix.
% \begin{macrocode}
%<@@=siunitx_symbol>
% \end{macrocode}
%
% \begin{variable}{\l_@@_tmpa_tl, \l_@@_tmpb_tl}
% Scratch space.
% \begin{macrocode}
\tl_new:N \l_@@_tmpa_tl
\tl_new:N \l_@@_tmpb_tl
% \end{macrocode}
% \end{variable}
%
% A small number of commands are needed from the companion fonts when working
% with $8$-bit engines. These are loaded by modern \LaTeXe{} kernel, so for
% older ones, force loading them using \pkg{textcomp}.
% \begin{macrocode}
\AtBeginDocument
{
\cs_if_free:cT { T@TS1 }
{ \RequirePackage { textcomp } }
}
% \end{macrocode}
%
% \begin{macro}{\@@_non_latin:n}
% A shortcut.
% \begin{macrocode}
\cs_new:Npn \@@_non_latin:n #1
{ \codepoint_generate:nn {#1} { \char_value_catcode:n {#1} } }
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@@_if_replace:NnT}
% A test to see if the unit definition which applies is still one we expect:
% here that means it is just using a (Unicode) codepoint. The comparison
% is string-based as \pkg{unicode-math} (at least) can alter some of them.
% Active characters are set to \cs{scan_stop:} so that the code here gives
% exactly the tokens (bytes) we want: needed for encodings other than
% \textsc{utf}-8.
% \begin{macrocode}
\prg_new_protected_conditional:Npnn \@@_if_replace:Nn #1#2 { T , TF }
{
\group_begin:
\protected@edef \l_@@_tmpa_tl
{ \exp_not:V \l_siunitx_unit_font_tl { \@@_non_latin:n {#2} } }
\int_step_inline:nnn { "80 } { "FF }
{ \char_set_active_eq:nN {##1} \scan_stop: }
\keys_set:nn { siunitx } { parse-units = false }
\siunitx_unit_format:nN {#1} \l_@@_tmpb_tl
\str_if_eq:VVTF \l_@@_tmpa_tl \l_@@_tmpb_tl
{
\group_end:
\prg_return_true:
}
{
\group_end:
\prg_return_false:
}
}
% \end{macrocode}
% \end{macro}
%
% At the start of the document, fonts are fixed and the user may have
% altered unit set up. If things are unchanged, we can alter the settings
% such that they use something \enquote{more sensible}.
% \begin{macrocode}
\AtBeginDocument
{
\@@_if_replace:NnT \arcminute { "02B9 }
{
\siunitx_declare_unit:Nnn \arcminute
{ \ensuremath { { } ' } }
{ quantity-product = { } }
}
\@@_if_replace:NnT \arcsecond { "02BA }
{
\siunitx_declare_unit:Nnn \arcsecond
{ \ensuremath { { } '' } }
{ quantity-product = { } }
}
% \end{macrocode}
% For |\degree|, direct input works in text mode so there is only a need to
% tidy up for math mode.
% \begin{macrocode}
\@@_if_replace:NnT \degree { "00B0 }
{
\siunitx_declare_unit:Nen \degree
{
\exp_not:N \TextOrMath
{
\@ifpackageloaded { inputenc }
{ \exp_not:N \textdegree }
{ \@@_non_latin:n { "00B0 } }
}
{
\@ifpackageloaded { unicode-math }
{ \@@_non_latin:n { "00B0 } }
{ { } ^ { \exp_not:N \circ } }
}
}
{ quantity-product = { } }
}
% \end{macrocode}
% For |\degreeCelsius|, much the same to think about but the comparison
% must be done by hand.
% \begin{macrocode}
\group_begin:
\tl_set:Nx \l_@@_tmpa_tl { \@@_non_latin:n { "00B0 } C }
\protected@edef \l_@@_tmpa_tl
{ \exp_not:V \l_siunitx_unit_font_tl { \l_@@_tmpa_tl } }
\keys_set:nn { siunitx } { parse-units = false }
\siunitx_unit_format:nN { \degreeCelsius } \l_@@_tmpb_tl
\str_if_eq:VVTF \l_@@_tmpa_tl \l_@@_tmpb_tl
{
\group_end:
\siunitx_declare_unit:Ne \degreeCelsius
{
\exp_not:N \TextOrMath
{
\@ifpackageloaded { inputenc }
{ \exp_not:N \textdegree }
{ \@@_non_latin:n { "00B0 } }
}
{
\@ifpackageloaded { unicode-math }
{ \@@_non_latin:n { "00B0 } }
{ { } ^ { \exp_not:N \circ } }
}
C
}
}
{ \group_end: }
% \end{macrocode}
% For |\ohm|, there is a math mode symbol we can use, so there has to be
% a mode-dependent definition. This doesn't work if the text mode symbol is
% bust: the \pkg{fourier} package puts us in that position.
% \begin{macrocode}
\@@_if_replace:NnT \ohm { "2126 }
{
\tl_set:Nx \l_@@_tmpa_tl
{
\cs_if_exist:NTF \upOmega
{ \exp_not:N \upOmega }
{ \exp_not:N \Omega }
}
\tl_set:Nx \l_@@_tmpb_tl
{
\exp_not:N \text
{ \exp_not:N \ensuremath { \exp_not:V \l_@@_tmpa_tl } }
}
\siunitx_declare_unit:Ne \ohm
{
\@ifpackageloaded { fourier }
{
\exp_not:N \ensuremath
{ \exp_not:V \l_@@_tmpa_tl }
}
{
\exp_not:N \TextOrMath
{
\bool_lazy_or:nnTF
{ \sys_if_engine_luatex_p: }
{ \sys_if_engine_xetex_p: }
{ \@@_non_latin:n { "2126 } }
{ \exp_not:N \textohm }
}
{
\@ifpackageloaded { fontspec }
{ \exp_not:V \l_@@_tmpb_tl }
{
\bool_lazy_any:nTF
{
{
\@ifclassloaded { beamer }
\c_true_bool
\c_false_bool
}
{
\@ifpackageloaded { kmath }
\c_true_bool
\c_false_bool
}
{
\@ifpackageloaded { mathastext }
\c_true_bool
\c_false_bool
}
}
{ \exp_not:V \l_@@_tmpb_tl }
{ \exp_not:V \l_@@_tmpa_tl }
}
}
}
}
}
% \end{macrocode}
% Only a text mode command is available for |\micro| in the standard
% set up.
% \begin{macrocode}
\@@_if_replace:NnT \micro { "03BC }
{
\siunitx_declare_prefix:Nne \micro { -6 }
{
\exp_not:N \text
{
\bool_lazy_or:nnTF
{ \sys_if_engine_luatex_p: }
{ \sys_if_engine_xetex_p: }
{ \@@_non_latin:n { "00B5 } }
{ \exp_not:N \textmu }
}
}
}
}
% \end{macrocode}
%
% As \pkg{uinicode-math} does stuff at the start of the document,
% \pkg{siunitx} needs to come after. As the former has two separate
% files internally, two rules are needed.
% \begin{macrocode}
\DeclareHookRule { begindocument } { siunitx } { after }
{ unicode-math-luatex }
\DeclareHookRule { begindocument } { siunitx } { after }
{ unicode-math-xetex }
% \end{macrocode}
%
% \subsection{Bookmark definitions}
%
% Inside PDF strings we disable the text printing function. The definition of
% |\ohm| is also reset as otherwise engine-dependent strings are generated
% (\XeTeX{} and \LuaTeX{} give different outcomes using for example
% |\textohm|).
% \begin{macrocode}
\AtBeginDocument
{
\@ifpackageloaded { hyperref }
{
\ExpandArgs { e } \pdfstringdefDisableCommands
{
\cs_set_eq:NN \siunitx_print_text:n \exp_not:N \use:n
\siunitx_declare_unit:Nn \exp_not:N \ohm
{ \@@_non_latin:n { "03A9 } }
}
}
{ }
}
% \end{macrocode}
%
% \begin{macrocode}
%</package>
% \end{macrocode}
%
% \end{implementation}
%
% \PrintIndex