[latex3-commits] [git/LaTeX3-latex3-latex3] master: Make juxtaposition with parentheses bind looser than without in l3fp (23c94a4)

Bruno Le Floch bruno at le-floch.fr
Tue May 28 07:37:54 CEST 2019


Repository : https://github.com/latex3/latex3
On branch  : master
Link       : https://github.com/latex3/latex3/commit/23c94a4ac42ea8192e80aeb3715105335be32dd1

>---------------------------------------------------------------

commit 23c94a4ac42ea8192e80aeb3715105335be32dd1
Author: Bruno Le Floch <bruno at le-floch.fr>
Date:   Tue May 28 07:37:54 2019 +0200

    Make juxtaposition with parentheses bind looser than without in l3fp
    
    This follows a long internal discussion.  This implements "option B1"
    in that discussion.


>---------------------------------------------------------------

23c94a4ac42ea8192e80aeb3715105335be32dd1
 l3kernel/CHANGELOG.md                   |    3 +-
 l3kernel/l3fp-parse.dtx                 |   48 +++++++++++++++++++++++++++----
 l3kernel/l3fp.dtx                       |   10 ++++---
 l3kernel/testfiles/m3expl001.luatex.tlg |    1 +
 l3kernel/testfiles/m3expl001.ptex.tlg   |    1 +
 l3kernel/testfiles/m3expl001.tlg        |    1 +
 l3kernel/testfiles/m3expl001.uptex.tlg  |    1 +
 l3kernel/testfiles/m3expl001.xetex.tlg  |    1 +
 l3kernel/testfiles/m3expl003.luatex.tlg |    1 +
 l3kernel/testfiles/m3expl003.ptex.tlg   |    1 +
 l3kernel/testfiles/m3expl003.tlg        |    1 +
 l3kernel/testfiles/m3expl003.uptex.tlg  |    1 +
 l3kernel/testfiles/m3expl003.xetex.tlg  |    1 +
 l3kernel/testfiles/m3fp-parse001.lvt    |   15 +++++++++-
 l3kernel/testfiles/m3fp-parse001.tlg    |   32 ++++++++++++++++++++-
 l3kernel/testfiles/m3fp-parse002.tlg    |    2 +-
 16 files changed, 107 insertions(+), 13 deletions(-)

diff --git a/l3kernel/CHANGELOG.md b/l3kernel/CHANGELOG.md
index 284a296..989abe5 100644
--- a/l3kernel/CHANGELOG.md
+++ b/l3kernel/CHANGELOG.md
@@ -11,9 +11,10 @@ this project uses date-based 'snapshot' version identifiers.
 
 - Experimental `\file_compare_timestamp:nNn(TF)`
 
-### Fixed
+### Changed
 
 - Precedence of juxtaposition (implicit multiplication) in l3fp
+  now different for keywords/variables and factors in parentheses
 
 ## [2019-05-09]
 
diff --git a/l3kernel/l3fp-parse.dtx b/l3kernel/l3fp-parse.dtx
index 6365d24..9634d4f 100644
--- a/l3kernel/l3fp-parse.dtx
+++ b/l3kernel/l3fp-parse.dtx
@@ -119,7 +119,7 @@
 %     \item[16] Function calls.
 %     \item[13/14] Binary |**| and~|^| (right to left).
 %     \item[12] Unary |+|, |-|, |!| (right to left).
-%     \item[11] Juxtaposition (implicit~|*|).
+%     \item[11] Juxtaposition (implicit~|*|) with no parenthesis.
 %     \item[10] Binary |*| and~|/|.
 %     \item[9] Binary |+| and~|-|.
 %     \item[7] Comparisons.
@@ -1949,7 +1949,7 @@
       {
         \exp_not:N \@@_exp_after_array_f:w #2 \s_@@_stop
         \exp_not:N \exp_after:wN
-        \exp_not:N \@@_parse_infix:NN
+        \exp_not:N \@@_parse_infix_after_paren:NN
         \exp_not:N \exp_after:wN #1
         \exp_not:N \exp:w
         \exp_not:N \@@_parse_expand:w
@@ -1984,7 +1984,7 @@
       \fi:
       \exp_end_continue_f:w
     \fi:
-    \@@_parse_infix:NN #1 )
+    \@@_parse_infix_after_paren:NN #1 )
   }
 %    \end{macrocode}
 % \end{macro}
@@ -2308,6 +2308,44 @@
 %    \end{macrocode}
 % \end{macro}
 %
