[latex3-commits] [git/LaTeX3-latex3-latex3] master: Make \infty and \pi into errors in fp expressions (fixes #357) (c0481e8)
Bruno Le Floch
bruno at le-floch.fr
Mon Apr 30 05:45:39 CEST 2018
Repository : https://github.com/latex3/latex3
On branch : master
Link : https://github.com/latex3/latex3/commit/c0481e8c3c3bee77d85b54afd52b9364965dcd52
>---------------------------------------------------------------
commit c0481e8c3c3bee77d85b54afd52b9364965dcd52
Author: Bruno Le Floch <bruno at le-floch.fr>
Date: Sun Apr 29 23:35:17 2018 -0400
Make \infty and \pi into errors in fp expressions (fixes #357)
I couldn't find a good way to distinguish them so I took a bad way:
systematically compare every register that comes into fp expressions
with \infty and with \pi.
>---------------------------------------------------------------
c0481e8c3c3bee77d85b54afd52b9364965dcd52
l3kernel/l3fp-parse.dtx | 41 +++++++++++++++++++++++++++----
l3kernel/l3fp.dtx | 5 ++++
l3kernel/testfiles/m3expl001.luatex.tlg | 3 +++
l3kernel/testfiles/m3expl001.ptex.tlg | 3 +++
l3kernel/testfiles/m3expl001.tlg | 3 +++
l3kernel/testfiles/m3expl001.uptex.tlg | 3 +++
l3kernel/testfiles/m3expl001.xetex.tlg | 3 +++
l3kernel/testfiles/m3expl003.luatex.tlg | 3 +++
l3kernel/testfiles/m3expl003.ptex.tlg | 3 +++
l3kernel/testfiles/m3expl003.tlg | 3 +++
l3kernel/testfiles/m3expl003.uptex.tlg | 3 +++
l3kernel/testfiles/m3expl003.xetex.tlg | 3 +++
l3kernel/testfiles/m3fp-parse002.lvt | 5 ++++
l3kernel/testfiles/m3fp-parse002.tlg | 23 +++++++++++++++++
14 files changed, 99 insertions(+), 5 deletions(-)
diff --git a/l3kernel/l3fp-parse.dtx b/l3kernel/l3fp-parse.dtx
index ae1e856..a49aba6 100644
--- a/l3kernel/l3fp-parse.dtx
+++ b/l3kernel/l3fp-parse.dtx
@@ -831,8 +831,6 @@
% \@@_parse_one_register_int:www,
% \@@_parse_one_register_mu:www,
% \@@_parse_one_register_dim:ww,
-% \@@_parse_one_register_wd:w,
-% \@@_parse_one_register_wd:Nw,
% }
% This is called whenever~|#2| is a control sequence other than
% \cs{scan_stop:} in meaning. We special-case \tn{wd}, \tn{ht}, \tn{dp}
@@ -856,9 +854,7 @@
\exp_after:wN \@@_parse_infix_after_operand:NwN
\exp_after:wN #1
\exp:w \exp_end_continue_f:w
- \if_meaning:w \box_wd:N #2 \@@_parse_one_register_wd:w \fi:
- \if_meaning:w \box_ht:N #2 \@@_parse_one_register_wd:w \fi:
- \if_meaning:w \box_dp:N #2 \@@_parse_one_register_wd:w \fi:
+ \@@_parse_one_register_special:N #2
\exp_after:wN \@@_parse_one_register_aux:Nw
\exp_after:wN #2
\int_value:w
@@ -895,12 +891,45 @@
\int_value:w \dim_to_decimal_in_sp:n { #1 pt } ;
}
% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}
+% {
+% \@@_parse_one_register_special:N,
+% \@@_parse_one_register_math:NNw,
+% \@@_parse_one_register_wd:w,
+% \@@_parse_one_register_wd:Nw
+% }
% The \tn{wd}, \tn{dp}, \tn{ht} primitives expect an integer argument.
% We abuse the exponent parser to find the integer argument: simply
% include the exponent marker~|e|. Once that \enquote{exponent} is
% found, use \cs{tex_the:D} to find the box dimension and then copy
% what we did for dimensions.
% \begin{macrocode}
+\cs_new:Npn \@@_parse_one_register_special:N #1
+ {
+ \if_meaning:w \box_wd:N #1 \@@_parse_one_register_wd:w \fi:
+ \if_meaning:w \box_ht:N #1 \@@_parse_one_register_wd:w \fi:
+ \if_meaning:w \box_dp:N #1 \@@_parse_one_register_wd:w \fi:
+ \if_meaning:w \infty #1
+ \@@_parse_one_register_math:NNw \infty #1
+ \fi:
+ \if_meaning:w \pi #1
+ \@@_parse_one_register_math:NNw \pi #1
+ \fi:
+ }
+\cs_new:Npn \@@_parse_one_register_math:NNw
+ #1#2#3#4 \@@_parse_expand:w
+ {
+ #3
+ \str_if_eq:nnTF {#1} {#2}
+ {
+ \__kernel_msg_expandable_error:nnn
+ { kernel } { fp-infty-pi } {#1}
+ \c_nan_fp
+ }
+ { #4 \@@_parse_expand:w }
+ }
\cs_new:Npn \@@_parse_one_register_wd:w
#1#2 \exp_after:wN #3#4 \@@_parse_expand:w
{
@@ -2921,6 +2950,8 @@
{ #1~expects~between~#2~and~#3~arguments. }
\__kernel_msg_new:nnn { kernel } { fp-bad-args }
{ Arguments~in~#1#2~are~invalid. }
+\__kernel_msg_new:nnn { kernel } { fp-infty-pi }
+ { Math~command~#1 is~not~an~fp }
%<*package>
\cs_if_exist:cT { @unexpandable at protect }
{
diff --git a/l3kernel/l3fp.dtx b/l3kernel/l3fp.dtx
index ac58162..43ae0c1 100644
--- a/l3kernel/l3fp.dtx
+++ b/l3kernel/l3fp.dtx
@@ -828,6 +828,11 @@
% preceded by any sign, but that sign is ignored.
% \item Any unrecognizable string triggers an error, and produces a
% \nan{}.
+% \item Note that commands such as \tn{infty}, \tn{pi}, or \tn{sin}
+% \emph{do not} work in floating point expressions. They may
+% silently be interpreted as completely unexpected numbers, because
+% integer constants (allowed in expressions) are commonly stored as
+% mathematical characters.
% \end{itemize}
%
% \subsection{Precedence of operators}
diff --git a/l3kernel/testfiles/m3expl001.luatex.tlg b/l3kernel/testfiles/m3expl001.luatex.tlg
index 05f4e29..6a580e9 100644
--- a/l3kernel/testfiles/m3expl001.luatex.tlg
+++ b/l3kernel/testfiles/m3expl001.luatex.tlg
@@ -3564,6 +3564,8 @@ Defining \__fp_parse_one_register_auxii:wwwNw on line ...
Defining \__fp_parse_one_register_mu:www on line ...
Defining \__fp_parse_one_register_int:www on line ...
Defining \__fp_parse_one_register_dim:ww on line ...
+Defining \__fp_parse_one_register_special:N on line ...
+Defining \__fp_parse_one_register_math:NNw on line ...
Defining \__fp_parse_one_register_wd:w on line ...
Defining \__fp_parse_one_register_wd:Nw on line ...
Defining \__fp_parse_one_digit:NN on line ...
@@ -3711,6 +3713,7 @@ Defining message LaTeX/kernel/fp-no-arg on line ...
Defining message LaTeX/kernel/fp-multi-arg on line ...
Defining message LaTeX/kernel/fp-num-args on line ...
Defining message LaTeX/kernel/fp-bad-args on line ...
+Defining message LaTeX/kernel/fp-infty-pi on line ...
Defining message LaTeX/kernel/fp-robust-cmd on line ...
Defining \fp_new:N on line ...
Defining \fp_new:c on line ...
diff --git a/l3kernel/testfiles/m3expl001.ptex.tlg b/l3kernel/testfiles/m3expl001.ptex.tlg
index 941ad8c..e1638f7 100644
--- a/l3kernel/testfiles/m3expl001.ptex.tlg
+++ b/l3kernel/testfiles/m3expl001.ptex.tlg
@@ -3818,6 +3818,8 @@ Defining \__fp_parse_one_register_auxii:wwwNw on line ...
Defining \__fp_parse_one_register_mu:www on line ...
Defining \__fp_parse_one_register_int:www on line ...
Defining \__fp_parse_one_register_dim:ww on line ...
+Defining \__fp_parse_one_register_special:N on line ...
+Defining \__fp_parse_one_register_math:NNw on line ...
Defining \__fp_parse_one_register_wd:w on line ...
Defining \__fp_parse_one_register_wd:Nw on line ...
Defining \__fp_parse_one_digit:NN on line ...
@@ -3965,6 +3967,7 @@ Defining message LaTeX/kernel/fp-no-arg on line ...
Defining message LaTeX/kernel/fp-multi-arg on line ...
Defining message LaTeX/kernel/fp-num-args on line ...
Defining message LaTeX/kernel/fp-bad-args on line ...
+Defining message LaTeX/kernel/fp-infty-pi on line ...
Defining message LaTeX/kernel/fp-robust-cmd on line ...
Defining \fp_new:N on line ...
Defining \fp_new:c on line ...
diff --git a/l3kernel/testfiles/m3expl001.tlg b/l3kernel/testfiles/m3expl001.tlg
index 7607121..3c353b9 100644
--- a/l3kernel/testfiles/m3expl001.tlg
+++ b/l3kernel/testfiles/m3expl001.tlg
@@ -3818,6 +3818,8 @@ Defining \__fp_parse_one_register_auxii:wwwNw on line ...
Defining \__fp_parse_one_register_mu:www on line ...
Defining \__fp_parse_one_register_int:www on line ...
Defining \__fp_parse_one_register_dim:ww on line ...
+Defining \__fp_parse_one_register_special:N on line ...
+Defining \__fp_parse_one_register_math:NNw on line ...
Defining \__fp_parse_one_register_wd:w on line ...
Defining \__fp_parse_one_register_wd:Nw on line ...
Defining \__fp_parse_one_digit:NN on line ...
@@ -3965,6 +3967,7 @@ Defining message LaTeX/kernel/fp-no-arg on line ...
Defining message LaTeX/kernel/fp-multi-arg on line ...
Defining message LaTeX/kernel/fp-num-args on line ...
Defining message LaTeX/kernel/fp-bad-args on line ...
+Defining message LaTeX/kernel/fp-infty-pi on line ...
Defining message LaTeX/kernel/fp-robust-cmd on line ...
Defining \fp_new:N on line ...
Defining \fp_new:c on line ...
diff --git a/l3kernel/testfiles/m3expl001.uptex.tlg b/l3kernel/testfiles/m3expl001.uptex.tlg
index f2a9d1a..f303722 100644
--- a/l3kernel/testfiles/m3expl001.uptex.tlg
+++ b/l3kernel/testfiles/m3expl001.uptex.tlg
@@ -3818,6 +3818,8 @@ Defining \__fp_parse_one_register_auxii:wwwNw on line ...
Defining \__fp_parse_one_register_mu:www on line ...
Defining \__fp_parse_one_register_int:www on line ...
Defining \__fp_parse_one_register_dim:ww on line ...
+Defining \__fp_parse_one_register_special:N on line ...
+Defining \__fp_parse_one_register_math:NNw on line ...
Defining \__fp_parse_one_register_wd:w on line ...
Defining \__fp_parse_one_register_wd:Nw on line ...
Defining \__fp_parse_one_digit:NN on line ...
@@ -3965,6 +3967,7 @@ Defining message LaTeX/kernel/fp-no-arg on line ...
Defining message LaTeX/kernel/fp-multi-arg on line ...
Defining message LaTeX/kernel/fp-num-args on line ...
Defining message LaTeX/kernel/fp-bad-args on line ...
+Defining message LaTeX/kernel/fp-infty-pi on line ...
Defining message LaTeX/kernel/fp-robust-cmd on line ...
Defining \fp_new:N on line ...
Defining \fp_new:c on line ...
diff --git a/l3kernel/testfiles/m3expl001.xetex.tlg b/l3kernel/testfiles/m3expl001.xetex.tlg
index d700e9e..6dfc094 100644
--- a/l3kernel/testfiles/m3expl001.xetex.tlg
+++ b/l3kernel/testfiles/m3expl001.xetex.tlg
@@ -3563,6 +3563,8 @@ Defining \__fp_parse_one_register_auxii:wwwNw on line ...
Defining \__fp_parse_one_register_mu:www on line ...
Defining \__fp_parse_one_register_int:www on line ...
Defining \__fp_parse_one_register_dim:ww on line ...
+Defining \__fp_parse_one_register_special:N on line ...
+Defining \__fp_parse_one_register_math:NNw on line ...
Defining \__fp_parse_one_register_wd:w on line ...
Defining \__fp_parse_one_register_wd:Nw on line ...
Defining \__fp_parse_one_digit:NN on line ...
@@ -3710,6 +3712,7 @@ Defining message LaTeX/kernel/fp-no-arg on line ...
Defining message LaTeX/kernel/fp-multi-arg on line ...
Defining message LaTeX/kernel/fp-num-args on line ...
Defining message LaTeX/kernel/fp-bad-args on line ...
+Defining message LaTeX/kernel/fp-infty-pi on line ...
Defining message LaTeX/kernel/fp-robust-cmd on line ...
Defining \fp_new:N on line ...
Defining \fp_new:c on line ...
diff --git a/l3kernel/testfiles/m3expl003.luatex.tlg b/l3kernel/testfiles/m3expl003.luatex.tlg
index 05f4e29..6a580e9 100644
--- a/l3kernel/testfiles/m3expl003.luatex.tlg
+++ b/l3kernel/testfiles/m3expl003.luatex.tlg
@@ -3564,6 +3564,8 @@ Defining \__fp_parse_one_register_auxii:wwwNw on line ...
Defining \__fp_parse_one_register_mu:www on line ...
Defining \__fp_parse_one_register_int:www on line ...
Defining \__fp_parse_one_register_dim:ww on line ...
+Defining \__fp_parse_one_register_special:N on line ...
+Defining \__fp_parse_one_register_math:NNw on line ...
Defining \__fp_parse_one_register_wd:w on line ...
Defining \__fp_parse_one_register_wd:Nw on line ...
Defining \__fp_parse_one_digit:NN on line ...
@@ -3711,6 +3713,7 @@ Defining message LaTeX/kernel/fp-no-arg on line ...
Defining message LaTeX/kernel/fp-multi-arg on line ...
Defining message LaTeX/kernel/fp-num-args on line ...
Defining message LaTeX/kernel/fp-bad-args on line ...
+Defining message LaTeX/kernel/fp-infty-pi on line ...
Defining message LaTeX/kernel/fp-robust-cmd on line ...
Defining \fp_new:N on line ...
Defining \fp_new:c on line ...
diff --git a/l3kernel/testfiles/m3expl003.ptex.tlg b/l3kernel/testfiles/m3expl003.ptex.tlg
index 941ad8c..e1638f7 100644
--- a/l3kernel/testfiles/m3expl003.ptex.tlg
+++ b/l3kernel/testfiles/m3expl003.ptex.tlg
@@ -3818,6 +3818,8 @@ Defining \__fp_parse_one_register_auxii:wwwNw on line ...
Defining \__fp_parse_one_register_mu:www on line ...
Defining \__fp_parse_one_register_int:www on line ...
Defining \__fp_parse_one_register_dim:ww on line ...
+Defining \__fp_parse_one_register_special:N on line ...
+Defining \__fp_parse_one_register_math:NNw on line ...
Defining \__fp_parse_one_register_wd:w on line ...
Defining \__fp_parse_one_register_wd:Nw on line ...
Defining \__fp_parse_one_digit:NN on line ...
@@ -3965,6 +3967,7 @@ Defining message LaTeX/kernel/fp-no-arg on line ...
Defining message LaTeX/kernel/fp-multi-arg on line ...
Defining message LaTeX/kernel/fp-num-args on line ...
Defining message LaTeX/kernel/fp-bad-args on line ...
+Defining message LaTeX/kernel/fp-infty-pi on line ...
Defining message LaTeX/kernel/fp-robust-cmd on line ...
Defining \fp_new:N on line ...
Defining \fp_new:c on line ...
diff --git a/l3kernel/testfiles/m3expl003.tlg b/l3kernel/testfiles/m3expl003.tlg
index 7607121..3c353b9 100644
--- a/l3kernel/testfiles/m3expl003.tlg
+++ b/l3kernel/testfiles/m3expl003.tlg
@@ -3818,6 +3818,8 @@ Defining \__fp_parse_one_register_auxii:wwwNw on line ...
Defining \__fp_parse_one_register_mu:www on line ...
Defining \__fp_parse_one_register_int:www on line ...
Defining \__fp_parse_one_register_dim:ww on line ...
+Defining \__fp_parse_one_register_special:N on line ...
+Defining \__fp_parse_one_register_math:NNw on line ...
Defining \__fp_parse_one_register_wd:w on line ...
Defining \__fp_parse_one_register_wd:Nw on line ...
Defining \__fp_parse_one_digit:NN on line ...
@@ -3965,6 +3967,7 @@ Defining message LaTeX/kernel/fp-no-arg on line ...
Defining message LaTeX/kernel/fp-multi-arg on line ...
Defining message LaTeX/kernel/fp-num-args on line ...
Defining message LaTeX/kernel/fp-bad-args on line ...
+Defining message LaTeX/kernel/fp-infty-pi on line ...
Defining message LaTeX/kernel/fp-robust-cmd on line ...
Defining \fp_new:N on line ...
Defining \fp_new:c on line ...
diff --git a/l3kernel/testfiles/m3expl003.uptex.tlg b/l3kernel/testfiles/m3expl003.uptex.tlg
index f2a9d1a..f303722 100644
--- a/l3kernel/testfiles/m3expl003.uptex.tlg
+++ b/l3kernel/testfiles/m3expl003.uptex.tlg
@@ -3818,6 +3818,8 @@ Defining \__fp_parse_one_register_auxii:wwwNw on line ...
Defining \__fp_parse_one_register_mu:www on line ...
Defining \__fp_parse_one_register_int:www on line ...
Defining \__fp_parse_one_register_dim:ww on line ...
+Defining \__fp_parse_one_register_special:N on line ...
+Defining \__fp_parse_one_register_math:NNw on line ...
Defining \__fp_parse_one_register_wd:w on line ...
Defining \__fp_parse_one_register_wd:Nw on line ...
Defining \__fp_parse_one_digit:NN on line ...
@@ -3965,6 +3967,7 @@ Defining message LaTeX/kernel/fp-no-arg on line ...
Defining message LaTeX/kernel/fp-multi-arg on line ...
Defining message LaTeX/kernel/fp-num-args on line ...
Defining message LaTeX/kernel/fp-bad-args on line ...
+Defining message LaTeX/kernel/fp-infty-pi on line ...
Defining message LaTeX/kernel/fp-robust-cmd on line ...
Defining \fp_new:N on line ...
Defining \fp_new:c on line ...
diff --git a/l3kernel/testfiles/m3expl003.xetex.tlg b/l3kernel/testfiles/m3expl003.xetex.tlg
index d700e9e..6dfc094 100644
--- a/l3kernel/testfiles/m3expl003.xetex.tlg
+++ b/l3kernel/testfiles/m3expl003.xetex.tlg
@@ -3563,6 +3563,8 @@ Defining \__fp_parse_one_register_auxii:wwwNw on line ...
Defining \__fp_parse_one_register_mu:www on line ...
Defining \__fp_parse_one_register_int:www on line ...
Defining \__fp_parse_one_register_dim:ww on line ...
+Defining \__fp_parse_one_register_special:N on line ...
+Defining \__fp_parse_one_register_math:NNw on line ...
Defining \__fp_parse_one_register_wd:w on line ...
Defining \__fp_parse_one_register_wd:Nw on line ...
Defining \__fp_parse_one_digit:NN on line ...
@@ -3710,6 +3712,7 @@ Defining message LaTeX/kernel/fp-no-arg on line ...
Defining message LaTeX/kernel/fp-multi-arg on line ...
Defining message LaTeX/kernel/fp-num-args on line ...
Defining message LaTeX/kernel/fp-bad-args on line ...
+Defining message LaTeX/kernel/fp-infty-pi on line ...
Defining message LaTeX/kernel/fp-robust-cmd on line ...
Defining \fp_new:N on line ...
Defining \fp_new:c on line ...
diff --git a/l3kernel/testfiles/m3fp-parse002.lvt b/l3kernel/testfiles/m3fp-parse002.lvt
index dd04c17..900690b 100644
--- a/l3kernel/testfiles/m3fp-parse002.lvt
+++ b/l3kernel/testfiles/m3fp-parse002.lvt
@@ -185,6 +185,11 @@
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+\TESTEXP { Bad~infty~pi }
+ {
+ \fp_to_tl:n { \infty , 2 , \pi }
+ }
+
% \TESTEXP { Indexing }
% {
% \fp_eval:n { (\1,\2\3,\4)[\0,\2][\1,\0] + \.\2 } \NEWLINE
diff --git a/l3kernel/testfiles/m3fp-parse002.tlg b/l3kernel/testfiles/m3fp-parse002.tlg
index 5abaed7..9cb2740 100644
--- a/l3kernel/testfiles/m3fp-parse002.tlg
+++ b/l3kernel/testfiles/m3fp-parse002.tlg
@@ -448,3 +448,26 @@ and I'll forget about whatever was undefined.
0pt
0
============================================================
+============================================================
+TEST 13: Bad infty pi
+============================================================
+! Undefined control sequence.
+<argument> \LaTeX3 error:
+ Math command \infty is not an fp
+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:
+ Math command \pi is not an fp
+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.
+(nan, 2, nan)
+============================================================
More information about the latex3-commits
mailing list