From 07608c759debfed1b06688fe888ac728f636eb61 Mon Sep 17 00:00:00 2001 From: Bruce Miller Date: Wed, 11 Dec 2024 10:58:23 -0500 Subject: [PATCH 1/2] Crude implementation of \leaders, at least getting the arguments right; updated test case --- lib/LaTeXML/Engine/TeX_Box.pool.ltxml | 53 ++++++++++++++++++++++++--- t/alignment/tabbing.xml | 6 +-- 2 files changed, 51 insertions(+), 8 deletions(-) diff --git a/lib/LaTeXML/Engine/TeX_Box.pool.ltxml b/lib/LaTeXML/Engine/TeX_Box.pool.ltxml index 73a48a8e7..56ae014d9 100644 --- a/lib/LaTeXML/Engine/TeX_Box.pool.ltxml +++ b/lib/LaTeXML/Engine/TeX_Box.pool.ltxml @@ -708,11 +708,54 @@ DefConstructor('\hrule RuleSpecification', return; }); # ====================================================================== -# Various leaders, ignored for now... -DefPrimitiveI('\leaders', undef, undef); -DefPrimitiveI('\cleaders', undef, undef); -DefPrimitiveI('\xleaders', undef, undef); - +# Various leaders, mostly faking it for now... + +# \leaders fills the space specified by (which may be \hfill) +# with copies of the +# \cleaders similarly, but centers the result, if it doesn't completely fill +# \xleaders similarly, but stretches the result, if it doesn't completely fill +# Note that the is NOT a Glue (eg a glue specification), but something like \hfill + +# Normally, these are used in a TOC, with a variable width (reflow), +# so you'd hope for some adaptive CSS approach. +# But the CSS is tricky, and you need CSS to control the leader's container as well. +# However, occasionally, leaders appear within an object with an explicitly requested width, +# so maybe it's reasonable to set the width (or duplicate the filler) to fill that width? +# Alternatively, you may wish to simply hide ltx_leaders +DefConstructor('\leaders Digested Digested', sub { + my ($document, $filler, $glue) = @_; + my $fw = $filler->getWidth; + # my $context = $document->getNode; + my $context = $document->getElement; + Debug("LEADERS of " . Stringify($filler) . " to fill " . Stringify($glue)); + my $cbox = $document->getNodeBox($context); + my $container = $document->openElement('ltx:text', _noautoclose => 1); + my ($fnode) = $document->absorb($filler); + my ($unwrap, $fillw, $reqw); + # EXPLICITLY requested width? + if ($fnode && $cbox && ($reqw = $cbox->getProperty('width'))) { + if ($document->getNodeQName($fnode) eq 'ltx:rule') { # Or other stretchable element? + Debug(" extend to " . ToString($reqw)); + $document->setAttribute($fnode, width => $reqw->toAttribute); + $document->addClass($fnode, 'ltx_filled_leader'); + $unwrap = 1; } + elsif (($fillw = $filler->getWidth) && ($fillw = $fillw->valueOf)) { + my $n = int($reqw->valueOf / $fillw); + Debug(" duplicate $n times"); + $document->addClass($container, 'ltx_filled_leader'); + for (my $i = 2 ; $i < $n ; $i++) { + $document->absorb($filler); } } } + else { + $document->addClass($container, 'ltx_leader'); } + $document->closeElement('ltx:text'); + $document->unwrapNodes($container) if $unwrap; # avoid redundant + return; }, + ## Hide the rule argument from contributing cell borders to any containing Alignment + bounded => 1, beforeDigest => sub { $STATE->assignValue(Alignment => undef); } +); + +Let('\cleaders', '\leaders'); +Let('\xleaders', '\leaders'); #%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 1; diff --git a/t/alignment/tabbing.xml b/t/alignment/tabbing.xml index 5cba21357..6c5c050dd 100644 --- a/t/alignment/tabbing.xml +++ b/t/alignment/tabbing.xml @@ -35,17 +35,17 @@ pc Pica = 12pt - + cc Cicero = 12dd - + cm Centimeter = 10mm - + From 489e0abf8c00d556b32c792893d748d1f9b48b46 Mon Sep 17 00:00:00 2001 From: Bruce Miller Date: Wed, 11 Dec 2024 23:34:44 -0500 Subject: [PATCH 2/2] Update various wide math accents to get stretchy=yes; slightly more plausible definitions of \hrulefill, etc; update affected tests --- lib/LaTeXML/Engine/TeX_Math.pool.ltxml | 32 +++++++++++++++++++------- lib/LaTeXML/Engine/plain.pool.ltxml | 17 +++++++------- t/ams/mathtools.xml | 4 ++-- t/complex/physics.xml | 8 +++---- t/fonts/abxtest.xml | 12 +++++----- t/fonts/mathaccents.xml | 22 +++++++++--------- t/math/sampler.xml | 4 ++-- 7 files changed, 58 insertions(+), 41 deletions(-) diff --git a/lib/LaTeXML/Engine/TeX_Math.pool.ltxml b/lib/LaTeXML/Engine/TeX_Math.pool.ltxml index d850d9d16..21d814086 100644 --- a/lib/LaTeXML/Engine/TeX_Math.pool.ltxml +++ b/lib/LaTeXML/Engine/TeX_Math.pool.ltxml @@ -908,18 +908,34 @@ Let('\vcenter', '\vbox'); # \overline c puts a line over the following character or subformula. # \underline c puts a line under the following character or subformula. -DefMath('\lx@math@overline{}', UTF(0xAF), operator_role => 'OVERACCENT', - name => 'overline', alias => '\overline'); +DefMath('\lx@math@overline{}', UTF(0xAF), + operator_role => 'OVERACCENT', scriptpos => 'mid', operator_stretchy => 'true', + name => 'overline', alias => '\overline'); DefConstructor('\lx@text@overline{}', "#1"); -DefMath('\lx@math@underline{}', UTF(0xAF), operator_role => 'UNDERACCENT', - name => 'underline', alias => '\underline'); +DefMath('\lx@math@underline{}', UTF(0xAF), + operator_role => 'UNDERACCENT', scriptpos => 'mid', operator_stretchy => 'true', + name => 'underline', alias => '\underline'); DefConstructor('\lx@text@underline{}', "#1"); -DefMath('\lx@math@overrightarrow{}', "\x{2192}", operator_role => 'OVERACCENT', - name => 'overrightarrow', alias => '\overrightarrow'); -DefMath('\lx@math@overleftarrow{}', "\x{2190}", operator_role => 'OVERACCENT', - name => 'overleftarrow', alias => '\overleftarrow'); +DefMath('\lx@math@overrightarrow{}', "\x{2192}", + operator_role => 'OVERACCENT', scriptpos => 'mid', operator_stretchy => 'true', + name => 'overrightarrow', alias => '\overrightarrow'); +DefMath('\lx@math@overleftarrow{}', "\x{2190}", + operator_role => 'OVERACCENT', scriptpos => 'mid', operator_stretchy => 'true', + name => 'overleftarrow', alias => '\overleftarrow'); +DefMath('\lx@math@underrightarrow{}', "\x{2192}", + operator_role => 'UNDERACCENT', scriptpos => 'mid', operator_stretchy => 'true', + name => 'underrightarrow', alias => '\underrightarrow'); +DefMath('\lx@math@underleftarrow{}', "\x{2190}", + operator_role => 'UNDERACCENT', scriptpos => 'mid', operator_stretchy => 'true', + name => 'underleftarrow', alias => '\underleftarrow'); +DefMath('\lx@math@overbrace{}', "\x{23DE}", + operator_role => 'OVERACCENT', scriptpos => 'mid', operator_stretchy => 'true', + name => 'overbrace', alias => '\overbrace', robust => 1); +DefMath('\lx@math@underbrace{}', "\x{23DF}", + operator_role => 'UNDERACCENT', scriptpos => 'mid', operator_stretchy => 'true', + name => 'underbrace', alias => '\underbrace', robust => 1); # Careful: Use \protect so that it doesn't expand too early in alignments, etc. # [Really shouldn't use \protect, since this is a TeX primitive and \protect is LaTeX] diff --git a/lib/LaTeXML/Engine/plain.pool.ltxml b/lib/LaTeXML/Engine/plain.pool.ltxml index 2473d9aef..45b52279a 100644 --- a/lib/LaTeXML/Engine/plain.pool.ltxml +++ b/lib/LaTeXML/Engine/plain.pool.ltxml @@ -736,9 +736,12 @@ DefConstructor('\@math@baccent {}', DefMathI('\to', undef, "\x{2192}", role => 'ARROW'); # RIGHTWARDS ARROW??? a bit more explicitly relation-like? -foreach my $op ('\hrulefill', '\dotfill', '\rightarrowfill', '\leftarrowfill', - '\upbracefill', '\downbracefill') { - DefPrimitiveI($op, undef, undef); } +DefMacro('\hrulefill', '\leaders\hrule\hfill'); +DefMacro('\dotfill', '\leaders\hbox{.}\hfill'); # Not exactly, but... +DefMath('\leftarrowfill', "\x{2190}", role => 'ARROW', stretchy => 'true'); +DefMath('\rightarrowfill', "\x{2192}", role => 'ARROW', stretchy => 'true'); +DefMath('\upbracefill', "\x{23DF}", role => 'ARROW', stretchy => 'true'); # for \underbrace +DefMath('\downbracefill', "\x{23DE}", role => 'ARROW', stretchy => 'true'); # for \overbrace Let('\sp', T_SUPER); Let('\sb', T_SUB); @@ -1218,11 +1221,9 @@ DefMath('\dot Digested', "\x{02D9}", operator_role => 'OVERACCENT'); # DOT DefMath('\ddot Digested', UTF(0xA8), operator_role => 'OVERACCENT'); # DIAERESIS DefMath('\widehat Digested', UTF(0x5E), operator_role => 'OVERACCENT'); # CIRCUMFLEX ACCENT [plain? also amsfonts] DefMath('\widetilde Digested', UTF(0x7E), operator_role => 'OVERACCENT'); # TILDE [plain? also amsfonts] -# These aren't handled as simple accents by TeX, so no Digested -DefMath('\overbrace {}', "\x{23DE}", operator_role => 'OVERACCENT', # TOP CURLY BRACKET - scriptpos => 'mid', robust => 1); -DefMath('\underbrace {}', "\x{23DF}", operator_role => 'UNDERACCENT', # BOTTOM CURLY BRACKET - scriptpos => 'mid', robust => 1); + +Let('\overbrace', '\lx@math@overbrace'); +Let('\underbrace', '\lx@math@underbrace'); # NOTE that all the above accents REQUIRE math mode # EXCEPT underline, overrightarrow and overleftarrow! diff --git a/t/ams/mathtools.xml b/t/ams/mathtools.xml index 7173f2336..0d49e03bf 100644 --- a/t/ams/mathtools.xml +++ b/t/ams/mathtools.xml @@ -1461,7 +1461,7 @@ Then a switch of tag forms.

