From 0eb382400cde2057cedda1cd0c6037375473db58 Mon Sep 17 00:00:00 2001 From: Alex Jordan Date: Tue, 30 Jul 2024 14:29:55 -0700 Subject: [PATCH] attempt to parse display math for proper PTX md/mrow structure when applicable --- macros/core/PGbasicmacros.pl | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/macros/core/PGbasicmacros.pl b/macros/core/PGbasicmacros.pl index 536e86f5f..d7df61686 100644 --- a/macros/core/PGbasicmacros.pl +++ b/macros/core/PGbasicmacros.pl @@ -1968,11 +1968,26 @@ sub general_math_ev3 { $out = "`$in`" if $mode eq "inline"; $out = '
`' . $in . '`
' if $mode eq "display"; } elsif ($displayMode eq "PTX") { - #protect XML control characters + # protect XML control characters $in =~ s/\&(?!([\w#]+;))/\\amp /g; $in =~ s/' . "$in" . '' if $mode eq "inline"; - $out = '' . "$in" . '' if $mode eq "display"; + # attempt to parse align|alignat|gather into complete md/mrow structure, otherwise use me + if ($mode eq 'inline') { + $out = "$in"; + } elsif ($mode eq 'display' && $in =~ /^\s*\\begin\{(align|alignat|gather)}((?!\\end\{\1}).)*\\end\{\1}\s*$/s) { + my $alignment = $1; + my $lines = + ($in =~ s/^\s*\\begin\{$alignment}\s*(((?!\\end\{$alignment}).)*)\s*\\end\{$alignment}\s*$/$1/sr); + $lines =~ s/^\{\d+\}// if ($alignment eq 'alignat'); + my @lines = split(/\\\\\n?/, $lines); + @lines = map { $_ =~ s/^\s+|\s+$//r } @lines; + my @rows = map {"$_"} @lines; + my $rows = join("\n", @rows); + $alignment = ($alignment eq 'align') ? '' : " alignment=\"$alignment\""; + $out = "\n$rows\n"; + } elsif ($mode eq 'display') { + $out = "$in"; + } } elsif ($displayMode eq "HTML_LaTeXMathML") { $in = HTML::Entities::encode_entities($in); $in = '{' . $in . '}';