From 6268e0974f70b379890285a94cbb6d539cf00119 Mon Sep 17 00:00:00 2001
From: Karl Berry <karl@freefriends.org>
Date: Fri, 28 Jan 2011 01:51:41 +0000
Subject: siunitx 2.1i (27jan11)

git-svn-id: svn://tug.org/texlive/trunk@21198 c570f23f-e606-0410-a88d-b1316a301751
---
 Master/texmf-dist/source/latex/siunitx/siunitx.dtx | 206 ++++++++++++++-------
 1 file changed, 135 insertions(+), 71 deletions(-)

(limited to 'Master/texmf-dist/source/latex/siunitx/siunitx.dtx')

diff --git a/Master/texmf-dist/source/latex/siunitx/siunitx.dtx b/Master/texmf-dist/source/latex/siunitx/siunitx.dtx
index 4155a8f510f..c2e5f97ca03 100644
--- a/Master/texmf-dist/source/latex/siunitx/siunitx.dtx
+++ b/Master/texmf-dist/source/latex/siunitx/siunitx.dtx
@@ -526,6 +526,8 @@ This work consists of the file  siunitx.dtx
 %\changes{v2.1g}{2010/12/21}{Checks on the versions of \pkg{expl3} and
 %  \pkg{xparse} installed}
 %\changes{v2.1h}{2011/01/18}{Detect AMS display-like environments}
+%\changes{v2.1i}{2011/01/27}{Improved logic for
+% \opt{per-mode} setting \opt{symbol-or-fraction}}
 %  
 %\begin{abstract}
 % Typesetting values with units requires care to ensure that the
@@ -2558,19 +2560,23 @@ This work consists of the file  siunitx.dtx
 %  \si[per-mode=repeated-symbol]{\joule\per\mole\per\kelvin}
 %\end{LaTeXdemo}
 % Finally, it is possible for the behaviour of the \cs{per} function
-% to depend on the surrounding environment. Setting the option to
-% \opt{symbol-or-fraction}, causes the same behaviour as
-% \opt{symbol} when the surroundings are in line, and the same 
-% behaviour as \opt{fraction} when in a display context.\footnote{Here,
-% \enquote{display} means either typeset in \TeX's display math mode or
-% using the AMS display-like environments. Simply using 
-% \cs{displaystyle} will not make otherwise in line math be detected as
-% display material.}
+% to depend on the prevailing math style. Setting \opt{per-mode} to
+% \opt{symbol-or-fraction} will use the \opt{symbol} setting for
+% in line math, and the \opt{fraction} setting when used in
+% \cs{displaystyle} math.
 %\begin{LaTeXdemo}
 %  \sisetup{per-mode = symbol-or-fraction}%
 %  \( \si{\joule\per\mole\per\kelvin} \) 
 %  \[ \si{\joule\per\mole\per\kelvin} \]
-%     \si{\joule\per\mole\per\kelvin} 
+%     \si{\joule\per\mole\per\kelvin} \\
+%  \( 
+%    \displaystyle 
+%    \si{\joule\per\mole\per\kelvin}
+%  \)
+%  \[ 
+%    \textstyle 
+%    \si{\joule\per\mole\per\kelvin}
+%  \]
 %\end{LaTeXdemo}
 % 
 %\DescribeOption{sticky-per}
@@ -2860,7 +2866,7 @@ This work consists of the file  siunitx.dtx
 %      S[table-number-alignment = right]
 %    }
 %    \toprule
-%    *4 {Some Values} \\
+%    {Some Values} & {Some Values} & {Some Values} & {Some Values} \\
 %    \midrule
 %       2.3456  &  2.3456  &  2.3456 &  2.3456 \\
 %      34.2345  & 34.2345  & 34.2345 & 34.2345 \\
@@ -2916,7 +2922,12 @@ This work consists of the file  siunitx.dtx
 %      S[table-figures-exponent = 1]
 %      }
 %    \toprule
