View Issue Details

IDProjectCategoryView StatusLast Update
0000520luatexluatex bugpublic2012-04-09 04:45
ReporterphiAssigned ToTaco 
PrioritynormalSeveritytweakReproducibilityhave not tried
Status closedResolutionfixed 
Product Version0.64.0 
Target VersionFixed in Version0.65.0 
Summary0000520: Calculation of top math accent shifts
DescriptionIf we consider math accents, we have to distinguish between several cases:
- Non-OTF fonts or OTF fonts without MATH table. In that case the skew char mechanism has to be used.
- OTF fonts with MATH table, top_accent not set: Use center of glyph.
- OTF fonts with MATH table, top_accent is set to zero: Use top_accent = 0 as absolute shift.
Currently LuaTeX doesn't distinguish between these cases: The top accent member of the charinfo struct is zero in each case. But top_accent = 0 is a legitimate value and inept as a sentinel. I've attached a patch (which unfortunately clashes with the other patch) that replaces the sentinel by INT_MIN (a very improbable value, but a flags register would be even better) and checks for math fonts using the same technique as the radical code (but in the long run a more idiomatic and robust solution without sentinels should be implemented).
Tagsmath

Activities

phi

2010-11-22 01:10

reporter  

top-accent-pos.patch (5,281 bytes)
Index: source/texk/web2c/luatexdir/tex/mlist.w
===================================================================
--- source/texk/web2c/luatexdir/tex/mlist.w	(revision 3964)
+++ source/texk/web2c/luatexdir/tex/mlist.w	(working copy)
@@ -2126,9 +2126,11 @@
 @c
 #define TOP_CODE 1
 #define BOT_CODE 2
