diff options
author | Hans Hagen <pragma@wxs.nl> | 2012-01-05 19:27:56 +0100 |
---|---|---|
committer | Hans Hagen <pragma@wxs.nl> | 2012-01-05 19:27:56 +0100 |
commit | 5e5b7116e78d1cb847434ef29a9fed154e49adf9 (patch) | |
tree | 4fe640ecbf5137c5c68d7730ae03b91c2169bd9a /tex/context/base/phys-dim.mkiv | |
parent | 551356b39d8dfbf10ed6542aa3281cb08cd36197 (diff) | |
download | context-5e5b7116e78d1cb847434ef29a9fed154e49adf9.tar.gz |
beta 2012.01.02 17:18
Diffstat (limited to 'tex/context/base/phys-dim.mkiv')
-rw-r--r-- | tex/context/base/phys-dim.mkiv | 278 |
1 files changed, 141 insertions, 137 deletions
diff --git a/tex/context/base/phys-dim.mkiv b/tex/context/base/phys-dim.mkiv index 3a153281d..84c3c7a2a 100644 --- a/tex/context/base/phys-dim.mkiv +++ b/tex/context/base/phys-dim.mkiv @@ -125,34 +125,34 @@ %D \NC \type{___,___,_12,345,678.==} \NC \ruledhbox{\strut\digits{___,___,_12,345,678.==}} \NC \NR %D \stoptabulate -\newconstant\c_digits_order -\newconstant\c_digits_method -\newconstant\c_digits_sign % we has sized (text script scriptscript) +\newconstant\c_phys_digits_order +\newconstant\c_phys_digits_method +\newconstant\c_phys_digits_sign % we has sized (text script scriptscript) -\unexpanded\def\setdigitmethod#1{\c_digits_method #1\relax} -\unexpanded\def\setdigitsign #1{\c_digits_sign #1\relax} -\unexpanded\def\setdigitorder #1{\c_digits_order #1\relax} +\unexpanded\def\setdigitmethod#1{\c_phys_digits_method #1\relax} +\unexpanded\def\setdigitsign #1{\c_phys_digits_sign #1\relax} +\unexpanded\def\setdigitorder #1{\c_phys_digits_order #1\relax} \let\setdigitmode\setdigitmethod % compatibility -\def\digits_normalized % we could calculate once and remember - {\ifcase\c_digits_sign +\def\phys_digits_normalized % we could calculate once and remember + {\ifcase\c_phys_digits_sign \expandafter\secondoftwoarguments \else\ifmmode - \expandafter\expandafter\expandafter\digits_normalized_math + \expandafter\expandafter\expandafter\phys_digits_normalized_math \else - \expandafter\expandafter\expandafter\digits_normalized_text + \expandafter\expandafter\expandafter\phys_digits_normalized_text \fi\fi} -\def\digits_normalized_math#1#2% +\def\phys_digits_normalized_math#1#2% {\setbox\scratchbox\hbox{$\Ustack{#1}$}% \hbox to \wd\scratchbox{\hss{$\Ustack{#2}$}\hss}} -\def\digits_normalized_text#1#2% +\def\phys_digits_normalized_text#1#2% {\setbox\scratchbox\hbox{#1}% \hbox to \wd\scratchbox{\hss#2\hss}} -\def\digits_raised +\def\phys_digits_raised {\ifmmode \expandafter\normalsuperscript \else @@ -160,19 +160,19 @@ \fi} \unexpanded\def\digitszeropadding {\hphantom{0}} -\unexpanded\def\digitsnegative {\digits_normalized{0}{\digits_raised{\textminus}}} -\unexpanded\def\digitspositive {\digits_normalized{0}{\digits_raised{\textplus}}} -\unexpanded\def\digitsnegative {\digits_normalized{0}{\mathematics{\negative}}} -\unexpanded\def\digitspositive {\digits_normalized{0}{\mathematics{\positive}}} -\unexpanded\def\digitsminus {\digits_normalized{0}{\mathematics{-}}} -\unexpanded\def\digitsplus {\digits_normalized{0}{\mathematics{+}}} +\unexpanded\def\digitsnegative {\phys_digits_normalized{0}{\phys_digits_raised{\textminus}}} +\unexpanded\def\digitspositive {\phys_digits_normalized{0}{\phys_digits_raised{\textplus}}} +\unexpanded\def\digitsnegative {\phys_digits_normalized{0}{\mathematics{\negative}}} +\unexpanded\def\digitspositive {\phys_digits_normalized{0}{\mathematics{\positive}}} +\unexpanded\def\digitsminus {\phys_digits_normalized{0}{\mathematics{-}}} +\unexpanded\def\digitsplus {\phys_digits_normalized{0}{\mathematics{+}}} \unexpanded\def\digitsspace {\hphantom{0}} \unexpanded\def\digitsseparatorspace{\hphantom{.}} \unexpanded\def\digitssignspace {\hphantom{\digitsminus}} \unexpanded\def\digitshighspace {\hphantom{\digitspositive}} -\unexpanded\def\digitspower #1{\times10\digits_raised{#1}} -\unexpanded\def\digitspowerplus #1{\times10\digits_raised{\digitsplus#1}} -\unexpanded\def\digitspowerminus #1{\times10\digits_raised{\digitsminus#1}} +\unexpanded\def\digitspower #1{\times10\phys_digits_raised{#1}} +\unexpanded\def\digitspowerplus #1{\times10\phys_digits_raised{\digitsplus#1}} +\unexpanded\def\digitspowerminus #1{\times10\phys_digits_raised{\digitsminus#1}} \unexpanded\def\digitsdigit #1{#1} \unexpanded\def\normaldigitscommasymbol {,} @@ -180,37 +180,41 @@ \let\normaldigitsseparatorspace\digitsseparatorspace -\letvalue{digit_c_0}\normaldigitscommasymbol -\letvalue{digit_p_0}\normaldigitsperiodsymbol -\letvalue{digit_s_0}\normaldigitsseparatorspace +\installcorenamespace{digitscomma} +\installcorenamespace{digitsperiod} +\installcorenamespace{digitsspace} -\letvalue{digit_c_1}\normaldigitsperiodsymbol -\letvalue{digit_p_1}\normaldigitscommasymbol -\letvalue{digit_s_1}\normaldigitsseparatorspace +\letvalue{\??digitscomma 0}\normaldigitscommasymbol +\letvalue{\??digitsperiod0}\normaldigitsperiodsymbol +\letvalue{\??digitsspace 0}\normaldigitsseparatorspace -\letvalue{digit_c_2}\normaldigitscommasymbol -\letvalue{digit_p_2}\normaldigitsperiodsymbol -\letvalue{digit_s_2}\normaldigitsseparatorspace +\letvalue{\??digitscomma 1}\normaldigitsperiodsymbol +\letvalue{\??digitsperiod1}\normaldigitscommasymbol +\letvalue{\??digitsspace 1}\normaldigitsseparatorspace -\letvalue{digit_c_3}\thinspace -\letvalue{digit_p_3}\normaldigitscommasymbol -\letvalue{digit_s_3}\thinspace +\letvalue{\??digitscomma 2}\normaldigitscommasymbol +\letvalue{\??digitsperiod2}\normaldigitsperiodsymbol +\letvalue{\??digitsspace 2}\normaldigitsseparatorspace -\letvalue{digit_c_4}\thinspace -\letvalue{digit_p_4}\normaldigitsperiodsymbol -\letvalue{digit_s_4}\thinspace +\letvalue{\??digitscomma 3}\thinspace +\letvalue{\??digitsperiod3}\normaldigitscommasymbol +\letvalue{\??digitsspace 3}\thinspace -\letvalue{digit_c_5}\thickspace -\letvalue{digit_p_5}\normaldigitscommasymbol -\letvalue{digit_s_5}\thickspace +\letvalue{\??digitscomma 4}\thinspace +\letvalue{\??digitsperiod4}\normaldigitsperiodsymbol +\letvalue{\??digitsspace 4}\thinspace -\letvalue{digit_c_6}\thickspace -\letvalue{digit_p_6}\normaldigitsperiodsymbol -\letvalue{digit_s_6}\thickspace +\letvalue{\??digitscomma 5}\thickspace +\letvalue{\??digitsperiod5}\normaldigitscommasymbol +\letvalue{\??digitsspace 5}\thickspace -\unexpanded\def\digitscommasymbol {\csname digit_c_\number\c_digits_method\endcsname} -\unexpanded\def\digitsperiodsymbol {\csname digit_p_\number\c_digits_method\endcsname} -\unexpanded\def\digitsseparatorspace {\csname digit_s_\number\c_digits_method\endcsname} +\letvalue{\??digitscomma 6}\thickspace +\letvalue{\??digitsperiod6}\normaldigitsperiodsymbol +\letvalue{\??digitsspace 6}\thickspace + +\unexpanded\def\digitscommasymbol {\csname\??digitscomma \number\c_phys_digits_method\endcsname} +\unexpanded\def\digitsperiodsymbol {\csname\??digitsperiod\number\c_phys_digits_method\endcsname} +\unexpanded\def\digitsseparatorspace {\csname\??digitsspace \number\c_phys_digits_method\endcsname} \unexpanded\def\digitsfinalcomma {\digitscommasymbol } % more for tracing \unexpanded\def\digitsfinalperiod {\digitsperiodsymbol} % more for tracing @@ -219,21 +223,21 @@ %D The user macro: -\unexpanded\def\digits_indeed#1% +\unexpanded\def\phys_digits_indeed#1% {\dontleavehmode \begingroup - \ctxcommand{digits(\!!bs\detokenize{#1}\!!es,"\ifcase\c_digits_order \v!normal\else\v!reverse\fi")}% + \ctxcommand{digits(\!!bs\detokenize{#1}\!!es,"\ifcase\c_phys_digits_order \v!normal\else\v!reverse\fi")}% \endgroup - \settrue\c_units_dospace} + \settrue\c_phys_units_dospace} \unexpanded\def\digits - {\doifnextbgroupelse\digits_argument\digits_spaced} + {\doifnextbgroupelse\phys_digits_argument\phys_digits_spaced} -\def\digits_argument#1% - {\digits_indeed{#1}} +\def\phys_digits_argument#1% + {\phys_digits_indeed{#1}} -\def\digits_spaced#1 % space delimited - {\digits_indeed{#1}} +\def\phys_digits_spaced#1 % space delimited + {\phys_digits_indeed{#1}} %D \macros %D {unit} @@ -348,11 +352,11 @@ \let\setupunits\setupunit -\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 +\newconstant \c_phys_units_mode % 0=text 1=math 2=textinmath 3=mathintext +\newconstant \c_phys_units_state % 0=start 1=suffix 2=operator 3=unit 4=prefix 5=number +\newconditional\c_phys_units_quantity +\newconditional\c_phys_units_number +\newconditional\c_phys_units_dospace % [\unit {micro ohm}]\par % no space before unit % [10\unit {micro ohm}]\par % no space before unit @@ -368,7 +372,7 @@ \unexpanded\def\installunitsseparator#1#2% {\setvalue{\??unitseparator#1}{#2}} -\unexpanded\def\dounitsseparator +\unexpanded\def\phys_units_separator {\edef\currentunitsseparator{\unitparameter\c!separator}% \csname\??unitseparator \ifcsname\??unitseparator\currentunitsseparator\endcsname\currentunitsseparator\else\v!normal\fi @@ -383,7 +387,7 @@ \unexpanded\def\installunitsspace#1#2% {\setvalue{\??unitspace#1}{#2}} -\unexpanded\def\dounitsspace +\unexpanded\def\phys_units_space {\unskip % weird, why is unskip needed \edef\currentunitsspace{\unitparameter\c!space}% \csname\??unitspace @@ -399,16 +403,16 @@ \newtoks \everyunits % we keep the old \units command so we need a longer one \appendtoks - \setuevalue\currentunit{\units_direct{\currentunit}} + \setuevalue\currentunit{\phys_units_direct{\currentunit}} \to \everydefineunit -\unexpanded\def\units_direct#1% +\unexpanded\def\phys_units_direct#1% {\begingroup \ifdim\lastskip>\zeropoint - \settrue\c_units_dospace + \settrue\c_phys_units_dospace \removelastskip \fi - \c_digits_method\unitparameter\c!method\relax + \c_phys_digits_method\unitparameter\c!method\relax \ifmmode\else\dontleavehmode\fi \edef\currentunit{#1}% \edef\unitlanguage{\unitparameter\s!language}% @@ -420,120 +424,120 @@ \edef\currentunitsalternative{\unitparameter\c!alternative}% \ifmmode \ifx\currentunitsalternative\v!text - \expandafter\expandafter\expandafter\units_direct_text_in_math + \expandafter\expandafter\expandafter\phys_units_direct_text_in_math \else - \expandafter\expandafter\expandafter\units_direct_math + \expandafter\expandafter\expandafter\phys_units_direct_math \fi \else \ifx\currentunitsalternative\v!mathematics - \expandafter\expandafter\expandafter\units_direct_math_in_text + \expandafter\expandafter\expandafter\phys_units_direct_math_in_text \else - \expandafter\expandafter\expandafter\units_direct_text + \expandafter\expandafter\expandafter\phys_units_direct_text \fi \fi} -\unexpanded\def\units_direct_text_in_math#1% +\unexpanded\def\phys_units_direct_text_in_math#1% {\mathtext{% - \c_units_mode\plustwo - \units_indeed{#1}% - \units_finish + \c_phys_units_mode\plustwo + \phys_units_indeed{#1}% + \phys_units_finish }% \endgroup} -\unexpanded\def\units_direct_math#1% - {\c_units_mode\plusone +\unexpanded\def\phys_units_direct_math#1% + {\c_phys_units_mode\plusone \rm\tf % slow \mathtf - \units_indeed{#1}% - \units_finish + \phys_units_indeed{#1}% + \phys_units_finish \endgroup} -\unexpanded\def\units_direct_text#1% - {\units_indeed{#1}% - \units_finish +\unexpanded\def\phys_units_direct_text#1% + {\phys_units_indeed{#1}% + \phys_units_finish \endgroup} -\unexpanded\def\units_direct_math_in_text#1% +\unexpanded\def\phys_units_direct_math_in_text#1% {\removeunwantedspaces % brr \startimath - \c_units_mode\plusthree + \c_phys_units_mode\plusthree \rm\tf \mathtf - \units_indeed{#1}% - \units_finish + \phys_units_indeed{#1}% + \phys_units_finish \stopimath \endgroup} -\unexpanded\def\units_direct_nested#1#2% - {\units_indeed{#2}} +\unexpanded\def\phys_units_direct_nested#1#2% + {\phys_units_indeed{#2}} \appendtoks - \let\units_direct\units_direct_nested + \let\phys_units_direct\phys_units_direct_nested \to \everyunits -\unexpanded\def\units_indeed#1% +\unexpanded\def\phys_units_indeed#1% {\ctxcommand{unit(\!!bs\detokenize{#1}\!!es,"\unitparameter\c!order")}} -\unexpanded\def\unitsPUS#1#2#3{\units_next\prefixtext{#1}\unittext{#2}\unitsraise{\suffixtext{#3}}\c_units_state\plusone} % suffix -\unexpanded\def\unitsPU #1#2{\units_next\prefixtext{#1}\unittext{#2}\c_units_state\plusthree} % unit -\unexpanded\def\unitsPS #1#2{\units_next\prefixtext{#1}\unitsraise{\suffixtext{#2}}\c_units_state\plusone} % suffix -\unexpanded\def\unitsUS #1#2{\units_next\unittext{#1}\unitsraise{\suffixtext{#2}}\c_units_state\plusone} % suffix -\unexpanded\def\unitsP #1{\units_next\prefixtext{#1}1\c_units_state\plusfour} % prefix -\unexpanded\def\unitsU #1{\units_next\unittext{#1}\c_units_state\plusthree} % unit -\unexpanded\def\unitsS #1{\units_start{}\unitsraise{\suffixtext{#1}}\c_units_state\plusone} % suffix -\unexpanded\def\unitsO #1{\units_start\operatortext{#1}\c_units_state\plustwo} % operator -\unexpanded\def\unitsN #1{\units_start#1\c_units_state\plusfive} % number -\unexpanded\def\unitsC #1{\removeunwantedspaces\unittext{#1}\c_units_state\plussix} % connected -\unexpanded\def\unitsQ #1{\removeunwantedspaces\unitslower{#1}\c_units_state\zerocount} % +\unexpanded\def\unitsPUS#1#2#3{\phys_units_next\prefixtext{#1}\unittext{#2}\unitsraise{\suffixtext{#3}}\c_phys_units_state\plusone} % suffix +\unexpanded\def\unitsPU #1#2{\phys_units_next\prefixtext{#1}\unittext{#2}\c_phys_units_state\plusthree} % unit +\unexpanded\def\unitsPS #1#2{\phys_units_next\prefixtext{#1}\unitsraise{\suffixtext{#2}}\c_phys_units_state\plusone} % suffix +\unexpanded\def\unitsUS #1#2{\phys_units_next\unittext{#1}\unitsraise{\suffixtext{#2}}\c_phys_units_state\plusone} % suffix +\unexpanded\def\unitsP #1{\phys_units_next\prefixtext{#1}1\c_phys_units_state\plusfour} % prefix +\unexpanded\def\unitsU #1{\phys_units_next\unittext{#1}\c_phys_units_state\plusthree} % unit +\unexpanded\def\unitsS #1{\phys_units_start{}\unitsraise{\suffixtext{#1}}\c_phys_units_state\plusone} % suffix +\unexpanded\def\unitsO #1{\phys_units_start\operatortext{#1}\c_phys_units_state\plustwo} % operator +\unexpanded\def\unitsN #1{\phys_units_start#1\c_phys_units_state\plusfive} % number +\unexpanded\def\unitsC #1{\removeunwantedspaces\unittext{#1}\c_phys_units_state\plussix} % connected +\unexpanded\def\unitsQ #1{\removeunwantedspaces\unitslower{#1}\c_phys_units_state\zerocount} % % Fonts can have a celsius and lack a fahrenheit symbol and as we want % to be consistent so we check for the counterparts as well. It's slow % but ok. Of course we could go virtual instead. -\def\text_fallback_prime {\textacute} -\def\text_fallback_doubleprime{\textacute\kern-.25em\textacute} -\def\text_fallback_celsius {°C} -\def\text_fallback_fahrenheit {°F} +\def\phys_units_text_prime {\textacute} +\def\phys_units_text_doubleprime{\textacute\kern-.25em\textacute} +\def\phys_units_text_celsius {°C} +\def\phys_units_text_fahrenheit {°F} \unexpanded\def\checkedtextprime {\iffontchar\font"2032\relax\iffontchar\font"2033\relax - ′\else\text_fallback_prime\fi\else\text_fallback_prime + ′\else\phys_units_text_prime\fi\else\phys_units_text_prime \fi} \unexpanded\def\checkedtextdoubleprime {\iffontchar\font"2033\relax\iffontchar\font"2032\relax - ″\else\text_fallback_doubleprime\fi\else\text_fallback_doubleprime + ″\else\phys_units_text_doubleprime\fi\else\phys_units_text_doubleprime \fi} \unexpanded\def\checkedtextcelsius {\iffontchar\font"2103\relax\iffontchar\font"2109\relax - ℉\else\text_fallback_celsius\fi\else\text_fallback_celsius + ℉\else\phys_units_text_celsius\fi\else\phys_units_text_celsius \fi} \unexpanded\def\checkedtextfahrenheit {\iffontchar\font"2109\relax\iffontchar\font"2103\relax - ℉\else\text_fallback_fahrenheit\fi\else\text_fallback_fahrenheit + ℉\else\phys_units_text_fahrenheit\fi\else\phys_units_text_fahrenheit \fi} \setelementnature[unit] [mixed] \setelementnature[quantity][mixed] -\let\units_finish\relax +\let\phys_units_finish\relax \unexpanded\def\unitsNstart {\ifmmode \else - \settrue\c_units_quantity + \settrue\c_phys_units_quantity \dostarttagged\t!quantity\empty - \settrue\c_units_number + \settrue\c_phys_units_number \dostarttagged\t!number\empty \fi} \unexpanded\def\unitsNstop - {\ifconditional\c_units_number - \setfalse\c_units_number + {\ifconditional\c_phys_units_number + \setfalse\c_phys_units_number \dostoptagged \fi - \c_units_state\plusfive} + \c_phys_units_state\plusfive} \unexpanded\def\unitsNspace {\space} @@ -541,23 +545,23 @@ \unexpanded\def\unitsN#1% {\unitsNstart#1\unitsNstop} -\def\units_start +\def\phys_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} + \let\phys_units_finish\phys_units_stop + \let\phys_units_start\relax} -\def\units_stop - {\ifconditional\c_units_number - \setfalse\c_units_number +\def\phys_units_stop + {\ifconditional\c_phys_units_number + \setfalse\c_phys_units_number \dostoptagged \fi - \ifconditional\c_units_quantity - \setfalse\c_units_quantity + \ifconditional\c_phys_units_quantity + \setfalse\c_phys_units_quantity \dostoptagged \fi \dostoptagged @@ -566,7 +570,7 @@ \fi} \def\unitsraise - {\ifcase\c_units_mode + {\ifcase\c_phys_units_mode \expandafter\high \or \expandafter\normalsuperscript @@ -577,7 +581,7 @@ \fi} \def\unitslower - {\ifcase\c_units_mode + {\ifcase\c_phys_units_mode \expandafter\low \or \expandafter\normalsubscript @@ -587,44 +591,44 @@ \expandafter\normalsubscript \fi} -\unexpanded\def\units_next - {\ifcase\c_units_state % start - \ifconditional\c_units_dospace +\unexpanded\def\phys_units_next + {\ifcase\c_phys_units_state % start + \ifconditional\c_phys_units_dospace % \ifdim\lastskip=\zeropoint - \dounitsspace + \phys_units_space % \else % % too tricky ... we could remove and add % \fi \fi \or % 1: suffix - {\dounitsseparator}% + {\phys_units_separator}% \or % 2: operator \or % 3: unit - {\dounitsseparator}% + {\phys_units_separator}% \or % 4: prefix \or % 5: number - \dounitsspace + \phys_units_space \or % 6: symbol (connected) \fi - \setfalse\c_units_dospace - \units_start} + \setfalse\c_phys_units_dospace + \phys_units_start} \unexpanded\def\unitsTIMES - {\ifnum\c_units_state=\plusone % suffix + {\ifnum\c_phys_units_state=\plusone % suffix \else \unitssmallspace \fi \cdot} % or \times \unexpanded\def\unitsOUTOF - {\ifnum\c_units_state=\plusone % suffix + {\ifnum\c_phys_units_state=\plusone % suffix \else \unitssmallspace \fi :} \unexpanded\def\unitsSOLIDUS - {\ifnum\c_units_state=\plusone % suffix + {\ifnum\c_phys_units_state=\plusone % suffix \unitsbackspace \fi {/}% @@ -668,9 +672,9 @@ %D \stoptyping \unexpanded\def\registerunit - {\dodoubleempty\register_unit} + {\dodoubleempty\phys_units_register} -\def\register_unit[#1][#2]% +\def\phys_units_register[#1][#2]% {\ctxcommand{registerunit(\!!bs#1\!!es,\!!bs#2\!!es)}} %D You can generate a list as follows: |