-%      *6  {Values} \\
+%        {Values}
+%      & {Values}
+%      & {Values}
+%      & {Values}
+%      & {Values}
+%      & {Values} \\
 %    \midrule
 %       2.3  &  2.3  &  2.3(5)  &  2.3(5)  &   2.3  &  2.3e8  \\
 %      34.23 & 34.23 & 34.23(4) & 34.23(4) &  34.23 & 34.23   \\
@@ -2946,7 +2957,8 @@ This work consists of the file  siunitx.dtx
 %      S[table-comparator = true]
 %      }
 %    \toprule
-%      *2 {Values} \\
+%        {Values}
+%      & {Values} \\
 %    \midrule
 %       2.3  & <   2.3e8  \\
 %      34.23 & =  34.23   \\
@@ -3015,7 +3027,11 @@ This work consists of the file  siunitx.dtx
 %      S[table-format =  2.2e1]
 %      }
 %    \toprule
-%      *5 {Values} \\
+%        {Values}
+%      & {Values}
+%      & {Values}
+%      & {Values}
+%      & {Values} \\
 %    \midrule
 %       2.3  &  2.3  &  2.3(5)  &   2.3  &  2.3e8  \\
 %      34.23 & 34.23 & 34.23(4) &  34.23 & 34.23   \\
@@ -3158,7 +3174,7 @@ This work consists of the file  siunitx.dtx
 %      S[table-align-text-post = false]
 %    }
 %    \toprule
-%      *2 {Values} \\
+%      {Values}             & {Values} \\
 %    \midrule
 %       2.3456              & 2.3456 \\
 %      34.234  \NoteMark{a} & 34.234 \NoteMark{a} \\
@@ -3263,7 +3279,9 @@ This work consists of the file  siunitx.dtx
 %      S[table-text-alignment = right]
 %      }
 %    \toprule
-%      *3 {Values} \\
+%        {Values}
+%      & {Values}
+%      & {Values} \\
 %    \midrule
 %      992.435  &  992.435  &  992.435  \\
 %     7734.2344 & 7734.2344 & 7734.2344 \\
@@ -4405,7 +4423,7 @@ This work consists of the file  siunitx.dtx
 %
 % The usual preliminaries.  
 %    \begin{macrocode}
-\ProvidesExplPackage {siunitx} {2011/01/18} {2.1h}
+\ProvidesExplPackage {siunitx} {2011/01/27} {2.1i}
   {A comprehensive (SI) units package}
 %    \end{macrocode}
 % 
@@ -4912,38 +4930,15 @@ This work consists of the file  siunitx.dtx
 %    \end{macrocode}
 %\end{macro}
 %
-%\begin{macro}{\siunitx_if_display_math_p:}
-%\begin{macro}[TF]{\siunitx_if_display_math:}
-% The AMS display environments are not actually in display mode, so
-% there needs to be some code to pick this up.
+%\begin{macro}{\l_siunitx_display_math_bool}
+% To test for display math, a flag is added to the start of every
+% display environment.
 %    \begin{macrocode}
-\prg_new_conditional:Npnn \siunitx_if_display_math: { T , F ,  TF , p } 
-  {
-    \mode_if_inner:TF
-      { \prg_return_false: }
-      { \prg_return_true: }
-}
-\AtBeginDocument {
-  \cs_if_exist:NT \if@display
-    {
-      \prg_set_conditional:Npnn \siunitx_if_display_math: 
-        { T , F ,  TF , p } 
-        {
-          \mode_if_inner:TF
-            { 
-              \if@display
-                \prg_return_true:
-              \tex_else:D
-                \prg_return_false:
-              \tex_fi:D
-            }
-            { \prg_return_true: }
-        }    
-    }    
-}
+\bool_new:N \l_siunitx_display_math_bool
+\toks_put_right:Nn \tex_everydisplay:D 
+  { \bool_set_true:N \l_siunitx_display_math_bool }
 %    \end{macrocode}
 %\end{macro}
-%\end{macro}
 %
 %\subsection{Font detection}
 %
