Debian Codegraph @

texmf-dist/source/latex/siunitx/siunitx-symbol.dtx

raw
1 % \iffalse meta-comment
2 %
3 % File: siunitx-symbol.dtx Copyright (C) 2018-2026 Joseph Wright
4 %
5 % It may be distributed and/or modified under the conditions of the
6 % LaTeX Project Public License (LPPL), either version 1.3c of this
7 % license or (at your option) any later version. The latest version
8 % of this license is in the file
9 %
10 % https://www.latex-project.org/lppl.txt
11 %
12 % This file is part of the "siunitx bundle" (The Work in LPPL)
13 % and all files in that bundle must be distributed together.
14 %
15 % The released version of this bundle is available from CTAN.
16 %
17 % -----------------------------------------------------------------------
18 %
19 % The development version of the bundle can be found at
20 %
21 % https://github.com/josephwright/siunitx
22 %
23 % for those people who are interested.
24 %
25 % -----------------------------------------------------------------------
26 %
27 %<*driver>
28 \documentclass{l3doc}
29 % Additional commands needed in this source
30 \ProvideDocumentCommand\email{m}{\href{mailto:#1}{\nolinkurl{#1}}}
31 % The next line is needed so that \GetFileInfo will be able to pick up
32 % version data
33 \usepackage{siunitx}
34 \begin{document}
35 \DocInput{\jobname.dtx}
36 \end{document}
37 %</driver>
38 % \fi
39 %
40 % \GetFileInfo{siunitx.sty}
41 %
42 % \title{^^A
43 % \pkg{siunitx-symbol} -- Symbol-related settings^^A
44 % \thanks{This file describes \fileversion,
45 % last revised \filedate.}^^A
46 % }
47 %
48 % \author{^^A
49 % Joseph Wright^^A
50 % \thanks{^^A
51 % E-mail:
52 % \email{[email protected]}^^A
53 % }^^A
54 % }
55 %
56 % \date{Released \filedate}
57 %
58 % \maketitle
59 %
60 % \begin{documentation}
61 %
62 % This sub-module exposes no API.
63 %
64 % \end{documentation}
65 %
66 % \begin{implementation}
67 %
68 % \section{\pkg{siunitx-symbol} implementation}
69 %
70 % Start the \pkg{DocStrip} guards.
71 % \begin{macrocode}
72 %<*package>
73 % \end{macrocode}
74 %
75 % Identify the internal prefix.
76 % \begin{macrocode}
77 %<@@=siunitx_symbol>
78 % \end{macrocode}
79 %
80 % \begin{variable}{\l_@@_tmpa_tl, \l_@@_tmpb_tl}
81 % Scratch space.
82 % \begin{macrocode}
83 \tl_new:N \l_@@_tmpa_tl
84 \tl_new:N \l_@@_tmpb_tl
85 % \end{macrocode}
86 % \end{variable}
87 %
88 % A small number of commands are needed from the companion fonts when working
89 % with $8$-bit engines. These are loaded by modern \LaTeXe{} kernel, so for
90 % older ones, force loading them using \pkg{textcomp}.
91 % \begin{macrocode}
92 \AtBeginDocument
93 {
94 \cs_if_free:cT { T@TS1 }
95 { \RequirePackage { textcomp } }
96 }
97 % \end{macrocode}
98 %
99 % \begin{macro}{\@@_non_latin:n}
100 % A shortcut.
101 % \begin{macrocode}
102 \cs_new:Npn \@@_non_latin:n #1
103 { \codepoint_generate:nn {#1} { \char_value_catcode:n {#1} } }
104 % \end{macrocode}
105 % \end{macro}
106 %
107 % \begin{macro}{\@@_if_replace:NnT}
108 % A test to see if the unit definition which applies is still one we expect:
109 % here that means it is just using a (Unicode) codepoint. The comparison
110 % is string-based as \pkg{unicode-math} (at least) can alter some of them.
111 % Active characters are set to \cs{scan_stop:} so that the code here gives
112 % exactly the tokens (bytes) we want: needed for encodings other than
113 % \textsc{utf}-8.
114 % \begin{macrocode}
115 \prg_new_protected_conditional:Npnn \@@_if_replace:Nn #1#2 { T }
116 {
117 \group_begin:
118 \protected@edef \l_@@_tmpa_tl
119 { \exp_not:V \l_siunitx_unit_font_tl { \@@_non_latin:n {#2} } }
120 \int_step_inline:nnn { "80 } { "FF }
121 { \char_set_active_eq:nN {##1} \scan_stop: }
122 \keys_set:nn { siunitx } { parse-units = false }
123 \siunitx_unit_format:nN {#1} \l_@@_tmpb_tl
124 \str_if_eq:VVTF \l_@@_tmpa_tl \l_@@_tmpb_tl
125 {
126 \group_end:
127 \prg_return_true:
128 }
129 {
130 \group_end:
131 \prg_return_false:
132 }
133 }
134 % \end{macrocode}
135 % \end{macro}
136 %
137 % At the start of the document, fonts are fixed and the user may have
138 % altered unit set up. If things are unchanged, we can alter the settings
139 % such that they use something \enquote{more sensible}.
140 % \begin{macrocode}
141 \AtBeginDocument
142 {
143 \@@_if_replace:NnT \arcminute { "02B9 }
144 {
145 \siunitx_declare_unit:Nnn \arcminute
146 { \ensuremath { { } ' } }
147 { prefix-mode = input , quantity-product = { } }
148 }
149 \@@_if_replace:NnT \arcsecond { "02BA }
150 {
151 \siunitx_declare_unit:Nnn \arcsecond
152 { \ensuremath { { } '' } }
153 { prefix-mode = input , quantity-product = { } }
154 }
155 % \end{macrocode}
156 % For |\degree|, direct input works in text mode so there is only a need to
157 % tidy up for math mode.
158 % \begin{macrocode}
159 \@@_if_replace:NnT \degree { "00B0 }
160 {
161 \siunitx_declare_unit:Nen \degree
162 {
163 \exp_not:N \TextOrMath
164 {
165 \@ifpackageloaded { inputenc }
166 { \exp_not:N \textdegree }
167 { \@@_non_latin:n { "00B0 } }
168 }
169 {
170 \@ifpackageloaded { unicode-math }
171 { \@@_non_latin:n { "00B0 } }
172 { { } ^ { \exp_not:N \circ } }
173 }
174 }
175 { prefix-mode = input , quantity-product = { } }
176 }
177 % \end{macrocode}
178 % For |\degreeCelsius|, much the same to think about but the comparison
179 % must be done by hand.
180 % \begin{macrocode}
181 \group_begin:
182 \tl_set:Ne \l_@@_tmpa_tl { \@@_non_latin:n { "00B0 } C }
183 \protected@edef \l_@@_tmpa_tl
184 { \exp_not:V \l_siunitx_unit_font_tl { \l_@@_tmpa_tl } }
185 \keys_set:nn { siunitx } { parse-units = false }
186 \siunitx_unit_format:nN { \degreeCelsius } \l_@@_tmpb_tl
187 \str_if_eq:VVTF \l_@@_tmpa_tl \l_@@_tmpb_tl
188 {
189 \group_end:
190 \siunitx_declare_unit:Ne \degreeCelsius
191 {
192 \exp_not:N \TextOrMath
193 {
194 \@ifpackageloaded { inputenc }
195 { \exp_not:N \textdegree }
196 { \@@_non_latin:n { "00B0 } }
197 }
198 {
199 \@ifpackageloaded { unicode-math }
200 { \@@_non_latin:n { "00B0 } }
201 { { } ^ { \exp_not:N \circ } }
202 }
203 C
204 }
205 }
206 { \group_end: }
207 % \end{macrocode}
208 % For |\ohm|, there is a math mode symbol we can use, so there has to be
209 % a mode-dependent definition. This doesn't work if the text mode symbol is
210 % bust: the \pkg{fourier} package puts us in that position.
211 % \begin{macrocode}
212 \@@_if_replace:NnT \ohm { "2126 }
213 {
214 \tl_set:Ne \l_@@_tmpa_tl
215 {
216 \cs_if_exist:NTF \upOmega
217 { \exp_not:N \upOmega }
218 { \exp_not:N \Omega }
219 }
220 \tl_set:Ne \l_@@_tmpb_tl
221 {
222 \exp_not:N \text
223 { \exp_not:N \ensuremath { \exp_not:V \l_@@_tmpa_tl } }
224 }
225 \siunitx_declare_unit:Ne \ohm
226 {
227 \@ifpackageloaded { fourier }
228 {
229 \exp_not:N \ensuremath
230 { \exp_not:V \l_@@_tmpa_tl }
231 }
232 {
233 \exp_not:N \TextOrMath
234 {
235 \bool_lazy_or:nnTF
236 { \sys_if_engine_luatex_p: }
237 { \sys_if_engine_xetex_p: }
238 { \@@_non_latin:n { "2126 } }
239 { \exp_not:N \textohm }
240 }
241 {
242 \@ifpackageloaded { fontspec }
243 { \exp_not:V \l_@@_tmpb_tl }
244 {
245 \bool_lazy_any:nTF
246 {
247 {
248 \@ifclassloaded { beamer }
249 \c_true_bool
250 \c_false_bool
251 }
252 {
253 \@ifpackageloaded { kmath }
254 \c_true_bool
255 \c_false_bool
256 }
257 {
258 \@ifpackageloaded { mathastext }
259 \c_true_bool
260 \c_false_bool
261 }
262 }
263 { \exp_not:V \l_@@_tmpb_tl }
264 { \exp_not:V \l_@@_tmpa_tl }
265 }
266 }
267 }
268 }
269 }
270 % \end{macrocode}
271 % Only a text mode command is available for |\micro| in the standard
272 % set up.
273 % \begin{macrocode}
274 \@@_if_replace:NnT \micro { "03BC }
275 {
276 \siunitx_declare_prefix:Nne \micro { -6 }
277 {
278 \exp_not:N \text
279 {
280 \bool_lazy_or:nnTF
281 { \sys_if_engine_luatex_p: }
282 { \sys_if_engine_xetex_p: }
283 { \@@_non_latin:n { "00B5 } }
284 { \exp_not:N \textmu }
285 }
286 }
287 }
288 }
289 % \end{macrocode}
290 %
291 % As \pkg{uinicode-math} does stuff at the start of the document,
292 % \pkg{siunitx} needs to come after. As the former has two separate
293 % files internally, two rules are needed.
294 % \begin{macrocode}
295 \DeclareHookRule { begindocument } { siunitx } { after }
296 { unicode-math-luatex }
297 \DeclareHookRule { begindocument } { siunitx } { after }
298 { unicode-math-xetex }
299 % \end{macrocode}
300 %
301 % \subsection{Bookmark definitions}
302 %
303 % Inside PDF strings we disable the text printing function. The definition of
304 % |\ohm| is also reset as otherwise engine-dependent strings are generated
305 % (\XeTeX{} and \LuaTeX{} give different outcomes using for example
306 % |\textohm|).
307 % \begin{macrocode}
308 \AtBeginDocument
309 {
310 \@ifpackageloaded { hyperref }
311 {
312 \ExpandArgs { e } \pdfstringdefDisableCommands
313 {
314 \cs_set_eq:NN \siunitx_print_text:n \exp_not:N \use:n
315 \siunitx_declare_unit:Nn \exp_not:N \ohm
316 { \@@_non_latin:n { "03A9 } }
317 }
318 }
319 { }
320 }
321 % \end{macrocode}
322 %
323 % \begin{macrocode}
324 %</package>
325 % \end{macrocode}
326 %
327 % \end{implementation}
328 %
329 % \PrintIndex