+% \begin{macro}{\@@_parse_infix_after_paren:NN}
+%   Variant of \cs{@@_parse_infix:NN} for use after a closing
+%   parenthesis.  The only difference is that \cs{@@_parse_infix_juxt:N}
+%   is replaced by \cs{@@_parse_infix_mul:N}.
+%    \begin{macrocode}
+\cs_new:Npn \@@_parse_infix_after_paren:NN #1 #2
+  {
+    \if_catcode:w \scan_stop: \exp_not:N #2
+      \if_int_compare:w
+          \@@_str_if_eq:nn { \s_@@_mark } { \exp_not:N #2 }
+          = 0 \exp_stop_f:
+        \exp_after:wN \exp_after:wN
+        \exp_after:wN \@@_parse_infix_mark:NNN
+      \else:
+        \exp_after:wN \exp_after:wN
+        \exp_after:wN \@@_parse_infix_mul:N
+      \fi:
+    \else:
+      \if_int_compare:w
+          \@@_int_eval:w
+            ( `#2 \if_int_compare:w `#2 > `Z - 32 \fi: ) / 26
+          = 3 \exp_stop_f:
+        \exp_after:wN \exp_after:wN
+        \exp_after:wN \@@_parse_infix_mul:N
+      \else:
+        \exp_after:wN \@@_parse_infix_check:NNN
+        \cs:w
+          @@_parse_infix_ \token_to_str:N #2 :N
+          \exp_after:wN \exp_after:wN \exp_after:wN
+        \cs_end:
+      \fi:
+    \fi:
+    #1
+    #2
+  }
+%    \end{macrocode}
+% \end{macro}
+%
 % \subsubsection{Closing parentheses and commas}
 %
 % \begin{macro}[EXP]{\@@_parse_infix_mark:NNN}
@@ -2466,10 +2504,10 @@
 % \begin{macro}[EXP]+\@@_parse_infix_(:N+
 %   When an opening parenthesis appears where we expect an infix
 %   operator, we compute the product of the previous operand and the
-%   contents of the parentheses using \cs{@@_parse_infix_juxt:N}.
+%   contents of the parentheses using \cs{@@_parse_infix_mul:N}.
 %    \begin{macrocode}
 \cs_new:cpn { @@_parse_infix_(:N } #1
-  { \@@_parse_infix_juxt:N #1 ( }
+  { \@@_parse_infix_mul:N #1 ( }
 %    \end{macrocode}
 % \end{macro}
 %
diff --git a/l3kernel/l3fp.dtx b/l3kernel/l3fp.dtx
index d74cc5b..122f9a6 100644
--- a/l3kernel/l3fp.dtx
+++ b/l3kernel/l3fp.dtx
@@ -858,9 +858,9 @@
 %   \item Function calls (\texttt{sin}, \texttt{ln}, \emph{etc}).
 %   \item Binary |**| and |^| (right associative).
 %   \item Unary |+|, |-|, |!|.
-%   \item Implicit multiplication by juxtaposition
-%     (\texttt{2pi}, \texttt{3(4+5)}, \emph{etc}).
-%   \item Binary |*| and |/|.
+%   \item Implicit multiplication by juxtaposition (\texttt{2pi})
+%     when neither factor is in parentheses.
+%   \item Binary |*| and |/|, implicit multiplication by juxtaposition with parentheses (for instance \texttt{3(4+5)}).
 %   \item Binary |+| and |-|.
 %   \item Comparisons |>=|, |!=|, |<?|, \emph{etc}.
 %   \item Logical \texttt{and}, denoted by |&&|.
@@ -869,8 +869,10 @@
 %   \item Comma (to build tuples).
 % \end{itemize}
 % The precedence of operations can be overridden using parentheses.
-% In particular, those precedences imply that
+% In particular, the precedence of juxtaposition implies that
 % \begin{align*}
+%   \mathtt{1/2pi} & = 1/(2\pi), \\
+%   \mathtt{1/2pi(pi+pi)} & = (2\pi)^{-1}(\pi+\pi) \simeq 1, \\
 %   \mathtt{sin 2pi} & = \sin(2)\pi \neq 0, \\
 %   \mathtt{2\char`\^2max(3,5)} & = 2^2 \max(3,5) = 20, \\
 %   \mathtt{1in/1cm} & = (1in)/(1cm) = 2.54 .
diff --git a/l3kernel/testfiles/m3expl001.luatex.tlg b/l3kernel/testfiles/m3expl001.luatex.tlg
index 47db6ae..18760f8 100644
--- a/l3kernel/testfiles/m3expl001.luatex.tlg
+++ b/l3kernel/testfiles/m3expl001.luatex.tlg
@@ -3835,6 +3835,7 @@ Defining \__fp_binary_rev_type_o:Nww on line ...
 Defining \__fp_parse_infix_after_operand:NwN on line ...
 Defining \__fp_parse_infix:NN on line ...
 Defining \__fp_parse_infix_check:NNN on line ...
+Defining \__fp_parse_infix_after_paren:NN on line ...
 Defining \__fp_parse_infix_mark:NNN on line ...
 Defining \__fp_parse_infix_end:N on line ...
 Defining \__fp_parse_infix_):N on line ...
diff --git a/l3kernel/testfiles/m3expl001.ptex.tlg b/l3kernel/testfiles/m3expl001.ptex.tlg
index 2242e94..2745bc1 100644
--- a/l3kernel/testfiles/m3expl001.ptex.tlg
+++ b/l3kernel/testfiles/m3expl001.ptex.tlg
@@ -4089,6 +4089,7 @@ Defining \__fp_binary_rev_type_o:Nww on line ...
 Defining \__fp_parse_infix_after_operand:NwN on line ...
 Defining \__fp_parse_infix:NN on line ...
 Defining \__fp_parse_infix_check:NNN on line ...
+Defining \__fp_parse_infix_after_paren:NN on line ...
 Defining \__fp_parse_infix_mark:NNN on line ...
 Defining \__fp_parse_infix_end:N on line ...
 Defining \__fp_parse_infix_):N on line ...
diff --git a/l3kernel/testfiles/m3expl001.tlg b/l3kernel/testfiles/m3expl001.tlg
index 36a6f3a..3c51f7a 100644
--- a/l3kernel/testfiles/m3expl001.tlg
+++ b/l3kernel/testfiles/m3expl001.tlg
@@ -4089,6 +4089,7 @@ Defining \__fp_binary_rev_type_o:Nww on line ...
 Defining \__fp_parse_infix_after_operand:NwN on line ...
 Defining \__fp_parse_infix:NN on line ...
 Defining \__fp_parse_infix_check:NNN on line ...
+Defining \__fp_parse_infix_after_paren:NN on line ...
 Defining \__fp_parse_infix_mark:NNN on line ...
 Defining \__fp_parse_infix_end:N on line ...
 Defining \__fp_parse_infix_):N on line ...
diff --git a/l3kernel/testfiles/m3expl001.uptex.tlg b/l3kernel/testfiles/m3expl001.uptex.tlg
index 638d1bd..9c6cacd 100644
--- a/l3kernel/testfiles/m3expl001.uptex.tlg
+++ b/l3kernel/testfiles/m3expl001.uptex.tlg
@@ -4089,6 +4089,7 @@ Defining \__fp_binary_rev_type_o:Nww on line ...
 Defining \__fp_parse_infix_after_operand:NwN on line ...
 Defining \__fp_parse_infix:NN on line ...
 Defining \__fp_parse_infix_check:NNN on line ...
+Defining \__fp_parse_infix_after_paren:NN on line ...
 Defining \__fp_parse_infix_mark:NNN on line ...
 Defining \__fp_parse_infix_end:N on line ...
 Defining \__fp_parse_infix_):N on line ...
diff --git a/l3kernel/testfiles/m3expl001.xetex.tlg b/l3kernel/testfiles/m3expl001.xetex.tlg
index 7ec458d..eca036e 100644
--- a/l3kernel/testfiles/m3expl001.xetex.tlg
+++ b/l3kernel/testfiles/m3expl001.xetex.tlg
@@ -3833,6 +3833,7 @@ Defining \__fp_binary_rev_type_o:Nww on line ...
 Defining \__fp_parse_infix_after_operand:NwN on line ...
 Defining \__fp_parse_infix:NN on line ...
 Defining \__fp_parse_infix_check:NNN on line ...
+Defining \__fp_parse_infix_after_paren:NN on line ...
 Defining \__fp_parse_infix_mark:NNN on line ...
 Defining \__fp_parse_infix_end:N on line ...
 Defining \__fp_parse_infix_):N on line ...
diff --git a/l3kernel/testfiles/m3expl003.luatex.tlg b/l3kernel/testfiles/m3expl003.luatex.tlg
index 47db6ae..18760f8 100644
--- a/l3kernel/testfiles/m3expl003.luatex.tlg
+++ b/l3kernel/testfiles/m3expl003.luatex.tlg
@@ -3835,6 +3835,7 @@ Defining \__fp_binary_rev_type_o:Nww on line ...
 Defining \__fp_parse_infix_after_operand:NwN on line ...
 Defining \__fp_parse_infix:NN on line ...
 Defining \__fp_parse_infix_check:NNN on line ...
+Defining \__fp_parse_infix_after_paren:NN on line ...
 Defining \__fp_parse_infix_mark:NNN on line ...
 Defining \__fp_parse_infix_end:N on line ...
 Defining \__fp_parse_infix_):N on line ...
diff --git a/l3kernel/testfiles/m3expl003.ptex.tlg b/l3kernel/testfiles/m3expl003.ptex.tlg
index 2242e94..2745bc1 100644
--- a/l3kernel/testfiles/m3expl003.ptex.tlg
+++ b/l3kernel/testfiles/m3expl003.ptex.tlg
@@ -4089,6 +4089,7 @@ Defining \__fp_binary_rev_type_o:Nww on line ...
 Defining \__fp_parse_infix_after_operand:NwN on line ...
 Defining \__fp_parse_infix:NN on line ...
 Defining \__fp_parse_infix_check:NNN on line ...
+Defining \__fp_parse_infix_after_paren:NN on line ...
 Defining \__fp_parse_infix_mark:NNN on line ...
 Defining \__fp_parse_infix_end:N on line ...
 Defining \__fp_parse_infix_):N on line ...
diff --git a/l3kernel/testfiles/m3expl003.tlg b/l3kernel/testfiles/m3expl003.tlg
index 36a6f3a..3c51f7a 100644
--- a/l3kernel/testfiles/m3expl003.tlg
+++ b/l3kernel/testfiles/m3expl003.tlg
@@ -4089,6 +4089,7 @@ Defining \__fp_binary_rev_type_o:Nww on line ...
 Defining \__fp_parse_infix_after_operand:NwN on line ...
 Defining \__fp_parse_infix:NN on line ...
 Defining \__fp_parse_infix_check:NNN on line ...
+Defining \__fp_parse_infix_after_paren:NN on line ...
 Defining \__fp_parse_infix_mark:NNN on line ...
 Defining \__fp_parse_infix_end:N on line ...
 Defining \__fp_parse_infix_):N on line ...
diff --git a/l3kernel/testfiles/m3expl003.uptex.tlg b/l3kernel/testfiles/m3expl003.uptex.tlg
index 638d1bd..9c6cacd 100644
--- a/l3kernel/testfiles/m3expl003.uptex.tlg
+++ b/l3kernel/testfiles/m3expl003.uptex.tlg
@@ -4089,6 +4089,7 @@ Defining \__fp_binary_rev_type_o:Nww on line ...
 Defining \__fp_parse_infix_after_operand:NwN on line ...
 Defining \__fp_parse_infix:NN on line ...
 Defining \__fp_parse_infix_check:NNN on line ...
+Defining \__fp_parse_infix_after_paren:NN on line ...
 Defining \__fp_parse_infix_mark:NNN on line ...
 Defining \__fp_parse_infix_end:N on line ...
 Defining \__fp_parse_infix_):N on line ...
diff --git a/l3kernel/testfiles/m3expl003.xetex.tlg b/l3kernel/testfiles/m3expl003.xetex.tlg
index 7ec458d..eca036e 100644
--- a/l3kernel/testfiles/m3expl003.xetex.tlg
+++ b/l3kernel/testfiles/m3expl003.xetex.tlg
@@ -3833,6 +3833,7 @@ Defining \__fp_binary_rev_type_o:Nww on line ...
 Defining \__fp_parse_infix_after_operand:NwN on line ...
 Defining \__fp_parse_infix:NN on line ...
 Defining \__fp_parse_infix_check:NNN on line ...
+Defining \__fp_parse_infix_after_paren:NN on line ...
 Defining \__fp_parse_infix_mark:NNN on line ...
 Defining \__fp_parse_infix_end:N on line ...
 Defining \__fp_parse_infix_):N on line ...
diff --git a/l3kernel/testfiles/m3fp-parse001.lvt b/l3kernel/testfiles/m3fp-parse001.lvt
index 174f2bf..4e8b74e 100644
--- a/l3kernel/testfiles/m3fp-parse001.lvt
+++ b/l3kernel/testfiles/m3fp-parse001.lvt
@@ -1,5 +1,5 @@
 %
-% Copyright (C) 2011-2012, 2014,2018 LaTeX3 Project
+% Copyright (C) 2011-2012, 2014,2018,2019 LaTeX3 Project
 %
 
 \documentclass{minimal}
@@ -118,12 +118,25 @@
   }
 
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+\dim_set:Nn \l_tmpa_dim { 1in }
 \TESTEXP { Juxtaposition~and~precedence }
   {
+    \fp_to_tl:n { in , mm } \NEWLINE
     \fp_to_tl:n { sin 2 pi } \NEWLINE
     \fp_to_tl:n { sin 2 \c_pi_fp } \NEWLINE
+    \fp_to_tl:n { round 2.2 \l_tmpa_dim (pi) } \NEWLINE
     \fp_to_tl:n { 2 ^ 2 max(3, 4) } \NEWLINE
     \fp_to_tl:n { 2 / 4 (5 - 1) } \NEWLINE
+    \fp_to_tl:n { 1 / 2 pi } \NEWLINE
+    \fp_to_tl:n { 1 / 2 (pi) } \NEWLINE
+    \fp_to_tl:n { 1 / (2) pi } \NEWLINE
+    \fp_to_tl:n { 1 / (2) (pi) } \NEWLINE
+    \fp_to_tl:n { 1 / 2 in } \NEWLINE
+    \fp_to_tl:n { 1 / 2 (in) } \NEWLINE
+    \fp_to_tl:n { 1 / (2) in } \NEWLINE
+    \fp_to_tl:n { 1 / (2) (in) } \NEWLINE
+    \fp_to_tl:n { 1 / 2 pi (pi + pi) } \NEWLINE
+    \fp_to_tl:n { 1 / () pi^(2,) } \NEWLINE
   }
 
 \END
diff --git a/l3kernel/testfiles/m3fp-parse001.tlg b/l3kernel/testfiles/m3fp-parse001.tlg
index 853dd0b..38977e3 100644
--- a/l3kernel/testfiles/m3fp-parse001.tlg
+++ b/l3kernel/testfiles/m3fp-parse001.tlg
@@ -330,8 +330,38 @@ TEST 9: Exponent and minus
 ============================================================
 TEST 10: Juxtaposition and precedence
 ============================================================
+! Undefined control sequence.
+<argument> \LaTeX3 error: 
+                           Invalid operation (1)/(())
+l. ...  }
+The control sequence at the end of the top line
+of your error message was never \def'ed. If you have
+misspelled it (e.g., `\hobx'), type `I' and the correct
+spelling (e.g., `I\hbox'). Otherwise just continue,
+and I'll forget about whatever was undefined.
+! Undefined control sequence.
+<argument> \LaTeX3 error: 
+                           Invalid operation (3.141592653589793)^((2,))
+l. ...  }
+The control sequence at the end of the top line
+of your error message was never \def'ed. If you have
+misspelled it (e.g., `\hobx'), type `I' and the correct
+spelling (e.g., `I\hbox'). Otherwise just continue,
+and I'll forget about whatever was undefined.
+(72.27, 2.845275590551181)
 2.856642116043664
 2.856642116043664
+454.0857331207334
 16
-0.125
+2
+0.1591549430918953
+1.570796326794896
+1.570796326794896
+1.570796326794896
+0.006918500069185001
+36.135
+36.135
+36.135
+0.9999999999999997
+nan
 ============================================================
diff --git a/l3kernel/testfiles/m3fp-parse002.tlg b/l3kernel/testfiles/m3fp-parse002.tlg
index 80c7c9b..9cb2740 100644
--- a/l3kernel/testfiles/m3fp-parse002.tlg
+++ b/l3kernel/testfiles/m3fp-parse002.tlg
@@ -349,7 +349,7 @@ spelling (e.g., `I\hbox'). Otherwise just continue,
 and I'll forget about whatever was undefined.
 ! Undefined control sequence.
 <argument> \LaTeX3 error: 
-                           Invalid operation ((1,))*((0,))
+                           Invalid operation ((0,))*((2,))
 l. ...  }
 The control sequence at the end of the top line
 of your error message was never \def'ed. If you have





More information about the latex3-commits mailing list