Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

attempt to parse display math for proper PTX md/mrow structure when a… #1089

Merged
merged 1 commit into from
Aug 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions macros/core/PGbasicmacros.pl
Original file line number Diff line number Diff line change
Expand Up @@ -1968,11 +1968,26 @@ sub general_math_ev3 {
$out = "`$in`" if $mode eq "inline";
$out = '<DIV ALIGN="CENTER">`' . $in . '`</DIV>' if $mode eq "display";
} elsif ($displayMode eq "PTX") {
#protect XML control characters
# protect XML control characters
$in =~ s/\&(?!([\w#]+;))/\\amp /g;
$in =~ s/</\\lt /g;
$out = '<m>' . "$in" . '</m>' if $mode eq "inline";
$out = '<me>' . "$in" . '</me>' if $mode eq "display";
# attempt to parse align|alignat|gather into complete md/mrow structure, otherwise use me
if ($mode eq 'inline') {
$out = "<m>$in</m>";
} 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 {"<mrow>$_</mrow>"} @lines;
my $rows = join("\n", @rows);
$alignment = ($alignment eq 'align') ? '' : " alignment=\"$alignment\"";
$out = "<md${alignment}>\n$rows\n</md>";
} elsif ($mode eq 'display') {
$out = "<me>$in</me>";
}
} elsif ($displayMode eq "HTML_LaTeXMathML") {
$in = HTML::Entities::encode_entities($in);
$in = '{' . $in . '}';
Expand Down