[latex3-commits] [git/LaTeX3-latex3-latex3] master: Better error message when random numbers are not available (in XeTeX) (28c9b05)

Bruno Le Floch bruno at le-floch.fr
Thu May 3 18:09:57 CEST 2018


Repository : https://github.com/latex3/latex3
On branch  : master
Link       : https://github.com/latex3/latex3/commit/28c9b05b7bb98846891b072ee1a673c3c4afe939

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

commit 28c9b05b7bb98846891b072ee1a673c3c4afe939
Author: Bruno Le Floch <bruno at le-floch.fr>
Date:   Thu May 3 18:09:57 2018 +0200

    Better error message when random numbers are not available (in XeTeX)


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

28c9b05b7bb98846891b072ee1a673c3c4afe939
 l3kernel/l3candidates.dtx              |   37 ++++++++++++---
 l3kernel/l3fp-random.dtx               |    8 ++--
 l3kernel/testfiles/m3rand001.xetex.tlg |   80 ++++++++++++++++----------------
 l3kernel/testfiles/m3seq009.xetex.tlg  |   32 ++++++++-----
 4 files changed, 95 insertions(+), 62 deletions(-)

diff --git a/l3kernel/l3candidates.dtx b/l3kernel/l3candidates.dtx
index f977632..9439ba2 100644
--- a/l3kernel/l3candidates.dtx
+++ b/l3kernel/l3candidates.dtx
@@ -2508,7 +2508,10 @@
   }
   {
     \cs_new_protected:Npn \seq_shuffle:N #1
-      { \__kernel_msg_error:nn { kernel } { fp-no-random } }
+      {
+        \__kernel_msg_error:nnn { kernel } { fp-no-random }
+          { \seq_shuffle:N #1 }
+      }
     \cs_new_eq:NN \seq_gshuffle:N \seq_shuffle:N
   }
 %    \end{macrocode}
@@ -2619,19 +2622,39 @@
 % \end{macro}
 %
 % \begin{macro}[EXP]{\sys_rand_seed:}
-%   Unpack the primitive.
+%   Unpack the primitive.  When random numbers are not available, we
+%   return zero after an error (and incidentally make sure the number of
+%   expansions needed is the same as with random numbers available).
 %    \begin{macrocode}
-\cs_new:Npn \sys_rand_seed: { \tex_the:D \tex_randomseed:D }
-\cs_if_exist:NF \tex_randomseed:D
-  { \cs_set:Npn \sys_rand_seed: { 0 } }
+\sys_if_rand_exist:TF
+  { \cs_new:Npn \sys_rand_seed: { \tex_the:D \tex_randomseed:D } }
+  {
+    \cs_new:Npn \sys_rand_seed:
+      {
+        \int_value:w
+        \__kernel_msg_expandable_error:nnn { kernel } { fp-no-random }
+          { \sys_rand_seed: }
+        \c_zero
+      }
+  }
 %    \end{macrocode}
 % \end{macro}
 %
 % \begin{macro}{\sys_gset_rand_seed:n}
 %   The primitive always assigns the seed globally.
 %    \begin{macrocode}
-\cs_new_protected:Npn \sys_gset_rand_seed:n #1
-  { \tex_setrandomseed:D \int_eval:n {#1} \exp_stop_f: }
+\sys_if_rand_exist:TF
+  {
+    \cs_new_protected:Npn \sys_gset_rand_seed:n #1
+      { \tex_setrandomseed:D \int_eval:n {#1} \exp_stop_f: }
+  }
+  {
+    \cs_new_protected:Npn \sys_gset_rand_seed:n #1
+      {
+        \__kernel_msg_error:nnn { kernel } { fp-no-random }
+          { \sys_gset_rand_seed:n {#1} }
+      }
+  }
 %    \end{macrocode}
 % \end{macro}
 %
diff --git a/l3kernel/l3fp-random.dtx b/l3kernel/l3fp-random.dtx
index 3527517..1159e6c 100644
--- a/l3kernel/l3fp-random.dtx
+++ b/l3kernel/l3fp-random.dtx
@@ -79,16 +79,18 @@
 \cs_if_exist:NF \tex_uniformdeviate:D
   {
     \__kernel_msg_new:nnn { kernel } { fp-no-random }
-      { Random~numbers~unavailable }
+      { Random~numbers~unavailable~for~#1 }
     \cs_new:Npn \@@_rand_o:Nw ? #1 @
       {
-        \__kernel_msg_expandable_error:nn { kernel } { fp-no-random }
+        \__kernel_msg_expandable_error:nnn { kernel } { fp-no-random }
+          { fp~rand }
         \exp_after:wN \c_nan_fp
       }
     \cs_new_eq:NN \@@_randint_o:Nw \@@_rand_o:Nw
     \cs_new:Npn \int_rand:nn #1#2
       {
-        \__kernel_msg_expandable_error:nn { kernel } { fp-no-random }
+        \__kernel_msg_expandable_error:nnn { kernel } { fp-no-random }
+          { \int_rand:nn {#1} {#2} }
         \int_eval:n {#1}
       }
   }
diff --git a/l3kernel/testfiles/m3rand001.xetex.tlg b/l3kernel/testfiles/m3rand001.xetex.tlg
index bb83fcb..bd6b4f0 100644
--- a/l3kernel/testfiles/m3rand001.xetex.tlg
+++ b/l3kernel/testfiles/m3rand001.xetex.tlg
@@ -6,7 +6,7 @@ TEST 1: Random floating point number
 ============================================================
 ! Undefined control sequence.
 <argument> \LaTeX3 error: 
-                           Random numbers unavailable
+                           Random numbers unavailable for fp rand
 l. ...  }
 The control sequence at the end of the top line
 of your error message was never \def'ed. If you have
@@ -20,7 +20,7 @@ TEST 2: Random integer
 ============================================================
 ! Undefined control sequence.
 <argument> \LaTeX3 error: 
-                           Random numbers unavailable
+                           Random numbers unavailable for fp rand
 l. ...  }
 The control sequence at the end of the top line
 of your error message was never \def'ed. If you have
@@ -29,7 +29,7 @@ spelling (e.g., `I\hbox'). Otherwise just continue,
 and I'll forget about whatever was undefined.
 ! Undefined control sequence.
 <argument> \LaTeX3 error: 
-                           Random numbers unavailable
+                           Random numbers unavailable for fp rand
 l. ...  }
 The control sequence at the end of the top line
 of your error message was never \def'ed. If you have
@@ -38,7 +38,7 @@ spelling (e.g., `I\hbox'). Otherwise just continue,
 and I'll forget about whatever was undefined.
 ! Undefined control sequence.
 <argument> \LaTeX3 error: 
-                           Random numbers unavailable
+                           Random numbers unavailable for fp rand
 l. ...  }
 The control sequence at the end of the top line
 of your error message was never \def'ed. If you have
@@ -47,7 +47,7 @@ spelling (e.g., `I\hbox'). Otherwise just continue,
 and I'll forget about whatever was undefined.
 ! Undefined control sequence.
 <argument> \LaTeX3 error: 
-                           Random numbers unavailable
+                           Random numbers unavailable for fp rand
 l. ...  }
 The control sequence at the end of the top line
 of your error message was never \def'ed. If you have
@@ -56,7 +56,7 @@ spelling (e.g., `I\hbox'). Otherwise just continue,
 and I'll forget about whatever was undefined.
 ! Undefined control sequence.
 <argument> \LaTeX3 error: 
-                           Random numbers unavailable
+                           Random numbers unavailable for fp rand
 l. ...  }
 The control sequence at the end of the top line
 of your error message was never \def'ed. If you have
@@ -79,7 +79,7 @@ spelling (e.g., `I\hbox'). Otherwise just continue,
 and I'll forget about whatever was undefined.
 ! Undefined control sequence.
 <argument> \LaTeX3 error: 
-                           Random numbers unavailable
+                           Random numbers unavailable for fp rand
 l. ...  }
 The control sequence at the end of the top line
 of your error message was never \def'ed. If you have
@@ -88,7 +88,7 @@ spelling (e.g., `I\hbox'). Otherwise just continue,
 and I'll forget about whatever was undefined.
 ! Undefined control sequence.
 <argument> \LaTeX3 error: 
-                           Random numbers unavailable
+                           Random numbers unavailable for fp rand
 l. ...  }
 The control sequence at the end of the top line
 of your error message was never \def'ed. If you have
@@ -97,7 +97,7 @@ spelling (e.g., `I\hbox'). Otherwise just continue,
 and I'll forget about whatever was undefined.
 ! Undefined control sequence.
 <argument> \LaTeX3 error: 
-                           Random numbers unavailable
+                           Random numbers unavailable for fp rand
 l. ...  }
 The control sequence at the end of the top line
 of your error message was never \def'ed. If you have
@@ -106,7 +106,7 @@ spelling (e.g., `I\hbox'). Otherwise just continue,
 and I'll forget about whatever was undefined.
 ! Undefined control sequence.
 <argument> \LaTeX3 error: 
-                           Random numbers unavailable
+                           Random numbers unavailable for fp rand
 l. ...  }
 The control sequence at the end of the top line
 of your error message was never \def'ed. If you have
@@ -115,7 +115,7 @@ spelling (e.g., `I\hbox'). Otherwise just continue,
 and I'll forget about whatever was undefined.
 ! Undefined control sequence.
 <argument> \LaTeX3 error: 
-                           Random numbers unavailable
+                           Random numbers unavailable for fp rand
 l. ...  }
 The control sequence at the end of the top line
 of your error message was never \def'ed. If you have
@@ -124,7 +124,7 @@ spelling (e.g., `I\hbox'). Otherwise just continue,
 and I'll forget about whatever was undefined.
 ! Undefined control sequence.
 <argument> \LaTeX3 error: 
-                           Random numbers unavailable
+                           Random numbers unavailable for fp rand
 l. ...  }
 The control sequence at the end of the top line
 of your error message was never \def'ed. If you have
@@ -133,7 +133,7 @@ spelling (e.g., `I\hbox'). Otherwise just continue,
 and I'll forget about whatever was undefined.
 ! Undefined control sequence.
 <argument> \LaTeX3 error: 
-                           Random numbers unavailable
+                           Random numbers unavailable for fp rand
 l. ...  }
 The control sequence at the end of the top line
 of your error message was never \def'ed. If you have
@@ -142,7 +142,7 @@ spelling (e.g., `I\hbox'). Otherwise just continue,
 and I'll forget about whatever was undefined.
 ! Undefined control sequence.
 <argument> \LaTeX3 error: 
-                           Random numbers unavailable
+                           Random numbers unavailable for fp rand
 l. ...  }
 The control sequence at the end of the top line
 of your error message was never \def'ed. If you have
@@ -151,7 +151,7 @@ spelling (e.g., `I\hbox'). Otherwise just continue,
 and I'll forget about whatever was undefined.
 ! Undefined control sequence.
 <argument> \LaTeX3 error: 
-                           Random numbers unavailable
+                           Random numbers unavailable for fp rand
 l. ...  }
 The control sequence at the end of the top line
 of your error message was never \def'ed. If you have
@@ -160,7 +160,7 @@ spelling (e.g., `I\hbox'). Otherwise just continue,
 and I'll forget about whatever was undefined.
 ! Undefined control sequence.
 <argument> \LaTeX3 error: 
-                           Random numbers unavailable
+                           Random numbers unavailable for fp rand
 l. ...  }
 The control sequence at the end of the top line
 of your error message was never \def'ed. If you have
@@ -169,7 +169,7 @@ spelling (e.g., `I\hbox'). Otherwise just continue,
 and I'll forget about whatever was undefined.
 ! Undefined control sequence.
 <argument> \LaTeX3 error: 
-                           Random numbers unavailable
+                           Random numbers unavailable for fp rand
 l. ...  }
 The control sequence at the end of the top line
 of your error message was never \def'ed. If you have
@@ -178,7 +178,7 @@ spelling (e.g., `I\hbox'). Otherwise just continue,
 and I'll forget about whatever was undefined.
 ! Undefined control sequence.
 <argument> \LaTeX3 error: 
-                           Random numbers unavailable
+                           Random numbers unavailable for fp rand
 l. ...  }
 The control sequence at the end of the top line
 of your error message was never \def'ed. If you have
@@ -187,7 +187,7 @@ spelling (e.g., `I\hbox'). Otherwise just continue,
 and I'll forget about whatever was undefined.
 ! Undefined control sequence.
 <argument> \LaTeX3 error: 
-                           Random numbers unavailable
+                           Random numbers unavailable for fp rand
 l. ...  }
 The control sequence at the end of the top line
 of your error message was never \def'ed. If you have
@@ -196,7 +196,7 @@ spelling (e.g., `I\hbox'). Otherwise just continue,
 and I'll forget about whatever was undefined.
 ! Undefined control sequence.
 <argument> \LaTeX3 error: 
-                           Random numbers unavailable
+                           Random numbers unavailable for fp rand
 l. ...  }
 The control sequence at the end of the top line
 of your error message was never \def'ed. If you have
@@ -205,7 +205,7 @@ spelling (e.g., `I\hbox'). Otherwise just continue,
 and I'll forget about whatever was undefined.
 ! Undefined control sequence.
 <argument> \LaTeX3 error: 
-                           Random numbers unavailable
+                           Random numbers unavailable for \int_rand:nn {1}{0}
 l. ...  }
 The control sequence at the end of the top line
 of your error message was never \def'ed. If you have
@@ -214,7 +214,7 @@ spelling (e.g., `I\hbox'). Otherwise just continue,
 and I'll forget about whatever was undefined.
 ! Undefined control sequence.
 <argument> \LaTeX3 error: 
-                           Random numbers unavailable
+                           Random numbers unavailable for fp rand
 l. ...  }
 The control sequence at the end of the top line
 of your error message was never \def'ed. If you have
@@ -223,7 +223,7 @@ spelling (e.g., `I\hbox'). Otherwise just continue,
 and I'll forget about whatever was undefined.
 ! Undefined control sequence.
 <argument> \LaTeX3 error: 
-                           Random numbers unavailable
+                           Random numbers unavailable for fp rand
 l. ...  }
 The control sequence at the end of the top line
 of your error message was never \def'ed. If you have
@@ -232,7 +232,7 @@ spelling (e.g., `I\hbox'). Otherwise just continue,
 and I'll forget about whatever was undefined.
 ! Undefined control sequence.
 <argument> \LaTeX3 error: 
-                           Random numbers unavailable
+                           Random numbers unavailable for fp rand
 l. ...  }
 The control sequence at the end of the top line
 of your error message was never \def'ed. If you have
@@ -263,7 +263,7 @@ TEST 4: Random integer in a range
 ============================================================
 ! Undefined control sequence.
 <argument> \LaTeX3 error: 
-                           Random numbers unavailable
+                           Random numbers unavailable for \int_rand:nn {-1}{1}
 l. ...  }
 The control sequence at the end of the top line
 of your error message was never \def'ed. If you have
@@ -272,7 +272,7 @@ spelling (e.g., `I\hbox'). Otherwise just continue,
 and I'll forget about whatever was undefined.
 ! Undefined control sequence.
 <argument> \LaTeX3 error: 
-                           Random numbers unavailable
+                           Random numbers unavailable for \int_rand:nn {-\c_...
 l. ...  }
 The control sequence at the end of the top line
 of your error message was never \def'ed. If you have
@@ -281,7 +281,7 @@ spelling (e.g., `I\hbox'). Otherwise just continue,
 and I'll forget about whatever was undefined.
 ! Undefined control sequence.
 <argument> \LaTeX3 error: 
-                           Random numbers unavailable
+                           Random numbers unavailable for \int_rand:nn {-\c_...
 l. ...  }
 The control sequence at the end of the top line
 of your error message was never \def'ed. If you have
@@ -290,7 +290,7 @@ spelling (e.g., `I\hbox'). Otherwise just continue,
 and I'll forget about whatever was undefined.
 ! Undefined control sequence.
 <argument> \LaTeX3 error: 
-                           Random numbers unavailable
+                           Random numbers unavailable for \int_rand:nn {-\c_...
 l. ...  }
 The control sequence at the end of the top line
 of your error message was never \def'ed. If you have
@@ -304,7 +304,7 @@ TEST 5: Random tl item
 ============================================================
 ! Undefined control sequence.
 <argument> \LaTeX3 error: 
-                           Random numbers unavailable
+                           Random numbers unavailable for \int_rand:nn {1}{\...
 l. ...  }
 The control sequence at the end of the top line
 of your error message was never \def'ed. If you have
@@ -313,7 +313,7 @@ spelling (e.g., `I\hbox'). Otherwise just continue,
 and I'll forget about whatever was undefined.
 ! Undefined control sequence.
 <argument> \LaTeX3 error: 
-                           Random numbers unavailable
+                           Random numbers unavailable for \int_rand:nn {1}{\...
 l. ...  }
 The control sequence at the end of the top line
 of your error message was never \def'ed. If you have
@@ -322,7 +322,7 @@ spelling (e.g., `I\hbox'). Otherwise just continue,
 and I'll forget about whatever was undefined.
 ! Undefined control sequence.
 <argument> \LaTeX3 error: 
-                           Random numbers unavailable
+                           Random numbers unavailable for \int_rand:nn {1}{\...
 l. ...  }
 The control sequence at the end of the top line
 of your error message was never \def'ed. If you have
@@ -331,7 +331,7 @@ spelling (e.g., `I\hbox'). Otherwise just continue,
 and I'll forget about whatever was undefined.
 ! Undefined control sequence.
 <argument> \LaTeX3 error: 
-                           Random numbers unavailable
+                           Random numbers unavailable for \int_rand:nn {1}{\...
 l. ...  }
 The control sequence at the end of the top line
 of your error message was never \def'ed. If you have
@@ -340,7 +340,7 @@ spelling (e.g., `I\hbox'). Otherwise just continue,
 and I'll forget about whatever was undefined.
 ! Undefined control sequence.
 <argument> \LaTeX3 error: 
-                           Random numbers unavailable
+                           Random numbers unavailable for \int_rand:nn {1}{\...
 l. ...  }
 The control sequence at the end of the top line
 of your error message was never \def'ed. If you have
@@ -355,7 +355,7 @@ TEST 6: Random clist item
 ============================================================
 ! Undefined control sequence.
 <argument> \LaTeX3 error: 
-                           Random numbers unavailable
+                           Random numbers unavailable for \int_rand:nn {1}{2}
 l. ...  }
 The control sequence at the end of the top line
 of your error message was never \def'ed. If you have
@@ -364,7 +364,7 @@ spelling (e.g., `I\hbox'). Otherwise just continue,
 and I'll forget about whatever was undefined.
 ! Undefined control sequence.
 <argument> \LaTeX3 error: 
-                           Random numbers unavailable
+                           Random numbers unavailable for \int_rand:nn {1}{4}
 l. ...  }
 The control sequence at the end of the top line
 of your error message was never \def'ed. If you have
@@ -373,7 +373,7 @@ spelling (e.g., `I\hbox'). Otherwise just continue,
 and I'll forget about whatever was undefined.
 ! Undefined control sequence.
 <argument> \LaTeX3 error: 
-                           Random numbers unavailable
+                           Random numbers unavailable for \int_rand:nn {1}{\...
 l. ...  }
 The control sequence at the end of the top line
 of your error message was never \def'ed. If you have
@@ -382,7 +382,7 @@ spelling (e.g., `I\hbox'). Otherwise just continue,
 and I'll forget about whatever was undefined.
 ! Undefined control sequence.
 <argument> \LaTeX3 error: 
-                           Random numbers unavailable
+                           Random numbers unavailable for \int_rand:nn {1}{\...
 l. ...  }
 The control sequence at the end of the top line
 of your error message was never \def'ed. If you have
@@ -397,7 +397,7 @@ TEST 7: Random seq item
 ============================================================
 ! Undefined control sequence.
 <argument> \LaTeX3 error: 
-                           Random numbers unavailable
+                           Random numbers unavailable for \int_rand:nn {1}{\...
 l. ...  }
 The control sequence at the end of the top line
 of your error message was never \def'ed. If you have
@@ -406,7 +406,7 @@ spelling (e.g., `I\hbox'). Otherwise just continue,
 and I'll forget about whatever was undefined.
 ! Undefined control sequence.
 <argument> \LaTeX3 error: 
-                           Random numbers unavailable
+                           Random numbers unavailable for \int_rand:nn {1}{\...
 l. ...  }
 The control sequence at the end of the top line
 of your error message was never \def'ed. If you have
@@ -420,7 +420,7 @@ TEST 8: Random prop key/value
 ============================================================
 ! Undefined control sequence.
 <argument> \LaTeX3 error: 
-                           Random numbers unavailable
+                           Random numbers unavailable for \int_rand:nn {1}{\...
 l. ...  }
 The control sequence at the end of the top line
 of your error message was never \def'ed. If you have
diff --git a/l3kernel/testfiles/m3seq009.xetex.tlg b/l3kernel/testfiles/m3seq009.xetex.tlg
index ddfea5e..57b0926 100644
--- a/l3kernel/testfiles/m3seq009.xetex.tlg
+++ b/l3kernel/testfiles/m3seq009.xetex.tlg
@@ -4,20 +4,28 @@ Author: Bruno Le Floch
 ============================================================
 TEST 1: seq_shuffle
 ============================================================
-! Undefined control sequence.
-\sys_gset_rand_seed:n #1->\tex_setrandomseed:D 
-                                               \int_eval:n {#1}\exp_stop_f: 
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+!
+! LaTeX error: "kernel/fp-no-random"
+! 
+! Random numbers unavailable for \sys_gset_rand_seed:n {12345}
+! 
+! See the LaTeX3 documentation for further information.
+! 
+! Type <return> to continue.
+!...............................................  
 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.
+|'''''''''''''''''''''''''''''''''''''''''''''''
+| LaTeX does not know anything more about this error, sorry.
+| 
+| Try typing <return> to proceed.
+| If that doesn't work, type X <return> to quit.
+|...............................................
 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 !
 ! LaTeX error: "kernel/fp-no-random"
 ! 
-! Random numbers unavailable
+! Random numbers unavailable for \seq_shuffle:N \l_tmpa_seq 
 ! 
 ! See the LaTeX3 documentation for further information.
 ! 
@@ -34,7 +42,7 @@ l. ...  }
 !
 ! LaTeX error: "kernel/fp-no-random"
 ! 
-! Random numbers unavailable
+! Random numbers unavailable for \seq_shuffle:N \l_tmpa_seq 
 ! 
 ! See the LaTeX3 documentation for further information.
 ! 
@@ -51,7 +59,7 @@ l. ...  }
 !
 ! LaTeX error: "kernel/fp-no-random"
 ! 
-! Random numbers unavailable
+! Random numbers unavailable for \seq_shuffle:N \l_tmpa_seq 
 ! 
 ! See the LaTeX3 documentation for further information.
 ! 
@@ -69,7 +77,7 @@ l. ...  }
 !
 ! LaTeX error: "kernel/fp-no-random"
 ! 
-! Random numbers unavailable
+! Random numbers unavailable for \seq_shuffle:N \g_tmpb_seq 
 ! 
 ! See the LaTeX3 documentation for further information.
 ! 





More information about the latex3-commits mailing list