On Wed, May 09, 2012 at 10:16:50AM +0200, Taco Hoekwater wrote:
>
> Hi all,
>
> On 05/08/2012 09:11 PM, David Carlisle wrote:
> >
> >Luatex has changed mathcode to allow a larger numeric range however
> >changing TeX primitives without giving them new names seems suspect and
> >in this particular case, since \mathcode has changed but \mathchardef
> >has not the essential link between these two commands has been broken.
>
> Not quite. You get the results below because the math code for `a
> has been set using \Umathcode, not the TeX82 \mathcode. In fact,
> assignment to \mathcode is not extended in LuaTeX at all.
Right, TeX Live's luatex.ini loads luatex-unicode-letters.tex which
unconditionally sets the mathcode for all characters using \Umathcode.
The following example gives an error when run with luatex, but no error
if -ini is passed:
\input plain
\mathchardef\matha\mathcode`a
\bye
That is the second issue I have with this luatex-unicode-letters.tex
files, which makes me wounder if it is really a wise idea to preload it
into the format.
> The output of \mathcode is indeed extended, and the value you get
> uses the same format as the input for \Umathcodenum (with that
> somewhat unusual XeTeX-invented format explained by Kazuki Maeda).
>
> The reason for this is that math character objects in luatex remember
> how they were defined. So if you do not want incompatibilities with
> TeX82, it would help if you did not use extended primitives to define stuff.
>
> That said, probably the result of (\the)\mathcode can be reverted
> back to compatibility with TeX82, and output a warning (and zero)
> if the actual value is out-of-range (like XeTeX does).
Attached a patch that does this (with the added bonus of fixing the
damage of luatex-unicode-letters.tex), what do you think? if it is OK,
I'll commit it.
Regards,
Khaled
diff --git a/source/texk/web2c/luatexdir/tex/mathcodes.h b/source/texk/web2c/luatexdir/tex/mathcodes.h
index 145a3f9..a809ddf 100644
--- a/source/texk/web2c/luatexdir/tex/mathcodes.h
+++ b/source/texk/web2c/luatexdir/tex/mathcodes.h
@@ -43,7 +43,7 @@ void set_math_code(int n,
int mathfamily, int mathcharacter, quarterword gl);
mathcodeval get_math_code(int n);
-int get_math_code_num(int n);
+int get_math_code_num(int n, boolean compat);
int get_del_code_num(int n);
mathcodeval scan_mathchar(int extcode);
mathcodeval scan_delimiter_as_mathchar(int extcode);
diff --git a/source/texk/web2c/luatexdir/tex/mathcodes.w b/source/texk/web2c/luatexdir/tex/mathcodes.w
index dd27fac..138551d 100644
--- a/source/texk/web2c/luatexdir/tex/mathcodes.w
+++ b/source/texk/web2c/luatexdir/tex/mathcodes.w
@@ -207,20 +207,33 @@ mathcodeval get_math_code(int n)
@ @c
-int get_math_code_num(int n)
+int get_math_code_num(int n, boolean compat)
{
mathcodeval mval;
mval = get_math_code(n);
- if (mval.origin_value == tex_mathcode) {
- return (mval.class_value * 16 + mval.family_value) * 256 +
- mval.character_value;
- } else if (mval.origin_value == aleph_mathcode) {
- return (mval.class_value * 256 + mval.family_value) * 65536 +
- mval.character_value;
- } else if (mval.origin_value == xetexnum_mathcode
- || mval.origin_value == xetex_mathcode) {
- return (mval.class_value + (mval.family_value * 8)) * (65536 * 32) +
- mval.character_value;
+ if (compat) {
+ if (mval.class_value > 7
+ || mval.family_value > 15
+ || mval.character_value > 255) {
+ print_err("Extended mathchar used as mathchar");
+ help2("A mathchar number must be between 0 and 32767.",
+ "I changed this one to zero.");
+ int_error(mval.character_value);
+ mval = get_math_code(0);
+ }
+ return mval.class_value * 4096 + mval.family_value * 256 + mval.character_value;
+ } else {
+ if (mval.origin_value == tex_mathcode) {
+ return (mval.class_value * 16 + mval.family_value) * 256 +
+ mval.character_value;
+ } else if (mval.origin_value == aleph_mathcode) {
+ return (mval.class_value * 256 + mval.family_value) * 65536 +
+ mval.character_value;
+ } else if (mval.origin_value == xetexnum_mathcode
+ || mval.origin_value == xetex_mathcode) {
+ return (mval.class_value + (mval.family_value * 8)) * (65536 * 32) +
+ mval.character_value;
+ }
}
return 0;
}
diff --git a/source/texk/web2c/luatexdir/tex/scanning.w b/source/texk/web2c/luatexdir/tex/scanning.w
index d8e8a0c..f785ebc 100644
--- a/source/texk/web2c/luatexdir/tex/scanning.w
+++ b/source/texk/web2c/luatexdir/tex/scanning.w
@@ -646,7 +646,7 @@ void scan_something_internal(int level, boolean negative)
/* Fetch a character code from some table */
scan_char_num();
if (m == math_code_base) {
- cur_val1 = get_math_code_num(cur_val);
+ cur_val1 = get_math_code_num(cur_val, true);
scanned_result(cur_val1, int_val_level);
} else if (m == lc_code_base) {
cur_val1 = get_lc_code(cur_val);
@@ -673,7 +673,7 @@ void scan_something_internal(int level, boolean negative)
case extdef_math_code_cmd:
/* Fetch an extended math code table value */
scan_char_num();
- cur_val1 = get_math_code_num(cur_val);
+ cur_val1 = get_math_code_num(cur_val, false);
scanned_result(cur_val1, int_val_level);
break;
case toks_register_cmd: