1
2
3
4
5
6
7
8
9
10
11
12
13
14\registerctxluafile{physdim}{}
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
125
126\newconstant\c_phys_digits_order
127\newconstant\c_phys_digits_method
128\newconstant\c_phys_digits_sign
129
130\unexpanded\def\setdigitmethod#1{\c_phys_digits_method #1\relax}
131\unexpanded\def\setdigitsign #1{\c_phys_digits_sign #1\relax}
132\unexpanded\def\setdigitorder #1{\c_phys_digits_order #1\relax}
133
134\let\setdigitmode\setdigitmethod
135
136\def\phys_digits_normalized
137 {\ifcase\c_phys_digits_sign
138 \expandafter\secondoftwoarguments
139 \else\ifmmode
140 \expandafter\expandafter\expandafter\phys_digits_normalized_math
141 \else
142 \expandafter\expandafter\expandafter\phys_digits_normalized_text
143 \fi\fi}
144
145\def\phys_digits_normalized_math#1#2
146 {\setbox\scratchbox\hbox{\normalstartimath\Ustack{#1}\normalstopimath}
147 \hbox to \wd\scratchbox{\hss{\normalstartimath\Ustack{#2}\normalstopimath}\hss}}
148
149\def\phys_digits_normalized_text#1#2
150 {\setbox\scratchbox\hbox{#1}
151 \hbox to \wd\scratchbox{\hss#2\hss}}
152
153\def\phys_digits_raised
154 {\ifmmode
155 \expandafter\normalsuperscript
156 \else
157 \expandafter\unitshigh
158 \fi}
159
160
161
162
163
164
165
166
167
168
169
170
171
172\unexpanded\def\digitstextbinop#1
173 {\ifmmode#1\else\fourperemspace\nobreak#1\fourperemspace\fi}
174
175
176\def\digitstimessymbol{\digitstextbinop\times}
177
178\unexpanded\def\digitszeropadding {\hphantom{0}}
179\unexpanded\def\digitsnegative {\phys_digits_normalized{0}{\phys_digits_raised{\textminus}}}
180\unexpanded\def\digitspositive {\phys_digits_normalized{0}{\phys_digits_raised{\textplus}}}
181\unexpanded\def\digitsnegative {\phys_digits_normalized{0}{\mathematics{\negative}}}
182\unexpanded\def\digitspositive {\phys_digits_normalized{0}{\mathematics{\positive}}}
183
184
185\unexpanded\def\digitsminus {\phys_digits_normalized{0}{\mathminus}}
186\unexpanded\def\digitsplus {\phys_digits_normalized{0}{\mathplus}}
187\unexpanded\def\digitsplusminus {\phys_digits_normalized{0}{\mathplusminus}}
188\unexpanded\def\digitsspace {\hphantom{0}}
189\unexpanded\def\digitsseparatorspace{\hphantom{.}}
190\unexpanded\def\digitssignspace {\hphantom{\digitsminus}}
191\unexpanded\def\digitshighspace {\hphantom{\digitspositive}}
192\unexpanded\def\digitspower #1{\digitstimessymbol10\phys_digits_raised{#1}}
193\unexpanded\def\digitspowerplus #1{\digitstimessymbol10\phys_digits_raised{\digitsplus#1}}
194\unexpanded\def\digitspowerminus #1{\digitstimessymbol10\phys_digits_raised{\digitsminus#1}}
195\unexpanded\def\digitsdigit #1{#1}
196
197\unexpanded\def\normaldigitscommasymbol {,}
198\unexpanded\def\normaldigitsperiodsymbol{.}
199
200\let\normaldigitsseparatorspace\digitsseparatorspace
201
202\installcorenamespace{digitscomma}
203\installcorenamespace{digitsperiod}
204\installcorenamespace{digitsspace}
205
206\letvalue{\??digitscomma 0}\normaldigitscommasymbol
207\letvalue{\??digitsperiod0}\normaldigitsperiodsymbol
208\letvalue{\??digitsspace 0}\normaldigitsseparatorspace
209
210\letvalue{\??digitscomma 1}\normaldigitsperiodsymbol
211\letvalue{\??digitsperiod1}\normaldigitscommasymbol
212\letvalue{\??digitsspace 1}\normaldigitsseparatorspace
213
214\letvalue{\??digitscomma 2}\normaldigitscommasymbol
215\letvalue{\??digitsperiod2}\normaldigitsperiodsymbol
216\letvalue{\??digitsspace 2}\normaldigitsseparatorspace
217
218\letvalue{\??digitscomma 3}\thinspace
219\letvalue{\??digitsperiod3}\normaldigitscommasymbol
220\letvalue{\??digitsspace 3}\thinspace
221
222\letvalue{\??digitscomma 4}\thinspace
223\letvalue{\??digitsperiod4}\normaldigitsperiodsymbol
224\letvalue{\??digitsspace 4}\thinspace
225
226\letvalue{\??digitscomma 5}\thickspace
227\letvalue{\??digitsperiod5}\normaldigitscommasymbol
228\letvalue{\??digitsspace 5}\thickspace
229
230\letvalue{\??digitscomma 6}\thickspace
231\letvalue{\??digitsperiod6}\normaldigitsperiodsymbol
232\letvalue{\??digitsspace 6}\thickspace
233
234\unexpanded\def\digitscommasymbol {\csname\??digitscomma \number\c_phys_digits_method\endcsname}
235\unexpanded\def\digitsperiodsymbol {\csname\??digitsperiod\number\c_phys_digits_method\endcsname}
236\unexpanded\def\digitsseparatorspace {\csname\??digitsspace \number\c_phys_digits_method\endcsname}
237
238
239
240
241
242
243\unexpanded\def\digitsfinalcomma {\digitsperiodsymbol}
244\unexpanded\def\digitsfinalperiod {\digitsperiodsymbol}
245\unexpanded\def\digitsintermediatecomma {\digitscommasymbol }
246\unexpanded\def\digitsintermediateperiod {\digitscommasymbol }
247
248
249
250\unexpanded\def\phys_digits_indeed#1
251 {\dontleavehmode
252 \begingroup
253 \ifcase\c_phys_digits_order\expandafter\clf_digits_normal\else\expandafter\clf_digits_reverse\fi{\detokenize{#1}}
254 \endgroup
255 \settrue\c_phys_units_dospace}
256
257\unexpanded\def\digits
258 {\doifelsenextbgroup\phys_digits_argument\phys_digits_spaced}
259
260\def\phys_digits_argument#1
261 {\phys_digits_indeed{#1}}
262
263\def\phys_digits_spaced#1
264 {\phys_digits_indeed{#1}}
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\installcorenamespace {unit}
360\installcorenamespace {unitseparator}
361\installcorenamespace {unitspace}
362
363\installcommandhandler \??unit {unit} \??unit
364
365\setupunit
366 [\c!alternative=,
367 \c!separator=\v!normal,
368 \s!language=\currentlanguage,
369 \c!order=\v!normal,
370 \c!method=0,
371
372
373
374
375 ]
376
377\definehigh[unitshigh][\c!style=\txx]
378\definelow [unitslow] [\c!style=\txx]
379
380\let\setupunits\setupunit
381
382\newconstant \c_phys_units_mode
383\newconstant \c_phys_units_state
384\newconditional\c_phys_units_quantity
385\newconditional\c_phys_units_number
386\newconditional\c_phys_units_dospace
387
388
389
390
391
392
393
394\unexpanded\def\unitssmallspace {\thinspace}
395\unexpanded\def\unitsmediumspace{\medspace}
396\unexpanded\def\unitsbigspace {\thickspace}
397\unexpanded\def\unitsbackspace {\negthinspace}
398
399\unexpanded\def\installunitsseparator#1#2
400 {\setvalue{\??unitseparator#1}{#2}}
401
402
403
404
405
406
407
408\unexpanded\def\phys_units_separator
409 {\edef\currentunitsseparator{\unitparameter\c!separator}
410 \ifcsname\??unitseparator\currentunitsseparator\endcsname\lastnamedcs\else\cdot\fi}
411
412\installunitsseparator\v!normal {\cdot}
413\installunitsseparator\v!big {\unitsbigspace}
414\installunitsseparator\v!medium {\unitsmediumspace}
415\installunitsseparator\v!small {\unitssmallspace}
416\installunitsseparator\v!none {}
417
418\unexpanded\def\installunitsspace#1#2
419 {\setvalue{\??unitspace#1}{#2}}
420
421
422
423
424
425
426
427
428\unexpanded\def\phys_units_space
429 {\unskip
430 \edef\currentunitsspace{\unitparameter\c!space}
431 \ifcsname\??unitspace\currentunitsspace\endcsname\lastnamedcs\else\unitsmediumspace\fi}
432
433\installunitsspace\v!normal {\unitsmediumspace}
434\installunitsspace\v!big {\unitsbigspace}
435\installunitsspace\v!medium {\unitsmediumspace}
436\installunitsspace\v!small {\unitssmallspace}
437\installunitsspace\v!none {}
438
439\newtoks \everyunits
440
441\appendtoks
442 \disablemathpunctuation
443 \nocharacteralign
444\to \everyunits
445
446\appendtoks
447 \setuevalue\currentunit{\phys_units_direct{\currentunit}}
448\to \everydefineunit
449
450\unexpanded\def\phys_units_direct#1
451 {\begingroup
452 \the\everyunits
453 \ifdim\lastskip>\zeropoint
454 \settrue\c_phys_units_dospace
455 \removelastskip
456 \fi
457 \c_phys_digits_method\unitparameter\c!method\relax
458 \ifmmode\else\dontleavehmode\fi
459 \edef\currentunit{#1}
460 \edef\unitlanguage{\unitparameter\s!language}
461 \let\prefixlanguage\unitlanguage
462 \let\operatorlanguage\unitlanguage
463
464
465 \useunitstyleandcolor\c!style\c!color
466 \edef\currentunitsalternative{\unitparameter\c!alternative}
467 \ifmmode
468 \ifx\currentunitsalternative\v!text
469 \expandafter\expandafter\expandafter\phys_units_direct_text_in_math
470 \else
471 \expandafter\expandafter\expandafter\phys_units_direct_math
472 \fi
473 \else
474 \ifx\currentunitsalternative\v!mathematics
475 \expandafter\expandafter\expandafter\phys_units_direct_math_in_text
476 \else
477 \expandafter\expandafter\expandafter\phys_units_direct_text
478 \fi
479 \fi}
480
481\unexpanded\def\phys_units_direct_text_in_math#1
482 {\mathtext{
483 \c_phys_units_mode\plustwo
484 \phys_units_indeed{#1}
485 \phys_units_finish
486 }
487 \endgroup}
488
489\unexpanded\def\phys_units_direct_math#1
490 {\c_phys_units_mode\plusone
491 \rm\tf
492 \mathtf
493 \phys_units_indeed{#1}
494 \phys_units_finish
495 \endgroup}
496
497\unexpanded\def\phys_units_direct_text#1
498 {\phys_units_indeed{#1}
499 \phys_units_finish
500 \endgroup}
501
502\unexpanded\def\phys_units_direct_math_in_text#1
503 {\removeunwantedspaces
504 \startimath
505 \c_phys_units_mode\plusthree
506 \rm\tf
507 \mathtf
508 \phys_units_indeed{#1}
509 \phys_units_finish
510 \stopimath
511 \endgroup}
512
513\unexpanded\def\phys_units_direct_nested#1#2
514 {\phys_units_indeed{#2}}
515
516\appendtoks
517 \let\phys_units_direct\phys_units_direct_nested
518\to \everyunits
519
520\unexpanded\def\phys_units_indeed#1
521 {\edef\p_order{\unitparameter\c!order}
522 \ifx\p_order\v!reverse\expandafter\clf_unit_reverse\else\expandafter\clf_unit_normal\fi{\detokenize{#1}}}
523
524\unexpanded\def\digitstextbinnop#1
525 {\ifmmode#1\else#1\fourperemspace\fi}
526
527\unexpanded\def\unitsPUS#1#2#3{\phys_units_next\prefixtext{#1}\unittext{#2}\unitsraise{\suffixtext{#3}}\c_phys_units_state\plusone}
528\unexpanded\def\unitsPU #1#2{\phys_units_next\prefixtext{#1}\unittext{#2}\c_phys_units_state\plusthree}
529\unexpanded\def\unitsPS #1#2{\phys_units_next\prefixtext{#1}\unitsraise{\suffixtext{#2}}\c_phys_units_state\plusone}
530\unexpanded\def\unitsUS #1#2{\phys_units_next\unittext{#1}\unitsraise{\suffixtext{#2}}\c_phys_units_state\plusone}
531\unexpanded\def\unitsP #1{\phys_units_next\prefixtext{#1}1\c_phys_units_state\plusfour}
532\unexpanded\def\unitsU #1{\phys_units_next\unittext{#1}\c_phys_units_state\plusthree}
533\unexpanded\def\unitsS #1{\phys_units_start{}\unitsraise{\suffixtext{#1}}\c_phys_units_state\plusone}
534\unexpanded\def\unitsO #1{\phys_units_start\operatortext{#1}\c_phys_units_state\plustwo}
535\unexpanded\def\unitsN #1{\phys_units_start#1\c_phys_units_state\plusfive}
536\unexpanded\def\unitsC #1{\removeunwantedspaces\unittext{#1}\c_phys_units_state\plussix}
537\unexpanded\def\unitsQ #1{\removeunwantedspaces\unitslower{#1}\c_phys_units_state\zerocount}
538\unexpanded\def\unitsR #1#2{
539 \ifmmode
540 #2
541 \else\ifnum#1=\plusone
542 \digitstextbinop{#2}
543 \else
544 \digitstextbinnop{#2}
545 \fi\fi
546 \c_phys_units_state\zerocount
547 \setfalse\c_phys_units_dospace
548 \setfalse\c_phys_units_number
549 \setfalse\c_phys_units_quantity}
550
551\unexpanded\def\unitsRPM {\unitsR\plusone {±}}
552\unexpanded\def\unitsRTO {\unitsR\plusone {–}}
553\unexpanded\def\unitsRabout {\unitsR\zerocount{±}}
554\unexpanded\def\unitsPopen {(}
555\unexpanded\def\unitsPclose {)}
556
557\unexpanded\def\unitrange#1{}
558
559
560
561
562
563\def\phys_units_text_prime {\textacute}
564\def\phys_units_text_doubleprime{\textacute\kern.25em\textacute}
565\def\phys_units_text_celsius {°C}
566\def\phys_units_text_fahrenheit {°F}
567
568\unexpanded\def\checkedtextprime
569 {\iffontchar\font"2032\relax\iffontchar\font"2033\relax
570 ′\else\phys_units_text_prime\fi\else\phys_units_text_prime
571 \fi}
572
573\unexpanded\def\checkedtextdoubleprime
574 {\iffontchar\font"2033\relax\iffontchar\font"2032\relax
575 ″\else\phys_units_text_doubleprime\fi\else\phys_units_text_doubleprime
576 \fi}
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594\let\checkedtextcelsius \phys_units_text_celsius
595\let\checkedtextfahrenheit\phys_units_text_fahrenheit
596
597\setelementnature[unit] [mixed]
598\setelementnature[quantity][mixed]
599
600\let\phys_units_finish\relax
601
602\unexpanded\def\unitsNstart
603 {\ifmmode \else
604 \settrue\c_phys_units_quantity
605 \dostarttagged\t!quantity\empty
606 \settrue\c_phys_units_number
607 \dostarttagged\t!number\empty
608 \fi}
609
610\unexpanded\def\unitsNstop
611 {\ifconditional\c_phys_units_number
612 \setfalse\c_phys_units_number
613 \dostoptagged
614 \fi
615 \c_phys_units_state\plusfive}
616
617
618
619
620\let\unitsNstartindeed\unitsNstart
621
622\unexpanded\def\unitsNstart
623 {\doifelsenextchar\unitsNstop\gobbleoneargument\unitsNstartindeed}
624
625
626
627\unexpanded\def\unitsNspace
628 {\space}
629
630\unexpanded\def\unitsN#1
631 {\unitsNstart#1\unitsNstop}
632
633\def\phys_units_start
634 {\ifmmode
635 \dostarttagged\t!maction\t!unit
636 \bgroup
637 \else
638 \dostarttagged\t!unit\empty
639 \fi
640 \let\phys_units_finish\phys_units_stop
641 \let\phys_units_start\relax}
642
643\def\phys_units_stop
644 {\ifconditional\c_phys_units_number
645 \setfalse\c_phys_units_number
646 \dostoptagged
647 \fi
648 \ifconditional\c_phys_units_quantity
649 \setfalse\c_phys_units_quantity
650 \dostoptagged
651 \fi
652 \dostoptagged
653 \ifmmode
654 \egroup
655 \fi}
656
657\def\unitsraise
658 {\ifcase\c_phys_units_mode
659 \expandafter\unitshigh
660 \or
661 \expandafter\normalsuperscript
662 \or
663 \expandafter\unitshigh
664 \or
665 \expandafter\normalsuperscript
666 \fi}
667
668\def\unitslower
669 {\ifcase\c_phys_units_mode
670 \expandafter\unitslow
671 \or
672 \expandafter\normalsubscript
673 \or
674 \expandafter\unitslow
675 \or
676 \expandafter\normalsubscript
677 \fi}
678
679\unexpanded\def\phys_units_next
680 {\ifcase\c_phys_units_state
681 \ifconditional\c_phys_units_dospace
682
683 \phys_units_space
684
685
686
687 \fi
688 \or
689 {\phys_units_separator}
690 \or
691 \or
692 {\phys_units_separator}
693 \or
694 \or
695 \phys_units_space
696 \or
697 \fi
698 \setfalse\c_phys_units_dospace
699 \phys_units_start}
700
701\unexpanded\def\unitsTIMES
702 {\ifnum\c_phys_units_state=\plusone
703 \else
704 \unitssmallspace
705 \fi
706 \cdot}
707
708\unexpanded\def\unitsOUTOF
709 {\ifnum\c_phys_units_state=\plusone
710 \else
711 \unitssmallspace
712 \fi
713 :}
714
715\unexpanded\def\unitsSOLIDUS
716 {\ifnum\c_phys_units_state=\plusone
717 \unitsbackspace
718 \fi
719 {}
720 }
721
722\definelabelclass [unit] [2]
723\definelabelclass [operator] [2]
724\definelabelclass [prefix] [2]
725\definelabelclass [suffix] [2]
726
727\clf_definelabels{prefix}{prefixes}\s!false\relax
728\clf_definelabels{unit}{units}\s!false\relax
729\clf_definelabels{operator}{operators}\s!false\relax
730\clf_definelabels{suffix}{suffixes}\s!false\relax
731
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\unexpanded\def\registerunit
758 {\dodoubleempty\phys_units_register}
759
760\def\phys_units_register[#1][#2]
761 {\clf_registerunit{#1}{#2}}
762
763
764
765
766
767
768
769
770
771
772
773\defineunit
774 [unit]
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
807
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\protect \endinput
835 |