Skip to content

Commit

Permalink
--noinvisibletimes: choose zero-width space over invisible times (#2303)
Browse files Browse the repository at this point in the history
  • Loading branch information
dginev authored Jan 28, 2024
1 parent 58389a8 commit 2f82c5f
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 13 deletions.
11 changes: 7 additions & 4 deletions bin/latexmlpost
Original file line number Diff line number Diff line change
Expand Up @@ -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, $invisibletimes) = (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);
Expand Down Expand Up @@ -123,6 +123,7 @@ GetOptions("quiet" => sub { $verbosity--; },
"mathsvg" => sub { addMathFormat('svg'); },
"nomathsvg" => sub { removeMathFormat('svg'); },
"linelength=i" => \$linelength,
"invisibletimes!" => \$invisibletimes,
"plane1!" => \$plane1,
"hackplane1!" => \$hackplane1,
"presentationmathml|pmml" => sub { addMathFormat('pmml'); },
Expand Down Expand Up @@ -472,8 +473,10 @@ 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) : ()),
(defined $invisibletimes ? (invisibletimes => $invisibletimes) :
(invisibletimes => 1)),
%OPTIONS)); }
elsif ($fmt eq 'cmml') {
require LaTeXML::Post::MathML::Content;
Expand Down
6 changes: 4 additions & 2 deletions lib/LaTeXML.pm
Original file line number Diff line number Diff line change
Expand Up @@ -506,8 +506,10 @@ 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) : ()),
(defined $$opts{invisibletimes} ? (invisibletimes => $$opts{invisibletimes}) :
(invisibletimes => 1)),
%PostOPS)); }
elsif ($fmt eq 'cmml') {
require LaTeXML::Post::MathML::Content;
Expand Down
1 change: 1 addition & 0 deletions lib/LaTeXML/Common/Config.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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},
"invisibletimes!" => \$$opts{invisibletimes},
"plane1!" => \$$opts{plane1},
"hackplane1!" => \$$opts{hackplane1},
"mathimages" => sub { addMathFormat($opts, 'images'); },
Expand Down
20 changes: 13 additions & 7 deletions lib/LaTeXML/Post/MathML.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -710,9 +710,12 @@ 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 $invisibletimes = $$LaTeXML::Post::MATHPROCESSOR{invisibletimes};
# just in case, default to "true" (classic behavior), if not specified
$invisibletimes = 1 unless defined $invisibletimes;
my $u_variant = $variant
&& ($plane1hack ? $plane1hackable{$variant}
: ($plane1 ? $variant : undef));
my $u_text = ($tag ne 'm:mtext') && $u_variant && unicode_convert($text, $u_variant);
Expand Down Expand Up @@ -749,7 +752,10 @@ 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 not($invisibletimes)) {
$text = "\x{200B}"; } }
if ($size) {
if ($size eq ($LaTeXML::MathML::SIZE || 'text')) { # If default size, no need to mention.
$size = undef; }
Expand Down Expand Up @@ -1075,7 +1081,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; }
Expand Down

0 comments on commit 2f82c5f

Please sign in to comment.