+#define TOP_OR_BOT_MASK ((TOP_CODE) | (BOT_CODE))
+#define STRETCH_ACCENT_CODE 4
 
 static void do_make_math_accent(pointer q, internal_font_number f, int c,
-                                int top_or_bot, int cur_style)
+                                int flags, int cur_style)
 {
     pointer p, r, x, y;         /* temporary registers for box construction */
     scaled s;                   /* amount to skew the accent to the right */
@@ -2138,6 +2140,8 @@
     boolean s_is_absolute;      /* will be true if a top-accent is placed in |s| */
     extinfo *ext;
     pointer attr_p;
+    const int top_or_bot = flags & TOP_OR_BOT_MASK;
+    const int compat_mode = radical_rule(cur_style) == undefined_math_parameter;
     attr_p = (top_or_bot == TOP_CODE ? accent_chr(q) : bot_accent_chr(q));
     s_is_absolute = false;
     c = cur_c;
@@ -2146,29 +2150,40 @@
     s = 0;
     if (type(nucleus(q)) == math_char_node) {
         fetch(nucleus(q));
+        if (compat_mode) {
+          if (top_or_bot == TOP_CODE) {
+            s = get_kern(cur_f, cur_c, skew_char(cur_f));
+          } else {
+            s = 0;
+          }
+        } else {
         if (top_or_bot == TOP_CODE) {
             s = char_top_accent(cur_f, cur_c);
-            if (s != 0) {
+            if (s != INT_MIN) {
                 s_is_absolute = true;
-            } else {
-                s = get_kern(cur_f, cur_c, skew_char(cur_f));
             }
         } else {                /* new skewchar madness for bot accents */
             s = char_bot_accent(cur_f, cur_c);
-            if (s == 0) {       /* better than nothing: */
+            if (s == INT_MIN) {       /* better than nothing: */
                 s = char_top_accent(cur_f, cur_c);
             }
-            if (s != 0) {
+            if (s != INT_MIN) {
                 s_is_absolute = true;
             }
         }
+        }
     }
     x = clean_box(nucleus(q), cramped_style(cur_style), cur_style);
     w = width(x);
     h = height(x);
+    if (!compat_mode && !s_is_absolute) {
+      s = half(w);
+      s_is_absolute = true;
+    }
     /* Switch to a larger accent if available and appropriate */
     y = null;
-    while (1) {
+    if (flags & STRETCH_ACCENT_CODE) {
+      while (1) {
         ext = NULL;
         if ((char_tag(f, c) == ext_tag) &&
             ((ext = get_charinfo_hor_variants(char_info(f, c))) != NULL)) {
@@ -2187,6 +2202,7 @@
                 break;
             c = yy;
         }
+      }
     }
     if (y == null) {
         y = char_box(f, c, node_attr(attr_p));
@@ -2223,8 +2239,9 @@
             sa = char_top_accent(f, c);
         else
             sa = char_bot_accent(f, c);
-        if (sa == 0) {
+        if (sa == INT_MIN) {
             sa = half(width(y));        /* just take the center */
+            printf("No top accent position for accent %u\n", c);
         }
         shift_amount(y) = s - sa;
     } else {
@@ -2265,12 +2282,12 @@
     type(nucleus(q)) = sub_box_node;
 }
 
-static void make_math_accent(pointer q, int cur_style)
+static void make_math_accent(pointer q, int cur_style, int stretch)
 {
     if (accent_chr(q) != null) {
         fetch(accent_chr(q));
         if (char_exists(cur_f, cur_c)) {
-            do_make_math_accent(q, cur_f, cur_c, TOP_CODE, cur_style);
+          do_make_math_accent(q, cur_f, cur_c, TOP_CODE | (stretch ? STRETCH_ACCENT_CODE : 0), cur_style);
         }
         flush_node(accent_chr(q));
         accent_chr(q) = null;
@@ -2278,7 +2295,7 @@
     if (bot_accent_chr(q) != null) {
         fetch(bot_accent_chr(q));
         if (char_exists(cur_f, cur_c)) {
-            do_make_math_accent(q, cur_f, cur_c, BOT_CODE, cur_style);
+          do_make_math_accent(q, cur_f, cur_c, BOT_CODE | (stretch ? STRETCH_ACCENT_CODE : 0), cur_style);
         }
         flush_node(bot_accent_chr(q));
         bot_accent_chr(q) = null;
@@ -3417,7 +3434,7 @@
                 make_radical(q, cur_style);
             break;
         case accent_noad:
-            make_math_accent(q, cur_style);
+          make_math_accent(q, cur_style, subtype(q) == 0);
             break;
         case style_node:
             cur_style = subtype(q);
Index: source/texk/web2c/luatexdir/font/luafont.w
===================================================================
--- source/texk/web2c/luatexdir/font/luafont.w	(revision 3964)
+++ source/texk/web2c/luatexdir/font/luafont.w	(working copy)
@@ -1226,9 +1226,9 @@
             set_charinfo_tounicode(co, NULL);
 
         if (has_math) {
-            j = n_numeric_field(L, luaS_top_accent_index, 0);
+            j = n_numeric_field(L, luaS_top_accent_index, INT_MIN);
             set_charinfo_top_accent(co, j);
-            j = n_numeric_field(L, luaS_bot_accent_index, 0);
+            j = n_numeric_field(L, luaS_bot_accent_index, INT_MIN);
             set_charinfo_bot_accent(co, j);
             k = n_numeric_field(L, luaS_next_index, -1);
             if (k >= 0) {
top-accent-pos.patch (5,281 bytes)

Taco

2010-11-24 15:01

administrator   ~0000662

You mean that this patch interferes with the 509 patch, right?

phi

2010-11-24 21:52

reporter   ~0000669

Last edited: 2010-11-25 23:10

View 2 revisions

Well, if you apply this patch to mlist.w and then the other patch to the other files, you get the patches combined. I disentangled my mess a bit and created a patch that contains only the code related to this item:
https://github.com/phst/unimath-extras/blob/master/luatex-patches/top-accent-pos.patch
EDIT: I've updated the patch for the new revision and also fixed a stupid bug that was in the previous versions of the patch.

Taco

2010-11-26 14:12

administrator   ~0000675

I have applied the patch, but I do not have a good test file. Can you please verify that processing is ok and that this does not break anything?

phi

2010-11-28 18:16

reporter   ~0000688

I don't have a test suite either, but I've attached two test files and their outputs with rev. 4000.

phi

2010-11-28 18:17

reporter  

luatex-accent-otf.tex (325 bytes)

phi

2010-11-28 18:17

reporter  

luatex-accent-otf.pdf (19,080 bytes)

phi

2010-11-28 18:17

reporter  

luatex-accents-cm.tex (138 bytes)

phi

2010-11-28 18:17

reporter  

luatex-accents-cm.pdf (16,166 bytes)

phi

2010-11-28 18:22

reporter  

luatex-hat-cm.tex (147 bytes)

phi

2010-11-28 18:22

reporter  

luatex-hat-cm.pdf (23,787 bytes)

phi

2010-11-28 18:23

reporter  

luatex-hat-otf.tex (429 bytes)

phi

2010-11-28 18:23

reporter  

luatex-hat-otf.pdf (20,028 bytes)

Taco

2010-11-29 10:08

administrator   ~0000689

resolve this item?

phi

2010-12-05 15:34

reporter   ~0000705

I'll ask Khaled who has a larger test suite.

Khaled Hosny

2010-12-06 23:04

developer  

accents.pdf (837,986 bytes)

Khaled Hosny

2010-12-06 23:07

developer   ~0000707

Top accents look fine, but (non-spacing) bottom accents are not. Since there is no bot_accent in the spec, bottom accents is in more need to love, but that may need a different issue of its own.

Taco

2010-12-07 10:36

administrator   ~0000708

ok, let's deal with bottom accents separately

Issue History

Date Modified Username Field Change
2010-11-22 01:09 phi New Issue
2010-11-22 01:10 phi File Added: top-accent-pos.patch
2010-11-24 15:00 Taco Status new => assigned
2010-11-24 15:00 Taco Assigned To => Taco
2010-11-24 15:01 Taco Note Added: 0000662
2010-11-24 21:52 phi Note Added: 0000669
2010-11-25 23:10 phi Note Edited: 0000669 View Revisions
2010-11-26 14:12 Taco Note Added: 0000675
2010-11-26 14:12 Taco Status assigned => feedback
2010-11-28 18:16 phi Note Added: 0000688
2010-11-28 18:16 phi Status feedback => assigned
2010-11-28 18:17 phi File Added: luatex-accent-otf.tex
2010-11-28 18:17 phi File Added: luatex-accent-otf.pdf
2010-11-28 18:17 phi File Added: luatex-accents-cm.tex
2010-11-28 18:17 phi File Added: luatex-accents-cm.pdf
2010-11-28 18:22 phi File Added: luatex-hat-cm.tex
2010-11-28 18:22 phi File Added: luatex-hat-cm.pdf
2010-11-28 18:23 phi File Added: luatex-hat-otf.tex
2010-11-28 18:23 phi File Added: luatex-hat-otf.pdf
2010-11-29 10:08 Taco Note Added: 0000689
2010-11-29 17:20 Taco Status assigned => feedback
2010-12-05 15:34 phi Note Added: 0000705
2010-12-05 15:34 phi Status feedback => assigned
2010-12-06 23:04 Khaled Hosny File Added: accents.pdf
2010-12-06 23:07 Khaled Hosny Note Added: 0000707
2010-12-07 10:36 Taco Note Added: 0000708
2010-12-07 10:36 Taco Status assigned => resolved
2010-12-07 10:36 Taco Resolution open => fixed
2010-12-13 14:43 Taco Fixed in Version => 0.65.0
2010-12-13 14:43 Taco Status resolved => closed
2012-04-09 04:41 Khaled Hosny Tag Attached: math