From 2327bf803115f3f720f2a2c0479f7b8d297f1a9a Mon Sep 17 00:00:00 2001 From: Deyan Ginev Date: Wed, 24 Jan 2024 14:37:03 -0500 Subject: [PATCH] introduce post-processing option --mathstylize=mo_implied_space --- bin/latexmlpost | 10 ++++++---- lib/LaTeXML.pm | 5 +++-- lib/LaTeXML/Common/Config.pm | 1 + lib/LaTeXML/Post/MathML.pm | 19 ++++++++++++------- 4 files changed, 22 insertions(+), 13 deletions(-) diff --git a/bin/latexmlpost b/bin/latexmlpost index c1e0696839..2b13ad762b 100755 --- a/bin/latexmlpost +++ b/bin/latexmlpost @@ -36,8 +36,8 @@ my ($format, $extension, $is_html, $urlstyle) = (undef, undef, undef, 'server'); my ($numbersections) = (1); my ($stylesheet, $defaultresources, $icon, @css, @javascript, @xsltparameters); my ($mathimagemag) = (1.75); -my ($linelength, $plane1, $hackplane1) = (undef, undef, undef); -my ($dographics, $svg, $picimages) = (undef, undef, undef); +my ($linelength, $plane1, $hackplane1, $mathstylize) = (undef, undef, undef, undef); +my ($dographics, $svg, $picimages) = (undef, undef, undef); my @graphicsmaps = (); my ($split, $splitat, $splitpath, $splitnaming) = (undef, 'section', undef, 'id'); my ($navtoc) = (undef); @@ -123,6 +123,7 @@ GetOptions("quiet" => sub { $verbosity--; }, "mathsvg" => sub { addMathFormat('svg'); }, "nomathsvg" => sub { removeMathFormat('svg'); }, "linelength=i" => \$linelength, + "mathstylize=s" => \$mathstylize, "plane1!" => \$plane1, "hackplane1!" => \$hackplane1, "presentationmathml|pmml" => sub { addMathFormat('pmml'); }, @@ -472,8 +473,9 @@ sub assemble_postprocessors { require LaTeXML::Post::MathML::Presentation; push(@mprocs, LaTeXML::Post::MathML::Presentation->new( linelength => $linelength, - (defined $plane1 ? (plane1 => $plane1) : (plane1 => 1)), - ($hackplane1 ? (hackplane1 => 1) : ()), + (defined $plane1 ? (plane1 => $plane1) : (plane1 => 1)), + ($hackplane1 ? (hackplane1 => 1) : ()), + ($mathstylize ? (mathstylize => $mathstylize) : ()), %OPTIONS)); } elsif ($fmt eq 'cmml') { require LaTeXML::Post::MathML::Content; diff --git a/lib/LaTeXML.pm b/lib/LaTeXML.pm index 6c795d3a38..36f75d5d14 100644 --- a/lib/LaTeXML.pm +++ b/lib/LaTeXML.pm @@ -506,8 +506,9 @@ sub convert_post { require LaTeXML::Post::MathML::Presentation; push(@mprocs, LaTeXML::Post::MathML::Presentation->new( linelength => $$opts{linelength}, - (defined $$opts{plane1} ? (plane1 => $$opts{plane1}) : (plane1 => 1)), - ($$opts{hackplane1} ? (hackplane1 => 1) : ()), + (defined $$opts{plane1} ? (plane1 => $$opts{plane1}) : (plane1 => 1)), + ($$opts{hackplane1} ? (hackplane1 => 1) : ()), + ($$opts{mathstylize} ? (mathstylize => $$opts{mathstylize}) : ()), %PostOPS)); } elsif ($fmt eq 'cmml') { require LaTeXML::Post::MathML::Content; diff --git a/lib/LaTeXML/Common/Config.pm b/lib/LaTeXML/Common/Config.pm index 854910c0d1..c8d21b0ce7 100644 --- a/lib/LaTeXML/Common/Config.pm +++ b/lib/LaTeXML/Common/Config.pm @@ -94,6 +94,7 @@ sub getopt_specification { # However, IF combining, then will need to support a id/ref mechanism. "mathimagemagnification=f" => \$$opts{mathimagemag}, "linelength=i" => \$$opts{linelength}, + "mathstylize=s" => \$$opts{mathstylize}, "plane1!" => \$$opts{plane1}, "hackplane1!" => \$$opts{hackplane1}, "mathimages" => sub { addMathFormat($opts, 'images'); }, diff --git a/lib/LaTeXML/Post/MathML.pm b/lib/LaTeXML/Post/MathML.pm index e3d0cadad1..703683f3f9 100644 --- a/lib/LaTeXML/Post/MathML.pm +++ b/lib/LaTeXML/Post/MathML.pm @@ -18,8 +18,8 @@ use LaTeXML::Util::Unicode; use LaTeXML::Post; use LaTeXML::Common::Font; use List::Util qw(max); -use base qw(LaTeXML::Post::MathProcessor); -use base qw(Exporter); +use base qw(LaTeXML::Post::MathProcessor); +use base qw(Exporter); our @EXPORT = ( qw( &DefMathML ), qw( &pmml &pmml_scriptsize &pmml_smaller @@ -710,9 +710,10 @@ sub stylizeContent { # For each mathvariant, and for each of those 5 groups, there is a linear mapping, # EXCEPT for chars defined before Plain 1, which already exist in lower blocks. # Get desired mapping strategy - my $plane1 = $$LaTeXML::Post::MATHPROCESSOR{plane1}; - my $plane1hack = $$LaTeXML::Post::MATHPROCESSOR{hackplane1}; - my $u_variant = $variant + my $plane1 = $$LaTeXML::Post::MATHPROCESSOR{plane1}; + my $plane1hack = $$LaTeXML::Post::MATHPROCESSOR{hackplane1}; + my $mathstylize = $$LaTeXML::Post::MATHPROCESSOR{mathstylize} || ''; + my $u_variant = $variant && ($plane1hack ? $plane1hackable{$variant} : ($plane1 ? $variant : undef)); my $u_text = ($tag ne 'm:mtext') && $u_variant && unicode_convert($text, $u_variant); @@ -749,7 +750,11 @@ sub stylizeContent { $size = undef if $stretchy; # Ignore size, if we're stretching. my $stretchyhack = undef; if ($text =~ /^[\x{2061}\x{2062}\x{2063}]*$/) { # invisible get no size or stretchiness - $stretchy = $size = undef; } + $stretchy = $size = undef; + # If requested, switch implied mo to space + if ($text eq "\x{2062}" and $mathstylize eq 'mo_implied_space') { + $text = "\x{200B}"; + } } if ($size) { if ($size eq ($LaTeXML::MathML::SIZE || 'text')) { # If default size, no need to mention. $size = undef; } @@ -1075,7 +1080,7 @@ sub space_walk { space_walk($self, $prev); while (my $next = shift(@nodes)) { my $invisop; # Save Invisible operators as potential target for (l|r)space - if (($$next[0] eq 'm:mo') && $$next[2] && ($$next[2] =~ /^[\x{2061}\x{2062}\x{2063}]*$/)) { + if (($$next[0] eq 'm:mo') && $$next[2] && ($$next[2] =~ /^[\x{200B}\x{2061}\x{2062}\x{2063}]*$/)) { $invisop = $next; $next = shift(@nodes); last unless $next; }