summaryrefslogtreecommitdiff
path: root/tex/context/base/phys-dim.mkiv
blob: 4df9d3ad908938e56c2ceb18a2347f0a327df756 (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
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
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
%D \module
%D   [       file=phys-dim,
%D        version=2011-06-13, % was digits and units 1997.03.19,
%D          title=\CONTEXT\ Physics,
%D       subtitle=Digits and 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.

\registerctxluafile{phys-dim}{}

\unprotect

%D \macros
%D   {digits, setdigitmode, setdigitsign}
%D
%D This is an update of the \MKII\ digits mechanism. Beware,
%D space delimited mode is now resticted!
%D
%D Depending on the digit mode the command \type {\digits}
%D normalizes number patterns depending on the language set.
%D
%D \starttyping
%D This will never be a \digits{1.000.000} seller.
%D \stoptyping
%D
%D We still support the space delimited case but this is only for special
%D purposes. When used in the text, you'd better use the argument variant.
%D
%D \startbuffer
%D 1 \setdigitmode {1} \setdigitorder{0} \digits {12.345,90}
%D 2 \setdigitmode {2} \setdigitorder{0} \digits {12.345,90}
%D 3 \setdigitmode {3} \setdigitorder{0} \digits {12.345,90}
%D 4 \setdigitmode {4} \setdigitorder{0} \digits {12.345,90}
%D 5 \setdigitmode {5} \setdigitorder{0} \digits {12.345,90}
%D 6 \setdigitmode {6} \setdigitorder{0} \digits {12.345,90}
%D 1 \setdigitmode {1} \setdigitorder{1} \digits {12.345,90}
%D 2 \setdigitmode {2} \setdigitorder{1} \digits {12.345,90}
%D 3 \setdigitmode {3} \setdigitorder{1} \digits {12.345,90}
%D 4 \setdigitmode {4} \setdigitorder{1} \digits {12.345,90}
%D 5 \setdigitmode {5} \setdigitorder{1} \digits {12.345,90}
%D 6 \setdigitmode {6} \setdigitorder{1} \digits {12.345,90}
%D \stopbuffer
%D
%D \typebuffer
%D
%D This is typeset as:
%D
%D \startlines \getbuffer \stoplines
%D
%D The sign can be typeset as is or within the space of a
%D digit.
%D
%D \startbuffer
%D \setdigitsign 0 \digits {+12.345,90}
%D \setdigitsign 1 \digits {+12.345,90}
%D \stopbuffer
%D
%D \typebuffer
%D
%D This is typset as:
%D
%D \startlines
%D \getbuffer
%D \stoplines
%D
%D The digit modes are:
%D
%D \startitemize[n,packed]
%D \item periods/comma
%D \item commas/period
%D \item thinmuskips/comma
%D \item thinmuskips/period
%D \item thickmuskips/comma
%D \item thickmuskips/period
%D \stopitemize
%D
%D The digit parser handles a bunch of special characters as
%D well as different formats. We strongly suggest you to use
%D the grouped call.
%D
%D \starttabulate[|l|l|l|]
%D \NC \type{.} \NC , .           \NC comma or period            \NC \NR
%D \NC \type{,} \NC , .           \NC comma or period            \NC \NR
%D \NC \type{@} \NC               \NC invisible space            \NC \NR
%D \NC \type{_} \NC               \NC invisible space            \NC \NR
%D \NC \type{/} \NC               \NC invisible sign             \NC \NR
%D \NC \type{-} \NC $-$           \NC minus sign                 \NC \NR
%D \NC \type{+} \NC $+$           \NC plus sign                  \NC \NR
%D \NC \type{s} \NC               \NC invisible high sign        \NC \NR
%D \NC \type{p} \NC $\positive$   \NC high plus sign             \NC \NR
%D \NC \type{m} \NC $\negative$   \NC high minus sign            \NC \NR
%D \NC \type{n} \NC $\negative$   \NC high minus (negative) sign \NC \NR
%D \NC \type{=} \NC $\zeroamount$ \NC zero padding               \NC \NR
%D \stoptabulate
%D
%D These triggers are used in the following examples.
%D
%D \startbuffer
%D \digits{12}
%D \digits{~~~.~~~.~~~.68.712,34}
%D \digits{___.___.111.68.712,34}
%D \digits{111.111.111.68.712,34}
%D \digits{12.345,90}
%D \digits{12.345.000}
%D \digits{12,34}
%D \digits{392.857.230.68.712,34}
%D \digits{1234}
%D \digits{123.222,00}
%D \digits{123.222,==}
%D \digits{123.222,00^10}
%D \digits{123.222,00e10}
%D \digits{/123.222,00e-12}
%D \digits{-123.222,00e-12}
%D \digits{+123.222,00e-12}
%D \digits{n123.222,00e-12}
%D \digits{s123.222,00e-12}
%D \digits{p123.222,00e-12}
%D \stopbuffer
%D
%D \typebuffer
%D
%D \startlines
%D \getbuffer
%D \stoplines

\newconstant\c_digits_order
\newconstant\c_digits_method
\newconstant\c_digits_sign  % we has sized (text script scriptscript)

\def\setdigitmethod#1{\c_digits_method #1\relax}
\def\setdigitsign  #1{\c_digits_sign   #1\relax}
\def\setdigitorder #1{\c_digits_order  #1\relax}

\let\setdigitmode\setdigitmethod % compatibility

\def\digits_normalized % we could calculate once and remember
  {\ifcase\c_digits_sign
     \expandafter\secondoftwoarguments
   \else\ifmmode
     \expandafter\expandafter\expandafter\digits_normalized_math
   \else
     \expandafter\expandafter\expandafter\digits_normalized_text
   \fi\fi}

\def\digits_normalized_math#1#2%
  {\setbox\scratchbox\hbox{$\Ustack{#1}$}%
   \hbox to \wd\scratchbox{\hss{$\Ustack{#2}$}\hss}}

\def\digits_normalized_text#1#2%
  {\setbox\scratchbox\hbox{#1}%
   \hbox to \wd\scratchbox{\hss#2\hss}}

\def\digits_raised
  {\ifmmode
     \expandafter\normalsuperscript
   \else
     \expandafter\high
   \fi}

\def\digitszeropadding   {\zeroamount}
\def\digitsnegative      {\digits_normalized{0}{\digits_raised{\textminus}}}
\def\digitspositive      {\digits_normalized{0}{\digits_raised{\textplus}}}
\def\digitsnegative      {\digits_normalized{0}{\mathematics{\negative}}}
\def\digitspositive      {\digits_normalized{0}{\mathematics{\positive}}}
\def\digitsminus         {\digits_normalized{0}{\mathematics{-}}}
\def\digitsplus          {\digits_normalized{0}{\mathematics{+}}}
\def\digitsspace         {\hphantom{0}}
\def\digitsseparatorspace{\hphantom{.}}
\def\digitssignspace     {\hphantom{\digitsminus}}
\def\digitshighspace     {\hphantom{\digitspositive}}
\def\digitspower         {\digits_raised}
\def\digitspowerplus   #1{\digits_raised{\digitsplus#1}}
\def\digitspowerminus  #1{\digits_raised{\digitsminus#1}}
\def\digitsdigit       #1{#1}

\def\normaldigitscommasymbol   {,}
\def\normaldigitsperiodsymbol  {.}
\let\normaldigitsseparatorspace\digitsseparatorspace

\letvalue{digit_c_0}\normaldigitscommasymbol
\letvalue{digit_p_0}\normaldigitsperiodsymbol
\letvalue{digit_s_0}\normaldigitsseparatorspace

\letvalue{digit_c_1}\normaldigitsperiodsymbol
\letvalue{digit_p_1}\normaldigitscommasymbol
\letvalue{digit_s_1}\normaldigitsseparatorspace

\letvalue{digit_c_2}\normaldigitscommasymbol
\letvalue{digit_p_2}\normaldigitsperiodsymbol
\letvalue{digit_s_2}\normaldigitsseparatorspace

\letvalue{digit_c_3}\thinspace
\letvalue{digit_p_3}\normaldigitscommasymbol
\letvalue{digit_s_3}\thinspace

\letvalue{digit_c_4}\thinspace
\letvalue{digit_p_4}\normaldigitsperiodsymbol
\letvalue{digit_s_4}\thinspace

\letvalue{digit_c_5}\thickspace
\letvalue{digit_p_5}\normaldigitscommasymbol
\letvalue{digit_s_5}\thickspace

\letvalue{digit_c_6}\thickspace
\letvalue{digit_p_6}\normaldigitsperiodsymbol
\letvalue{digit_s_6}\thickspace

\def\digitscommasymbol         {\csname digit_c_\number\c_digits_method\endcsname}
\def\digitsperiodsymbol        {\csname digit_p_\number\c_digits_method\endcsname}
\def\digitsseparatorspace      {\csname digit_s_\number\c_digits_method\endcsname}

\def\digitsfinalcomma          {\digitscommasymbol } % more for tracing
\def\digitsfinalperiod         {\digitsperiodsymbol} % more for tracing
\def\digitsintermediatecomma   {\digitscommasymbol } % more for tracing
\def\digitsintermediateperiod  {\digitsperiodsymbol} % more for tracing

%D The user macro:

\unexpanded\def\digits_indeed#1%
  {\dontleavehmode
   \begingroup
   \ctxcommand{digits(\!!bs\detokenize{#1}\!!es,"\ifcase\c_digits_order \v!normal\else\v!reverse\fi")}%
   \endgroup
   \settrue\c_units_dospace}

\unexpanded\def\digits
  {\doifnextbgroupelse\digits_argument\digits_spaced}

\def\digits_argument#1%
  {\digits_indeed{#1}}

\def\digits_spaced#1 % space delimited
  {\digits_indeed{#1}}

%D \macros
%D   {unit}
%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 01: $10\unit{km/h}$
%D 02: $\unit{10      km/h}$
%D 03: \unit{km/h}
%D 04: \unit{10 km/h}
%D 05: \unit{10 km/h}
%D 06: \unit{~1 km/h}
%D 07: 10\unit{km/h}
%D 08: 10 \unit{km/h}
%D 09: $10 \unit{km/h}$
%D 10: 10 \unit{KiloMeter/Hour}
%D 11: 10 \unit{kilometer/hour}
%D 12: 10 \unit{km/h}
%D 13: 10 \unit{kilometer per hour}
%D 14: 10 \unit{km / h}
%D 15: 10 \unit{ km / h }
%D 16: 10 \unit{km/ms2}
%D 17: 10 \unit{meter per second}
%D 18: 10 \unit{cubic meter}
%D 19: 10 \unit{cubic meter per second}
%D 21: 10 \unit{cubic meter / second}
%D 22: $10 \unit{cubic meter / second}$
%D 23: 30 \unit{kilo pascal }
%D 24: 30 \unit{kilo pascal square meter / second}
%D 25: 30 \unit{kilo pascal square meter / kelvin second}
%D 26: \unit{30 kilo pascal square meter / kelvin second}
%D 27: $30 \unit{kilo pascal square meter / kelvin second }$
%D 28: 30 \unit{crap}
%D 29: 30 \unit{AC}
%D 30: $\frac{10 \unit{m/s}}{20 \unit{m/s}} $
%D 31: {\ss 30 \unit{kilo pascal square meter / second kelvin}}
%D 32: \unit{123.22^-3 km/s}
%D 33: \unit{123.22e-3 km/s}
%D \stopbuffer
%D
%D \typebuffer
%D
%D Result: \startlines \getbuffer \stoplines
%D
%D Depending on needs we can add more tweaks (also depends on to what
%D extent we need to be compatible with \MKII.
%D
%D Formatting is supported too:
%D
%D \startbuffer
%D \starttabulate[|l|l|l|]
%D \HL
%D \NC \unit{10 kilo gram}       \NC \digits{10}        \NC \unit{10}        \NC \NR
%D \NC \unit{1 kilogram}         \NC \digits{1}         \NC \unit{1}         \NC \NR
%D \NC \unit{0.1 kilogram}       \NC \digits{0.1}       \NC \unit{0.1}       \NC \NR
%D \NC \unit{1.1 kilogram}       \NC \digits{1.1}       \NC \unit{1.1}       \NC \NR
%D \NC \unit{11 kilogram}        \NC \digits{11}        \NC \unit{11}        \NC \NR
%D \HL
%D \NC \unit{00,000.10 kilogram} \NC \digits{00,000.10} \NC \unit{00,000.10} \NC \NR
%D \NC \unit{@@,@@0.10 kilogram} \NC \digits{@@,@@0.10} \NC \unit{@@,@@0.10} \NC \NR
%D \NC \unit{__,___.10 kilogram} \NC \digits{__,___.10} \NC \unit{__,___.10} \NC \NR
%D \NC \unit{__,__0:10 kilogram} \NC \digits{__,__0:10} \NC \unit{__,__0:10} \NC \NR
%D \NC \unit{__,___:10 kilogram} \NC \digits{__,___:10} \NC \unit{__,___:10} \NC \NR
%D \HL
%D \stoptabulate
%D \stopbuffer
%D
%D \typebuffer \getbuffer
%D
%D Punctuation can be configures usiing \type {method}:
%D
%D \startbuffer
%D \starttabulate[|l|l|l|]
%D \HL
%D \NC   \NC \setupunits[method=0]\unit{00,000.10 kilogram} \NC \setupunits[method=0]\unit{@@,@@0.10 kilogram} \NC \NR
%D \NC 1 \NC \setupunits[method=1]\unit{00,000.10 kilogram} \NC \setupunits[method=1]\unit{@@,@@0.10 kilogram} \NC \NR
%D \NC 2 \NC \setupunits[method=2]\unit{00,000.10 kilogram} \NC \setupunits[method=2]\unit{@@,@@0.10 kilogram} \NC \NR
%D \NC 3 \NC \setupunits[method=3]\unit{00,000.10 kilogram} \NC \setupunits[method=3]\unit{@@,@@0.10 kilogram} \NC \NR
%D \NC 4 \NC \setupunits[method=4]\unit{00,000.10 kilogram} \NC \setupunits[method=4]\unit{@@,@@0.10 kilogram} \NC \NR
%D \NC 5 \NC \setupunits[method=5]\unit{00,000.10 kilogram} \NC \setupunits[method=5]\unit{@@,@@0.10 kilogram} \NC \NR
%D \NC 6 \NC \setupunits[method=6]\unit{00,000.10 kilogram} \NC \setupunits[method=6]\unit{@@,@@0.10 kilogram} \NC \NR
%D \HL
%D \stoptabulate
%D \stopbuffer
%D
%D \typebuffer \getbuffer

% only a space when a number is part of the unit

\installcommandhandler \??un {units} \??un

\setupunits
  [\c!alternative=,        % done: text
   \c!separator=\v!normal, % done: cdot|big|medium|space
   \c!label=,              % done: (no interface yet)
   \c!order=\v!normal,     % ,. (reverse: .,)
   \c!method=0,
  %\c!grid=\v!yes,         % (maybe)
  %\c!style=...,           % done
  %\c!color=...,           % done
  %\c!space=...,           % (maybe) small medium big
  ]

\newconstant   \c_units_mode   % 0=text 1=math 2=textinmath 3=mathintext
\newconstant   \c_units_state  % 0=start 1=suffix 2=operator 3=unit 4=prefix 5=number
\newconditional\c_units_quantity
\newconditional\c_units_number
\newconditional\c_units_dospace

% [\unit   {micro ohm}]\par %  no space before unit
% [10\unit {micro ohm}]\par %  no space before unit
% [10 \unit{micro ohm}]\par %     space before unit
% [ \unit  {micro ohm}]\par %     space before unit
% [\unit{10 micro ohm}]\par %     space before unit

\def\unitssmallspace {\thinspace}
\def\unitsmediumspace{\medspace}
\def\unitsbigspace   {\thickspace}
\def\unitsbackspace  {\negthinspace}

\def\installunitsseparator#1#2%
  {\setvalue{\??un::#1}{#2}}

\unexpanded\def\dounitsseparator
  {\edef\currentunitsseparator{\unitsparameter\c!separator}%
   \csname\??un::%
     \ifcsname\??un::\currentunitsseparator\endcsname\currentunitsseparator\else\v!normal\fi
   \endcsname}

\installunitsseparator\v!normal {\cdot}
\installunitsseparator\v!big    {\unitsbigspace}
\installunitsseparator\v!medium {\unitsmediumspace}
\installunitsseparator\v!small  {\unitssmallspace}
\installunitsseparator\v!none   {}

\newtoks \everyunits % we keep the old \units command so we need a longer one

\appendtoks
    \setuevalue\currentunits{\units_direct{\currentunits}}
\to \everydefineunits

\unexpanded\def\units_direct#1%
  {\begingroup
   \ifdim\lastskip>\zeropoint
     \settrue\c_units_dospace
     \removelastskip
   \fi
   \c_digits_method\unitsparameter\c!method\relax
   \ifmmode\else\dontleavehmode\fi
   \edef\currentunits{#1}%
   \the\everyunits
  %\removeunwantedspaces % now ok yet
   \dosetunitsattributes\c!style\c!color
   \edef\currentunitsalternative{\unitsparameter\c!alternative}%
   \ifmmode
     \ifx\currentunitsalternative\v!text
       \expandafter\expandafter\expandafter\units_direct_text_in_math
     \else
       \expandafter\expandafter\expandafter\units_direct_math
     \fi
   \else
     \ifx\currentunitsalternative\v!mathematics
       \expandafter\expandafter\expandafter\units_direct_math_in_text
     \else
       \expandafter\expandafter\expandafter\units_direct_text
     \fi
   \fi}

\unexpanded\def\units_direct_text_in_math#1%
  {\mathtext{%
     \c_units_mode\plustwo
     \units_indeed{#1}%
     \units_finish
   }%
   \endgroup}

\unexpanded\def\units_direct_math#1%
  {\c_units_mode\plusone
   \rm\tf
   \mathtf
   \units_indeed{#1}%
   \units_finish
   \endgroup}

\unexpanded\def\units_direct_text#1%
  {\units_indeed{#1}%
   \units_finish
   \endgroup}

\unexpanded\def\units_direct_math_in_text#1%
  {\removeunwantedspaces % brr
   \startimath
   \c_units_mode\plusthree
   \rm\tf
   \mathtf
   \units_indeed{#1}%
   \units_finish
   \stopimath
   \endgroup}

\unexpanded\def\units_direct_nested#1#2%
  {\units_indeed{#2}}

\appendtoks
    \let\units_direct\units_direct_nested
\to \everyunits

\unexpanded\def\units_indeed#1{\ctxcommand{unit(\!!bs\detokenize{#1}\!!es,"\unitsparameter\c!label","\unitsparameter\c!order")}}

\unexpanded\def\unitsPUS#1#2#3{\units_next#1#2\unitsraise{#3}\c_units_state\plusone}   % suffix
\unexpanded\def\unitsPU   #1#2{\units_next#1#2\c_units_state               \plusthree} % unit
\unexpanded\def\unitsPS   #1#2{\units_next#1\unitsraise{#2}\c_units_state  \plusone}   % suffix
\unexpanded\def\unitsUS   #1#2{\units_next#1\unitsraise{#2}\c_units_state  \plusone}   % suffix
\unexpanded\def\unitsP      #1{\units_next#1\c_units_state                 \plusfour}  % prefix
\unexpanded\def\unitsU      #1{\units_next#1\c_units_state                 \plusthree} % unit
\unexpanded\def\unitsS      #1{\units_start{}\unitsraise{#1}\c_units_state \plusone}   % suffix
\unexpanded\def\unitsO      #1{\units_start#1\c_units_state                \plustwo}   % operator
\unexpanded\def\unitsN      #1{\units_start#1\c_units_state                \plusfive}  % number

\setelementnature[unit]    [mixed]
\setelementnature[quantity][mixed]

\let\units_finish\relax

\unexpanded\def\unitsNstart
  {\ifmmode \else
     \settrue\c_units_quantity
     \dostarttagged\t!quantity\empty
     \settrue\c_units_number
     \dostarttagged\t!number\empty
   \fi}

\unexpanded\def\unitsNstop
  {\ifconditional\c_units_number
     \setfalse\c_units_number
     \dostoptagged
   \fi
   \c_units_state\plusfive}

\unexpanded\def\unitsN#1%
  {\unitsNstart#1\unitsNstop}

\def\units_start
  {\ifmmode
     \dostarttagged\t!mathaction\t!unit
     \bgroup % make an mrow
   \else
     \dostarttagged\t!unit\empty
   \fi
   \let\units_finish\units_stop
   \let\units_start\relax}

\def\units_stop
  {\ifconditional\c_units_number
     \setfalse\c_units_number
     \dostoptagged
   \fi
   \ifconditional\c_units_quantity
     \setfalse\c_units_quantity
     \dostoptagged
   \fi
   \dostoptagged
   \ifmmode
     \egroup
   \fi}

\def\unitsraise
  {\ifcase\c_units_mode
     \expandafter\high
   \or
     \expandafter\normalsuperscript
   \or
     \expandafter\high
   \or
     \expandafter\normalsuperscript
   \fi}

\def\unitslower
  {\ifcase\c_units_mode
     \expandafter\low
   \or
     \expandafter\normalsubscript
   \or
     \expandafter\low
   \or
     \expandafter\normalsubscript
   \fi}

\unexpanded\def\units_next
  {\ifcase\c_units_state % start
     \ifconditional\c_units_dospace
      % \ifdim\lastskip=\zeropoint
         \unitsbigspace
      % \else
      %   % too tricky ... we could remove and add
      % \fi
     \fi
   \or % suffix
     {\dounitsseparator}%
   \or % operator
   \or % unit
     {\dounitsseparator}%
   \or % prefix
   \or % number
     \unitsbigspace
   \fi
   \setfalse\c_units_dospace
   \units_start}

\unexpanded\def\unitsTIMES
  {\ifnum\c_units_state=\plusone % suffix
   \else
     \unitssmallspace
   \fi
   \cdot} % or \times

\unexpanded\def\unitsOUTOF
  {\ifnum\c_units_state=\plusone % suffix
   \else
     \unitssmallspace
   \fi
   :}

\unexpanded\def\unitsSOLIDUS
  {\ifnum\c_units_state=\plusone % suffix
     \unitsbackspace
   \fi
   {/}%
   }%\unitsbackspace}

%D Now we define the standard units command:

\defineunits
  [unit]

%D Example:
%D
%D \startbuffer[definitions]
%D \startluacode
%D     languages.data.labels.prefixes.whatever = {
%D         Kilo = "olik"
%D     }
%D
%D     languages.data.labels.units.whatever = {
%D         Meter  = "retem",
%D         Second = "dnoces",
%D     }
%D
%D     languages.data.labels.operators.whatever = {
%D         Solidus = " rep "
%D     }
%D \stopluacode
%D \stopbuffer
%D
%D \startbuffer[sample]
%D \startlines
%D \lunit{10 km/s}
%D \lunit{10 Kilo Meter/s}
%D \lunit{10 kilo Meter/s}
%D \lunit{10 Kilo m/s}
%D \lunit{10 k Meter/s}
%D \stoplines
%D \stopbuffer
%D
%D \typebuffer[definitions] \getbuffer[definitions]
%D
%D \startbuffer
%D \typebuffer[sample]
%D
%D \defineunits[lunit]                 \getbuffer[sample]
%D \defineunits[lunit][label=test]     \getbuffer[sample]
%D \defineunits[lunit][label=whatever] \getbuffer[sample]
%D \stopbuffer
%D
%D \typebuffer \getbuffer

\protect \endinput