LaTeXML
view release on metacpan or search on metacpan
lib/LaTeXML/Post/UnicodeMath.pm view on Meta::CPAN
UTF(0x60) => "\x{0300}", # \grave
"\x{02D9}" => "\x{0307}", # \dot
UTF(0xAB) => "\x{0308}", # \ddot
UTF(0xAF) => "\x{0304}", # \bar, \overline
"\x{2192}" => "\x{20D7}", # \vec
"\x{02D8}" => "\x{0306}", # \breve
"o" => "\x{030A}", # \r
"\x{02DD}" => "\x{030B}", # \H
);
our %underaccents = (
UTF(0xB8) => "\x{0327}", # \c
'.' => "\x{0323}", # dot below
UTF(0xAF) => "\x{0331}", # macron below
"=" => "\x{0361}", # \t
"," => "\x{0361}", # lfhook
);
# \overbrace, \underbrace, \overleftarrow ??
sub unimath_overaccent {
my ($op, $base) = @_;
my $acc = $op->textContent;
my $cacc = $acc && $overaccents{$acc};
my ($ubase, $uprec) = unimath_internal($base);
$ubase = '(' . $ubase . ')' if length($ubase) > 1;
return ($ubase . ($cacc ? $cacc : "\x{252C}" . $acc), $PREC_SCRIPTOP); }
sub unimath_underaccent {
my ($op, $base) = @_;
my $acc = $op->textContent;
my $cacc = $acc && $underaccents{$acc};
my ($ubase, $uprec) = unimath_internal($base);
$ubase = '(' . $ubase . ')' if length($ubase) > 1; # maybe NBSP, too???
return ($ubase . ($cacc ? $cacc : "\x{252C}" . $acc), $PREC_SCRIPTOP); }
# Handle text contents.
# We probably should pass this back to the same code used in CrossRef.
# But also, there's the question of what to do with nested math?
# Is that even allowable in UnicodeMath?
sub unimath_text {
my (@nodes) = @_;
return ('"' . join('', map { (ref $_ ? $_->textContent : $_); } @nodes) . '"', $PREC_SYMBOL); }
sub unimath_error {
return unimath_text('ERROR ', @_); }
#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
# Tranlators
#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
DefUnicodeMath('Apply:?:?', \&unimath_prefix);
DefUnicodeMath('Apply:ADDOP:?', \&unimath_infix);
DefUnicodeMath('Apply:MULOP:?', \&unimath_infix);
DefUnicodeMath('Apply:BINOP:?', \&unimath_infix);
DefUnicodeMath('Apply:RELOP:?', \&unimath_infix);
DefUnicodeMath('Apply:METARELOP:?', \&unimath_infix);
DefUnicodeMath('Apply:ARROW:?', \&unimath_infix);
DefUnicodeMath('Apply:COMPOSEOP:?', \&unimath_infix);
DefUnicodeMath("Apply:DIFFOP:?", \&unimath_prefix);
DefUnicodeMath('Apply:BIGOP:?', \&unimath_prefix);
DefUnicodeMath('Apply:INTOP:?', \&unimath_prefix);
DefUnicodeMath('Apply:SUMOP:?', \&unimath_prefix);
DefUnicodeMath('Apply:?:formulae', \&unimath_map);
DefUnicodeMath('Apply:?:multirelation', \&unimath_args);
DefUnicodeMath('Apply:?:limit-from', \&unimath_prefix);
DefUnicodeMath('Apply:?:annotated', \&unimath_prefix);
DefUnicodeMath('Apply:FRACOP:?', sub {
my ($op, $num, $den, @more) = @_;
my $thickness = $op->getAttribute('thickness');
if (defined $thickness) { # Hmm? maybe not even a fraction?
return ('(' . unimath_nested($num, 0) . UTF(0xA6) . unimath_nested($den, 0) . ')', $PREC_SYMBOL); }
else {
return (unimath_nested($num, $PREC_MULOP) . '/' . unimath_nested($den, $PREC_MULOP), 1); } });
DefUnicodeMath('Apply:MODIFIEROP:?', \&unimath_infix);
DefUnicodeMath('Apply:MIDDLE:?', \&unimath_infix);
DefUnicodeMath('Apply:SUPERSCRIPTOP:?', \&unimath_sup);
DefUnicodeMath('Apply:SUBSCRIPTOP:?', \&unimath_sub);
# These could search for candidate combining chars?
DefUnicodeMath('Apply:OVERACCENT:?', \&unimath_overaccent);
DefUnicodeMath('Apply:UNDERACCENT:?', \&unimath_underaccent);
DefUnicodeMath('Apply:POSTFIX:?', sub { # Reverse presentation, no @apply
my ($op) = unimath_internal($_[0]);
return (unimath_nested($_[1], $PREC_MULOP) . $op, $PREC_MULOP); });
DefUnicodeMath('Apply:?:square-root', sub {
return ("\x{221A}" . unimath_nested($_[1], $PREC_MULOP), $PREC_MULOP); });
DefUnicodeMath('Apply:?:nth-root', sub {
# Could convert to \x{221B} for cube, \x{221C} for quartic
my ($n) = unimath_internal($_[2]);
my $op = ($n eq '2' ? "\x{221A}"
: ($n eq '3' ? "\x{221B}"
: ($n eq '4' ? "\x{221C}"
: "\\root " . $n . "\\of")));
return ($op . unimath_nested($_[1], $PREC_MULOP), $PREC_MULOP); });
DefUnicodeMath('Apply:ENCLOSE:?', sub {
my ($op, $base) = @_;
return (unimath_nested($base, $PREC_SYMBOL), $PREC_SYMBOL); });
# ================================================================================
# cfrac! Ugh!
DefUnicodeMath('Apply:?:continued-fraction', sub {
return unimath_error("continued fraction"); });
#================================================================================
1;
__END__
=pod
=head1 NAME
C<LaTeXML::Post::UnicodeMath> - Post-Processing module for converting math to UnicodeMath.
=head1 SYNOPSIS
C<LaTeXML::Post::UnicodeMath> converts math into UnicodeMath.
It should be usable as a primary math format (alone), or as a secondary format.
This module can also be used to convert ltx:XMath expressions into plain Unicode strings
for use in attributes.
( run in 0.664 second using v1.01-cache-2.11-cpan-437f7b0c052 )