1
2
3
4
5
6
7
8
9
10
11
12
13
14\registerctxluafile{physdim}{autosuffix}
15
16
17
18\unprotect
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\newconstant\c_phys_digits_order
125\newconstant\c_phys_digits_method
126\newconstant\c_phys_digits_sign
127
128\permanent\protected\def\setdigitmethod#1{\c_phys_digits_method #1\relax}
129\permanent\protected\def\setdigitsign #1{\c_phys_digits_sign #1\relax}
130\permanent\protected\def\setdigitorder #1{\c_phys_digits_order #1\relax}
131
132\aliased\let\setdigitmode\setdigitmethod
133
134\def\phys_digits_normalized
135 {\ifcase\c_phys_digits_sign
136 \expandafter\secondoftwoarguments
137 \orelse\ifmmode
138 \expandafter\phys_digits_normalized_math
139 \else
140 \expandafter\phys_digits_normalized_text
141 \fi}
142
143\def\phys_digits_normalized_math#1#2
144 {\setbox\scratchbox\hbox{\normalstartimath\mathstack{#1}\normalstopimath}
145 \hbox to \wd\scratchbox{\hss{\normalstartimath\mathstack{#2}\normalstopimath}\hss}}
146
147\def\phys_digits_normalized_text#1#2
148 {\setbox\scratchbox\hbox{#1}
149 \hbox to \wd\scratchbox{\hss#2\hss}}
150
151\def\phys_digits_raised
152 {\ifmmode
153 \expandafter\normalsuperscript
154 \else
155 \expandafter\unitshigh
156 \fi}
157
158
159
160
161
162
163
164
165
166
167
168
169
170\permanent\protected\def\digitstextbinop#1
171 {\ifmmode\mathord{#1}\else\nobreak#1\fi}
172
173\frozen\def\digitstimessymbol{\digitstextbinop\times}
174
175\frozen\protected\def\digitszeropadding {\hphantom{0}}
176\frozen\protected\def\digitsnegative {\phys_digits_normalized{0}{\mathematics{\negative}}}
177\frozen\protected\def\digitspositive {\phys_digits_normalized{0}{\mathematics{\positive}}}
178\frozen\protected\def\digitsminus {\phys_digits_normalized{0}{\mathminus}}
179\frozen\protected\def\digitsplus {\phys_digits_normalized{0}{\mathplus}}
180\frozen\protected\def\digitsplusminus {\phys_digits_normalized{0}{\mathplusminus}}
181\frozen\protected\def\digitsspace {\hphantom{0}}
182 \protected\def\digitsseparatorspace{\hphantom{.}}
183\frozen\protected\def\digitssignspace {\hphantom{\digitsminus}}
184\frozen\protected\def\digitshighspace {\hphantom{\digitspositive}}
185\frozen\protected\def\digitspower #1{\digitstimessymbol10\phys_digits_raised{#1}}
186\frozen\protected\def\digitspowerplus #1{\digitstimessymbol10\phys_digits_raised{\digitsplus#1}}
187\frozen\protected\def\digitspowerminus #1{\digitstimessymbol10\phys_digits_raised{\digitsminus#1}}
188\frozen\protected\def\digitsdigit #1{#1}
189
190\frozen\protected\def\normaldigitscommasymbol {,}
191\frozen\protected\def\normaldigitsperiodsymbol{.}
192
193\frozen\let\normaldigitsseparatorspace\digitsseparatorspace
194
195\installcorenamespace{digitscomma}
196\installcorenamespace{digitsperiod}
197\installcorenamespace{digitsspace}
198
199\letcsname\??digitscomma 0\endcsname\normaldigitscommasymbol
200\letcsname\??digitsperiod0\endcsname\normaldigitsperiodsymbol
201\letcsname\??digitsspace 0\endcsname\normaldigitsseparatorspace
202
203\letcsname\??digitscomma 1\endcsname\normaldigitsperiodsymbol
204\letcsname\??digitsperiod1\endcsname\normaldigitscommasymbol
205\letcsname\??digitsspace 1\endcsname\normaldigitsseparatorspace
206
207\letcsname\??digitscomma 2\endcsname\normaldigitscommasymbol
208\letcsname\??digitsperiod2\endcsname\normaldigitsperiodsymbol
209\letcsname\??digitsspace 2\endcsname\normaldigitsseparatorspace
210
211\letcsname\??digitscomma 3\endcsname\thinspace
212\letcsname\??digitsperiod3\endcsname\normaldigitscommasymbol
213\letcsname\??digitsspace 3\endcsname\thinspace
214
215\letcsname\??digitscomma 4\endcsname\thinspace
216\letcsname\??digitsperiod4\endcsname\normaldigitsperiodsymbol
217\letcsname\??digitsspace 4\endcsname\thinspace
218
219\letcsname\??digitscomma 5\endcsname\thickspace
220\letcsname\??digitsperiod5\endcsname\normaldigitscommasymbol
221\letcsname\??digitsspace 5\endcsname\thickspace
222
223\letcsname\??digitscomma 6\endcsname\thickspace
224\letcsname\??digitsperiod6\endcsname\normaldigitsperiodsymbol
225\letcsname\??digitsspace 6\endcsname\thickspace
226
227\frozen\protected\def\digitscommasymbol {\csname\??digitscomma \the\c_phys_digits_method\endcsname}
228\frozen\protected\def\digitsperiodsymbol {\csname\??digitsperiod\the\c_phys_digits_method\endcsname}
229\frozen\protected\def\digitsseparatorspace {\csname\??digitsspace \the\c_phys_digits_method\endcsname}
230
231\frozen\protected\def\digitsfinalcomma {\digitsperiodsymbol}
232\frozen\protected\def\digitsfinalperiod {\digitsperiodsymbol}
233\frozen\protected\def\digitsintermediatecomma {\digitscommasymbol }
234\frozen\protected\def\digitsintermediateperiod{\digitscommasymbol }
235
236
237
238\protected\def\phys_digits_indeed#1
239 {\dontleavehmode
240 \begingroup
241 \ifcase\c_phys_digits_order\expandafter\clf_digits_normal\else\expandafter\clf_digits_reverse\fi{\detokenize{#1}}
242 \endgroup
243 \c_phys_units_dospace\conditionaltrue}
244
245\permanent\protected\def\digits
246 {\doifelsenextbgroup\phys_digits_argument\phys_digits_spaced}
247
248\def\phys_digits_argument#1
249 {\phys_digits_indeed{#1}}
250
251\def\phys_digits_spaced#1
252 {\phys_digits_indeed{#1}}
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\installcorenamespace {unit}
348\installcorenamespace {unitseparator}
349\installcorenamespace {unitspace}
350
351\installcommandhandler \??unit {unit} \??unit
352
353\setupunit
354 [\c!alternative=,
355 \c!separator=\v!normal,
356 \s!language=\currentlanguage,
357 \c!order=,
358 \c!option=,
359 \c!method=0,
360
361
362
363
364 ]
365
366\definehigh[unitshigh][\c!style=\txx]
367\definelow [unitslow] [\c!style=\txx]
368
369\aliased\let\setupunits\setupunit
370
371\newconstant \c_phys_units_mode
372\newconstant \c_phys_units_state
373\newconditional\c_phys_units_quantity
374\newconditional\c_phys_units_number
375\newconditional\c_phys_units_dospace
376
377
378
379
380
381
382
383\frozen\protected\def\unitssmallspace {\thinspace}
384\frozen\protected\def\unitsmediumspace{\medspace}
385\frozen\protected\def\unitsbigspace {\thickspace}
386\frozen\protected\def\unitsbackspace {\negthinspace}
387\frozen\protected\def\unitsmathspace {\ifmmode\mathatomskip\mathdimensioncode\mathdimensioncode\mathstyle\fi}
388
389\permanent\protected\def\installunitsseparator#1#2
390 {\defcsname\??unitseparator#1\endcsname{#2}}
391
392\protected\def\phys_units_separator
393 {\ifcsname\??unitseparator\unitparameter\c!separator\endcsname\lastnamedcs\else\ifmmode\mathord\cdot\else\cdot\fi\fi}
394
395\installunitsseparator\v!normal{\ifmmode\mathord\cdot\else\cdot\fi}
396\installunitsseparator\v!big {\unitsbigspace}
397\installunitsseparator\v!medium{\unitsmediumspace}
398\installunitsseparator\v!small {\unitssmallspace}
399\installunitsseparator\v!none {}
400\installunitsseparator\v!math {\unitsmathspace}
401
402\permanent\protected\def\installunitsspace#1#2
403 {\defcsname\??unitspace#1\endcsname{#2}}
404
405
406
407
408
409
410
411
412\protected\def\phys_units_space
413 {\ifmmode
414
415 \else
416 \unskip
417 \ifcsname\??unitspace\unitparameter\c!space\endcsname\lastnamedcs\else\unitsmediumspace\fi
418 \fi}
419
420\installunitsspace\v!normal{\unitsmediumspace}
421\installunitsspace\v!big {\unitsbigspace}
422\installunitsspace\v!medium{\unitsmediumspace}
423\installunitsspace\v!small {\unitssmallspace}
424\installunitsspace\v!none {}
425\installunitsspace\v!math {\unitsmathspace}
426
427\newtoks \everyunits
428
429\appendtoks
430 \disablemathpunctuation
431 \nocharacteralign
432\to \everyunits
433
434\appendtoks
435 \frozen\protected\instance\edefcsname\currentunit\endcsname{\phys_units_direct{\currentunit}}
436\to \everydefineunit
437
438\protected\def\phys_units_direct#1
439 {\begingroup
440 \expand\everyunits\relax
441 \ifdim\lastskip>\zeropoint
442 \c_phys_units_dospace\conditionaltrue
443 \removelastskip
444 \fi
445 \cdef\currentunit{#1}
446 \c_phys_digits_method\unitparameter\c!method\relax
447 \ifmmode\else\dontleavehmode\fi
448
449 \enforced\edef\unitlanguage{\unitparameter\s!language}
450 \enforced\let\prefixlanguage\unitlanguage
451 \enforced\let\operatorlanguage\unitlanguage
452
453
454 \useunitstyleandcolor\c!style\c!color
455 \ifmmode
456 \ifcstok{\unitparameter\c!alternative}\v!text
457 \expandafter\expandafter\expandafter\phys_units_direct_text_in_math
458 \else
459 \expandafter\expandafter\expandafter\phys_units_direct_math
460 \fi
461 \else
462 \ifcstok{\unitparameter\c!alternative}\v!mathematics
463 \expandafter\expandafter\expandafter\phys_units_direct_math_in_text
464 \else
465 \expandafter\expandafter\expandafter\phys_units_direct_text
466 \fi
467 \fi}
468
469\protected\def\phys_units_direct_text_in_math#1
470 {\mathtext{
471 \c_phys_units_mode\plustwo
472 \phys_units_indeed{#1}
473 \phys_units_finish
474 }
475 \endgroup}
476
477\protected\def\phys_units_direct_math#1
478 {\c_phys_units_mode\plusone
479 \rm\tf
480 \mathtf
481 \phys_units_indeed{#1}
482 \phys_units_finish
483 \endgroup}
484
485\protected\def\phys_units_direct_text#1
486 {\phys_units_indeed{#1}
487 \phys_units_finish
488 \endgroup}
489
490\protected\def\phys_units_direct_math_in_text#1
491 {\removeunwantedspaces
492 \startimath
493 \c_phys_units_mode\plusthree
494 \rm\tf
495 \mathtf
496 \phys_units_indeed{#1}
497 \phys_units_finish
498 \stopimath
499 \endgroup}
500
501\protected\def\phys_units_direct_nested#1#2
502 {\phys_units_indeed{#2}}
503
504\appendtoks
505 \let\phys_units_direct\phys_units_direct_nested
506\to \everyunits
507
508
509
510
511
512
513
514
515
516
517\protected\def\phys_units_indeed#1
518 {\clf_unit{\unitparameter\c!order}{\unitparameter\c!option}{\detokenize{#1}}}
519
520\permanent\protected\def\unitsPUS#1#2#3{\phys_units_next\prefixtext{#1}\unittext{#2}\unitsraise{\suffixtext{#3}}\c_phys_units_state\plusone}
521\permanent\protected\def\unitsPU #1#2{\phys_units_next\prefixtext{#1}\unittext{#2}\c_phys_units_state\plusthree}
522\permanent\protected\def\unitsPS #1#2{\phys_units_next\prefixtext{#1}\unitsraise{\suffixtext{#2}}\c_phys_units_state\plusone}
523\permanent\protected\def\unitsUS #1#2{\phys_units_next\unittext{#1}\unitsraise{\suffixtext{#2}}\c_phys_units_state\plusone}
524\permanent\protected\def\unitsP #1{\phys_units_next\prefixtext{#1}1\c_phys_units_state\plusfour}
525\permanent\protected\def\unitsU #1{\phys_units_next\unittext{#1}\c_phys_units_state\plusthree}
526\permanent\protected\def\unitsS #1{\phys_units_start{}\unitsraise{\suffixtext{#1}}\c_phys_units_state\plusone}
527\permanent\protected\def\unitsO #1{\phys_units_start\operatortext{#1}\c_phys_units_state\plustwo}
528
529\permanent\protected\def\unitsC #1{\removeunwantedspaces\unittext{#1}\c_phys_units_state\plussix}
530\permanent\protected\def\unitsQ #1{\removeunwantedspaces\unitslower{#1}\c_phys_units_state\zerocount}
531\permanent\protected\def\unitsR #1#2{
532 \ifmmode
533 #2
534 \orelse\ifnum#1=\plusone
535 \digitstextbinop{#2}
536 \else
537 \digitstextbinop{#2}
538 \fi
539 \c_phys_units_state\zerocount
540 \c_phys_units_dospace\conditionalfalse
541 \c_phys_units_number\conditionalfalse
542 \c_phys_units_quantity\conditionalfalse}
543\permanent\protected\def\unitsRPM {\unitsR\plusone {±}}
544\permanent\protected\def\unitsRTO {\unitsR\plusone {–}}
545\permanent\protected\def\unitsRabout {\unitsR\zerocount{±}}
546\permanent\protected\def\unitsPopen {(}
547\permanent\protected\def\unitsPclose {)}
548\permanent\protected\def\unitrange #1{}
549
550
551
552
553
554\permanent\protected\def\phys_units_text_prime {\textacute}
555\permanent\protected\def\phys_units_text_doubleprime{\textacute\kern.25em\textacute}
556\permanent\protected\def\phys_units_text_celsius {°C}
557\permanent\protected\def\phys_units_text_fahrenheit {°F}
558
559\permanent\protected\def\checkedtextprime
560 {\iffontchar\font"2032\relax\iffontchar\font"2033\relax
561 ′\else\phys_units_text_prime\fi\else\phys_units_text_prime
562 \fi}
563
564\permanent\protected\def\checkedtextdoubleprime
565 {\iffontchar\font"2033\relax\iffontchar\font"2032\relax
566 ″\else\phys_units_text_doubleprime\fi\else\phys_units_text_doubleprime
567 \fi}
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585\aliased\let\checkedtextcelsius \phys_units_text_celsius
586\aliased\let\checkedtextfahrenheit\phys_units_text_fahrenheit
587
588\setelementnature[unit] [mixed]
589\setelementnature[quantity][mixed]
590
591\let\phys_units_finish\relax
592
593\permanent\protected\def\unitsNstartindeed
594 {\ifmmode \else
595 \c_phys_units_quantity\conditionaltrue
596 \dostarttaggednodetail\t!quantity
597 \c_phys_units_number\conditionaltrue
598 \dostarttaggednodetail\t!number
599 \fi}
600
601\permanent\protected\def\unitsNstop
602 {\ifconditional\c_phys_units_number
603 \c_phys_units_number\conditionalfalse
604 \dostoptagged
605 \fi
606 \c_phys_units_state\plusfive}
607
608
609
610
611
612
613\permanent\protected\def\unitsNstart
614 {\doifelsenextchar\unitsNstop\gobbleoneargument\unitsNstartindeed}
615
616
617
618\permanent\protected\def\unitsNspace
619 {\space}
620
621\permanent\protected\def\unitsN#1
622 {\unitsNstart#1\unitsNstop}
623
624\def\phys_units_start
625 {\ifmmode
626 \dostarttagged\t!munit{\lastunitstring}
627 \mathatom
628 \s!leftclass \mathdimensioncode
629 \s!rightclass \mathdimensioncode
630 \bgroup
631 \else
632 \dostarttaggednodetail\t!unit
633 \fi
634 \let\phys_units_finish\phys_units_stop
635 \let\phys_units_start\relax}
636
637\def\phys_units_stop
638 {\ifconditional\c_phys_units_number
639 \c_phys_units_number\conditionalfalse
640 \dostoptagged
641 \fi
642 \ifconditional\c_phys_units_quantity
643 \c_phys_units_quantity\conditionalfalse
644 \dostoptagged
645 \fi
646 \dostoptagged
647 \ifmmode
648 \egroup
649 \fi}
650
651\permanent\def\unitsraise
652 {\ifcase\c_phys_units_mode
653 \expandafter\unitshigh
654 \or
655 \expandafter\normalsuperscript
656 \or
657 \expandafter\unitshigh
658 \or
659 \expandafter\normalsuperscript
660 \fi}
661
662\permanent\def\unitslower
663 {\ifcase\c_phys_units_mode
664 \expandafter\unitslow
665 \or
666 \expandafter\normalsubscript
667 \or
668 \expandafter\unitslow
669 \or
670 \expandafter\normalsubscript
671 \fi}
672
673\protected\def\phys_units_next
674 {\ifcase\c_phys_units_state
675 \ifconditional\c_phys_units_dospace
676
677 \phys_units_space
678
679
680
681 \fi
682 \or
683 {\phys_units_separator}
684 \or
685 \or
686 {\phys_units_separator}
687 \or
688 \or
689 \phys_units_space
690 \or
691 \fi
692 \c_phys_units_dospace\conditionalfalse
693 \phys_units_start}
694
695\permanent\protected\def\unitsTIMES
696 {\ifnum\c_phys_units_state=\plusone
697 \else
698 \unitssmallspace
699 \fi
700 \cdot}
701
702\permanent\protected\def\unitsOUTOF
703 {\ifnum\c_phys_units_state=\plusone
704 \else
705 \unitssmallspace
706 \fi
707 :}
708
709
710
711
712
713
714
715
716\permanent\protected\def\unitsSOLIDUS
717 {\ifnum\c_phys_units_state=\plusone
718 \ifmmode\else\unitsbackspace\fi
719 \fi
720 {}
721 }
722
723\definelabelclass [unit] [2]
724\definelabelclass [operator] [2]
725\definelabelclass [prefix] [2]
726\definelabelclass [suffix] [2]
727
728\clf_definelabels{prefix}{prefixes}\s!false\relax
729\clf_definelabels{unit}{units}\s!false\relax
730\clf_definelabels{operator}{operators}\s!false\relax
731\clf_definelabels{suffix}{suffixes}\s!false\relax
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757\permanent\tolerant\protected\def\registerunit [#1]#*[#2]{\clf_registerunit {#1}{#2}}
758\permanent\tolerant\protected\def\registerunitshortcut[#1]#*[#2]{\clf_registerunitshortcut{#1}{#2}}
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806\defineunit
807 [unit]
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876\mutable\protected\def\digitsbreak{\hskip\zeropoint\s!plus\onepoint\relax\ifmmode\allowbreak\fi}
877
878\protect \endinput
879 |