blob: 2e4495e82dace21e0ab39d2fdcb28f686c171d22 (
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
|
%D \module
%D [ file=m-dimensions,
%D version=1997.03.19,
%D title=\CONTEXT\ Extra Modules,
%D subtitle=Scientific Units,
%D author={Hans Hagen},
%D date=\currentdate,
%D copyright={PRAGMA ADE \& \CONTEXT\ Development Team}]
%C
%C This module is part of the \CONTEXT\ macro||package and is
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.
\unprotect
\registerctxluafile{m-dimensions}{}
\startmodule[dimensions]
%D \macros
%D {su}
%D
%D We have been using the units module (and its predecessor) for over a decade
%D now but when we moved on to \LUATEX\ a variant was prototyped that permits a
%D less texie coding. I finally picked up that thread and cleaned up the code a
%D bit so users can now play with it. (The main reason was that I wanted to
%D test exporting.)
%D
%D \startbuffer
%D \su{10 km/h}
%D 10\su{km/h}
%D 10 \su{km/h}
%D $10\su{km/h}$
%D $10 \su{km/h}$
%D 10 \su{KiloMeter/Hour}
%D 10 \su{kilometer/hour}
%D 10 \su{km/h}
%D 10 \su{kilometer per hour}
%D 10 \su{km / h}
%D 10 \su{ km / h }
%D 10 \su{km/ms2}
%D 10 \su{meter per second}
%D 10 \su{cubic meter}
%D 10 \su{cubic meter per second}
%D 10 \su{cubic meter / second}
%D $10 \su{cubic meter / second}$
%D 30 \su{kilo pascal }
%D 30 \su{kilo pascal square meter / second}
%D 30 \su{kilo pascal square meter / second kelvin}
%D 30 \su{crap}
%D $ \frac{10 \su{m/s}}{20 \su{m/s}} $
%D \stopbuffer
%D
%D \typebuffer
%D
%D Result: \getbuffer
\newconstant \c_scientificunit_mode % 0=text 1=math
\newconstant \c_scientificunit_state % 0=start 1=suffix 2=operator 3=unit 4=prefix 5=number
\newconditional\c_scientificunit_number
% tags and export
% smash == snapper
% hbox ook in mmode
\def\scientificunithalfspace{\thinspace}
\def\scientificunitbackspace{\negthinspace}
\newtoks \everyscientificunit % we keep the old \units command so we need a longer one
\unexpanded\def\scientificunit#1%
{\begingroup
\the\everyscientificunit
\removeunwantedspaces
\ifmmode
\c_scientificunit_mode\plusone
\rm\tf
\mathtf
\fi
\scientificunit_indeed{#1}%
\scientificunit_finish
\endgroup}
\appendtoks
\let\scientificunit\scientificunit_indeed
\to \everyscientificunit
\let\su\scientificunit
\appendtoks
\let\su\scientificunit_indeed
\to \everyscientificunit
\unexpanded\def\scientificunit_indeed#1{\ctxcommand{scientificunit(\!!bs#1\!!es)}}
\unexpanded\def\scientificunitPUS#1#2#3{\scientificunit_next#1#2\scientificunitraise{#3}\c_scientificunit_state\plusone} % suffix
\unexpanded\def\scientificunitPU #1#2{\scientificunit_next#1#2\c_scientificunit_state \plusthree} % unit
\unexpanded\def\scientificunitPS #1#2{\scientificunit_next#1\scientificunitraise{#2}\c_scientificunit_state \plusone} % suffix
\unexpanded\def\scientificunitUS #1#2{\scientificunit_next#1\scientificunitraise{#2}\c_scientificunit_state \plusone} % suffix
\unexpanded\def\scientificunitP #1{\scientificunit_next#1\c_scientificunit_state \plusfour} % prefix
\unexpanded\def\scientificunitU #1{\scientificunit_next#1\c_scientificunit_state \plusthree} % unit
\unexpanded\def\scientificunitS #1{\scientificunit_start{}\scientificunitraise{#1}\c_scientificunit_state \plusone} % suffix
\unexpanded\def\scientificunitO #1{\scientificunit_start#1\c_scientificunit_state \plustwo} % operator
\unexpanded\def\scientificunitN #1{\scientificunit_start#1\c_scientificunit_state \plusfive} % number
\setelementnature[unit] [mixed]
\setelementnature[quantity][mixed]
\unexpanded\def\scientificunitN#1%
{\ifmmode
#1%
\else
\dostarttagged{quantity}\empty
\dostarttagged{number}\empty
#1%
\dostoptagged
\settrue\c_scientificunit_number
\fi
%\scientificunit_start
\c_scientificunit_state\plusfive}
\def\scientificunit_start
{\ifmmode
\dostarttagged\t!mathaction{unit}%
\bgroup % make an mrow
\else
\dostarttagged{unit}\empty
\fi
\let\scientificunit_finish\scientificunit_stop
\let\scientificunit_start\relax}
\def\scientificunit_stop
{\ifmmode
\egroup
\fi
\ifconditional\c_scientificunit_number
\dostoptagged
\fi
\dostoptagged}
\def\scientificunitraise
{\ifnum\c_scientificunit_mode=\plusone
\expandafter\normalsuperscript
\else
\expandafter\high
\fi}
\def\scientificunitlower
{\ifnum\c_scientificunit_mode=\plusone
\expandafter\normalsubscript
\else
\expandafter\low
\fi}
\unexpanded\def\scientificunit_next
{\ifcase\c_scientificunit_state % start
\scientificunithalfspace
\scientificunithalfspace
\or % suffix
{\cdot}% \scientificunithalfspace
\or % operator
\or % unit
{\cdot}% \scientificunithalfspace
\or % prefix
\or % number
\scientificunithalfspace
\scientificunithalfspace
\fi
\scientificunit_start}
\unexpanded\def\scientificunitTIMES
{\ifnum\c_scientificunit_state=\plusone % suffix
\else
\scientificunithalfspace
\fi
\cdot} % or \times
\unexpanded\def\scientificunitOUTOF
{\ifnum\c_scientificunit_state=\plusone % suffix
\else
\scientificunithalfspace
\fi
:}
\unexpanded\def\scientificunitSOLIDUS
{\ifnum\c_scientificunit_state=\plusone % suffix
\scientificunitbackspace
\fi
{/}%
}%\scientificunitbackspace}
\stopmodule
\protect \endinput
|