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