- + + @@ -1492,7 +1492,7 @@ Then a switch of tag forms.

- + + 1 diff --git a/t/complex/physics.xml b/t/complex/physics.xml index d9b74f3d7..34a9174e0 100644 --- a/t/complex/physics.xml +++ b/t/complex/physics.xml @@ -661,13 +661,13 @@ a - - + + a - - + + a diff --git a/t/fonts/abxtest.xml b/t/fonts/abxtest.xml index f91b019a5..3046acd62 100644 --- a/t/fonts/abxtest.xml +++ b/t/fonts/abxtest.xml @@ -4696,7 +4696,7 @@ - + A @@ -4716,7 +4716,7 @@ - + A @@ -5022,8 +5022,8 @@
- - + + A @@ -5042,8 +5042,8 @@
- - + + A diff --git a/t/fonts/mathaccents.xml b/t/fonts/mathaccents.xml index 49a1954ff..80f64cf79 100644 --- a/t/fonts/mathaccents.xml +++ b/t/fonts/mathaccents.xml @@ -639,7 +639,7 @@ dot, ddot, overline, widehat, widetilde)

[ - + A ] @@ -654,7 +654,7 @@ dot, ddot, overline, widehat, widetilde)

[ - + ] @@ -669,7 +669,7 @@ dot, ddot, overline, widehat, widetilde)

[ - + A ] @@ -684,7 +684,7 @@ dot, ddot, overline, widehat, widetilde)

[ - + A @@ -704,7 +704,7 @@ dot, ddot, overline, widehat, widetilde)

[ - + A @@ -743,7 +743,7 @@ dot, ddot, overline, widehat, widetilde)

- + A @@ -762,7 +762,7 @@ dot, ddot, overline, widehat, widetilde)

- + A @@ -781,7 +781,7 @@ dot, ddot, overline, widehat, widetilde)

- + A @@ -800,7 +800,7 @@ dot, ddot, overline, widehat, widetilde)

- + A @@ -820,11 +820,11 @@ dot, ddot, overline, widehat, widetilde)

- + - + f o diff --git a/t/math/sampler.xml b/t/math/sampler.xml index a85e112f8..3f00974ed 100644 --- a/t/math/sampler.xml +++ b/t/math/sampler.xml @@ -1239,8 +1239,8 @@ some as accents, and pre-scripts (m:multiscripts, a - - + + def b