@@ -5159,7 +5154,7 @@ This work consists of the file  siunitx.dtx
 \cs_new_protected_nopar:Npn \siunitx_detect_font_weight: {
   \mode_if_math:TF 
     {
-      \siunitx_if_display_math:TF
+      \bool_if:NTF \l_siunitx_display_math_bool
         {
           \bool_if:NTF \l_siunitx_detect_display_math_bool 
             { \siunitx_detect_font_weight_math: }
@@ -5232,9 +5227,9 @@ This work consists of the file  siunitx.dtx
   \siunitx_detect_font_family_text:
   \mode_if_math:T
     {
-      \bool_if:NT \l_siunitx_detect_display_math_bool
+      \bool_if:NT \l_siunitx_display_math_bool
         {
-          \siunitx_if_display_math:T
+          \bool_if:NT \l_siunitx_detect_display_math_bool
             { \siunitx_detect_font_family_math: }
         }
     }
@@ -10106,18 +10101,6 @@ This work consists of the file  siunitx.dtx
                 { \siunitx_unit_format_literal:n {#1} }
             }
             {
-              \bool_if:NT \l_siunitx_per_auto_bool
-                {
-                  \tl_set:Nn \l_siunitx_per_mode_tl { symbol }
-                  \mode_if_math:T
-                    {
-                      \siunitx_if_display_math:T
-                        {
-                          \tl_set:Nn \l_siunitx_per_mode_tl 
-                            { fraction }
-                        }
-                    }
-                }
               \cs_set_eq:NN \siunitx_pm: \pm  
               \siunitx_unit_parse:nn {#1} {#2}
               \siunitx_unit_format:
@@ -10423,6 +10406,14 @@ This work consists of the file  siunitx.dtx
 %    \end{macrocode}
 %\end{macro}
 %
+%\begin{macro}{\l_siunitx_omit_unit_space_bool}
+% Needed to omit the space between a number an a unit when printing
+% symbols and when there is no numerator unit.
+%    \begin{macrocode}
+\bool_new:N \l_siunitx_omit_unit_space_bool
+%    \end{macrocode}
+%\end{macro}
+%
 %\begin{macro}{\l_siunitx_per_auto_bool}
 %\begin{macro}{\l_siunitx_per_fraction_bool}
 %\begin{macro}{\l_siunitx_per_mode_tl}
@@ -10498,6 +10489,7 @@ This work consists of the file  siunitx.dtx
       \bool_set_true:N \l_siunitx_per_auto_bool
       \bool_set_true:N \l_siunitx_per_fraction_bool
       \bool_set_true:N \l_siunitx_per_two_parts_bool
+      \tl_set:Nn \l_siunitx_per_mode_tl { symbol }
     },
   per-symbol           .tl_set:N  = \l_siunitx_per_symbol_tl,
   power-font           .choice:,
@@ -10542,7 +10534,7 @@ This work consists of the file  siunitx.dtx
       \str_if_eq:VnT \l_siunitx_per_mode_tl { symbol }
         {
           \prop_if_in:NnT \l_siunitx_unit_prop { per-1 }
-            { \tl_clear:N \l_siunitx_number_unit_separator_tl }
+            { \bool_set_true:N \l_siunitx_omit_unit_space_bool }
         }
     }
   \int_while_do:nNnn { \l_siunitx_unit_int } > { 0 }
@@ -10614,6 +10606,7 @@ This work consists of the file  siunitx.dtx
 %
 %\begin{macro}{\siunitx_unit_format_fraction:}
 %\begin{macro}[aux]{\siunitx_unit_format_fraction:}
+%\begin{macro}[aux]{\siunitx_unit_format_auto:}
 %\begin{macro}[aux]{\siunitx_unit_format_symbol:}
 %\begin{macro}[aux]{\siunitx_unit_format_symbol_aux:}
 %\begin{macro}[aux]{\siunitx_unit_format_symbol_aux_alt:}
@@ -10624,8 +10617,12 @@ This work consists of the file  siunitx.dtx
 \cs_new_protected_nopar:Npn \siunitx_unit_format_fraction: {
   \int_compare:nNnTF { \l_siunitx_unit_denominator_int } > { 0 } 
     {
-      \use:c 
-        { siunitx_unit_format_fraction_ \l_siunitx_per_mode_tl : }
+      \bool_if:NTF \l_siunitx_per_auto_bool
+        { \siunitx_unit_format_fraction_auto: }
+        {
+          \use:c 
+            { siunitx_unit_format_fraction_ \l_siunitx_per_mode_tl : }
+        }
     }
     { \tl_set_eq:NN \l_siunitx_unit_tl \l_siunitx_unit_numerator_tl }
 } 
@@ -10650,6 +10647,47 @@ This work consists of the file  siunitx.dtx
   \tl_set:Nx \l_siunitx_unit_tl 
     { \exp_not:N \ensuremath { \exp_not:V \l_siunitx_unit_tl } }
 } 
+%    \end{macrocode}
+% For the \opt{symbol} setting, there is a need to deal with the
+% possible \opt{symbol-or-fraction} choice. That is achieved by
+% setting up both the \opt{fraction} and \opt{symbol} output.
+% In the automatic mode, both cases are combined inside a 
+% \cs{tex_mathchoice:D}, with appropriate protection, before sending
+% everything through for printing.
+%    \begin{macrocode}
+\cs_new_protected_nopar:Npn \siunitx_unit_format_fraction_auto: {
+    \mode_if_math:TF
+      {
+        \group_begin:
+          \siunitx_unit_format_fraction_fraction:
+        \exp_args:NNNV \group_end:
+        \tl_set:Nn \l_siunitx_tmpa_tl \l_siunitx_unit_tl
+        \group_begin:
+          \siunitx_unit_format_fraction_symbol:
+        \exp_args:NNNV \group_end:
+        \tl_set:Nn \l_siunitx_tmpb_tl \l_siunitx_unit_tl
+        \tl_set:Nx \l_siunitx_tmpb_tl
+          {
+            \siunitx_print:nn { unit } 
+              { \exp_not:V \l_siunitx_tmpb_tl }
+          }
+        \tl_set:Nx \l_siunitx_unit_tl
+          {
+            \exp_not:N \ensuremath {
+              \tex_mathchoice:D
+                { \exp_not:V \l_siunitx_tmpa_tl }
+                { \exp_not:V \l_siunitx_tmpb_tl }
+                { \exp_not:V \l_siunitx_tmpb_tl }
+                { \exp_not:V \l_siunitx_tmpb_tl }
+              }
+          }
+      }
+      { \siunitx_unit_format_fraction_symbol: }
+}
+%    \end{macrocode}
+% For a normal symbol, the two parts of the input are arranged either
+% side of the symbol itself in math mode.
+%    \begin{macrocode}
 \cs_new_protected_nopar:Npn \siunitx_unit_format_fraction_symbol: {
   \siunitx_unit_format_fraction_symbol_aux:
   \int_compare:nNnT { \l_siunitx_unit_denominator_int } > { 1 }
@@ -10667,8 +10705,8 @@ This work consists of the file  siunitx.dtx
     \l_siunitx_per_symbol_tl
   \tl_put_right:NV \l_siunitx_unit_tl \l_siunitx_unit_denominator_tl
 }
-\cs_new_protected_nopar:Npn \siunitx_unit_format_fraction_symbol_aux: {
-}
+\cs_new_protected_nopar:Npn 
+  \siunitx_unit_format_fraction_symbol_aux: { }
 \cs_new_protected_nopar:Npn 
   \siunitx_unit_format_fraction_symbol_aux_alt: {
   \tl_if_empty:NT \l_siunitx_unit_numerator_tl 
@@ -10680,11 +10718,13 @@ This work consists of the file  siunitx.dtx
 %\end{macro}
 %\end{macro}
 %\end{macro}
+%\end{macro}
 %
 %\begin{macro}{\siunitx_unit_format_init:}
 % The normal initialisation stuff.
 %    \begin{macrocode}
 \cs_new_protected_nopar:Npn \siunitx_unit_format_init: {
+  \bool_set_false:N \l_siunitx_omit_unit_space_bool
   \tl_clear:N \l_siunitx_unit_tl
   \tl_clear:N \l_siunitx_unit_current_tl
   \tl_clear:N \l_siunitx_unit_denominator_tl
@@ -11217,7 +11257,7 @@ This work consists of the file  siunitx.dtx
 \cs_new_protected:Npn \siunitx_unit_output:nn #1#2 {
   \cs_set_eq:NN \siunitx_unit_format_symbol_aux: 
     \siunitx_unit_format_symbol_aux_alt:
-  \cs_set_eq:NN \siunitx_unit_format_fraction_symbol_aux: 
+  \cs_set_eq:NN \siunitx_unit_format_fraction_symbol_aux_ii: 
     \siunitx_unit_format_fraction_symbol_aux_alt:
   \siunitx_unit_in:nn {#1} {#2}
   \int_compare:nNnF { \l_siunitx_unit_prefix_int } = { 0 } 
@@ -11238,15 +11278,39 @@ This work consists of the file  siunitx.dtx
 %\end{macro} 
 %
 %\begin{macro}{\siunitx_unit_output_number_sep:}
-% For printing the number separator.
+%\begin{macro}{\siunitx_unit_output_number_sep_aux:}
+% For printing the number separator. The \cs{tex_mathchoice:D} code
+% deals with the \opt{symbol-or-fraction} setting for \opt{per-mode},
+% as in that case omission of the space between a number and unit
+% depends on the current math style.
 %    \begin{macrocode}
 \cs_new_protected_nopar:Npn \siunitx_unit_output_number_sep: {
   \bool_if:NTF \l_siunitx_number_unit_breaks_bool 
-    { \penalty \binoppenalty } { \nobreak }    
-  \siunitx_ensuremath:n { \l_siunitx_number_unit_separator_tl }
+    { \penalty \binoppenalty } { \nobreak }
+  \bool_if:NTF \l_siunitx_per_auto_bool
+    {
+      \mode_if_math:TF
+        {
+          \ensuremath
+            {
+              \tex_mathchoice:D
+                { \l_siunitx_number_unit_separator_tl } 
+                { \siunitx_unit_output_number_sep_aux: }
+                { \siunitx_unit_output_number_sep_aux: }
+                { \siunitx_unit_output_number_sep_aux: }
+            }
+        }
+        { \siunitx_unit_output_number_sep_aux: }
+    }
+    { \siunitx_unit_output_number_sep_aux: }
+}
+\cs_new_protected_nopar:Npn \siunitx_unit_output_number_sep_aux: {
+  \bool_if:NF \l_siunitx_omit_unit_space_bool
+    { \siunitx_ensuremath:n { \l_siunitx_number_unit_separator_tl } }
 }
 %    \end{macrocode}
 %\end{macro}
+%\end{macro}
 %
 %\begin{macro}{\siunitx_unit_output_pre_print:}
 %\begin{macro}{\siunitx_unit_output_print:}
@@ -14492,7 +14556,7 @@ This work consists of the file  siunitx.dtx
 %    \end{macrocode}
 %    
 %    \begin{macrocode}
-\ProvidesExplFile {siunitx-version-1.cfg} {2011/01/18} {2.1h} 
+\ProvidesExplFile {siunitx-version-1.cfg} {2011/01/27} {2.1i} 
   {siunitx: Version 1 settings}
 %    \end{macrocode}
 %    
@@ -15773,7 +15837,7 @@ This work consists of the file  siunitx.dtx
 %    \end{macrocode}  
 %    
 %    \begin{macrocode}
-\ProvidesExplFile {siunitx-binary.cfg} {2011/01/18} {2.1h}
+\ProvidesExplFile {siunitx-binary.cfg} {2011/01/27} {2.1i}
   {siunitx: Binary units}
 %    \end{macrocode}
 %    
-- 
cgit v1.2.3

