slatex / LaTeXML-Plugin-sTeX

A LaTeXML Plugin for Semantic LaTeX (sTeX)
LaTeX Project Public License v1.3c
2 stars 3 forks source link

presentation.sty.ltxml totally fails because CROSSREFOP handling LaTeXML postprocessing did not get moved from the KWARC branch. #140

Closed kohlhase closed 4 years ago

kohlhase commented 4 years ago

Dennis and I just found a problem with (almost all constructors in) presentation.sty.ltxml.

TLDR: We need help in extending the sTeX plugin with postprocessing!

The symptom is that in the (presentation MathML) renderin in the notation definitions, the \prefix presentation operator generates (if I disable omdocpost.xsl):

<omdoc:rendering ic="variant:ddo" argprec="          ">
        <ltx:Math mode="inline" xml:id="partial-derivative.notation5.m4" about="#partial-derivative.notation5.m4" stex:srcref="smglom/calculus/source/partial-derivative.tex#textrange(from=7;0,to=7;76)" tex="\crossrefOp[fun]{\frac{\partial}{\partial{arg:2}}}" text="CROSSREFOP@(partial-differential / partial-differential@(arg:2))" font="italic" fragid="partial-derivative.notation5.m4">
          <ltx:XMath>
            <ltx:XMApp role="CROSSREFOP">
              <ltx:XMTok cr="fun" role="CROSSREFOP"/>
              <ltx:XMApp>
                <ltx:XMTok mathstyle="text" meaning="divide" role="FRACOP"/>
                <ltx:XMTok meaning="partial-differential" mode="math" name="partial" role="OPERATOR" font="upright" fontsize="70%">βˆ‚</ltx:XMTok>
                <ltx:XMApp font="upright" fontsize="70%">
                  <ltx:XMTok meaning="partial-differential" mode="math" name="partial" role="OPERATOR">βˆ‚</ltx:XMTok>
                  <ltx:XMTok mode="math" role="ID">arg:2</ltx:XMTok>
                </ltx:XMApp>
              </ltx:XMApp>
            </ltx:XMApp>
          </ltx:XMath>
          <om:OMOBJ>
            <om:OMA>
              <om:OMV name="CROSSREFOP"/>
              <om:OMA>
                <om:OMS cd="latexml" name="divide"/>
                <om:OMS cd="latexml" name="partial-differential"/>
                <om:OMA>
                  <om:OMS cd="latexml" name="partial-differential"/>
                  <om:OMV name="arg:2"/>
                </om:OMA>
              </om:OMA>
            </om:OMA>
          </om:OMOBJ>
          <m:math about="#partial-derivative.notation5.m4" alttext="\crossrefOp[fun]{\frac{\partial}{\partial{arg:2}}}" display="inline">
            <m:mrow>
              <m:mi mathcolor="red">𝐢𝑅𝑂𝑆𝑆𝑅𝐸𝐹𝑂𝑃</m:mi>
              <m:mo mathvariant="italic"></m:mo>
              <m:mfrac>
                <m:mo mathvariant="normal">βˆ‚</m:mo>
                <m:mrow>
                  <m:mo mathvariant="italic">βˆ‚</m:mo>
                  <m:mo mathvariant="italic"></m:mo>
                  <m:mi mathvariant="italic">arg:2</m:mi>
                </m:mrow>
              </m:mfrac>
            </m:mrow>
          </m:math>
        </ltx:Math>
        <m:mrow>
          <m:mo fence="true">(</m:mo>
          <ltx:Math mode="inline" xml:id="partial-derivative.notation5.m5" about="#partial-derivative.notation5.m5" stex:srcref="smglom/calculus/source/partial-derivative.tex#textrange(from=7;0,to=7;76)" tex="arg:1" text="arg:1" font="italic" fragid="partial-derivative.notation5.m5">
            <ltx:XMath>
              <ltx:XMTok mode="math" role="ID" font="upright">arg:1</ltx:XMTok>
            </ltx:XMath>
            <om:OMOBJ>
              <om:OMV name="normal-arg:1"/>
            </om:OMOBJ>
            <m:math about="#partial-derivative.notation5.m5" alttext="arg:1" display="inline">
              <m:mi mathvariant="normal">arg:1</m:mi>
            </m:math>
          </ltx:Math>
          <m:mo fence="true">)</m:mo>
        </m:mrow>
      </omdoc:rendering>

in a nutshell, the problem is that

          <ltx:XMath>
            <ltx:XMApp role="CROSSREFOP">
              <ltx:XMTok cr="fun" role="CROSSREFOP"/>

is post-processed to

           <m:mrow>
              <m:mi mathcolor="red">𝐢𝑅𝑂𝑆𝑆𝑅𝐸𝐹𝑂𝑃</m:mi>
              <m:mo mathvariant="italic"></m:mo>

The later comes from the \prefix macro

DefMacro('\prefix[]{}{}','\@prefix[#1]{\ensuremath{\crossrefOp[fun]{#2}}}{\ensuremath{#3 }}');

where \crossrefOp is defined in presentation.sty.ltxml as

DefConstructor('\crossrefOp[]{}',
       "?#2(<ltx:XMApp role='CROSSREFOP'>"
              .  "<ltx:XMTok role='CROSSREFOP' cr='?#1(#1)(fun)'/>"
              .  "<ltx:XMWrap>#2</ltx:XMWrap>"
              ."</ltx:XMApp>)()",
   requireMath=>1);

obviously with the idea that this would be converted to a proper cross-reference in LaTeXML post-processing. But in the LaTeXML master there is nothing of the sort, but in the old KWARC fork of LaTeXML we find:

# Experimental; for an XMApp with role=ID, we treat it as a ci
# or ultimately as csymbol, if it had defining attributes,
# but we format its contents as pmml
sub cmml_decoratedSymbol {
  my ($item) = @_;
  return ['m:ci', {}, pmml($item)]; }

# Experimental; for an XMApp with role=CROSSREFOP, we treat it as a mo
# and we format its contents as pmml
# Note that we need to transfer the cr attribute of the XMApp to the m:mo
sub pmml_decoratedOperator {
  my ($head, @args) = @_;
  return undef if (!($head->getAttribute('role') eq "CROSSREFOP"));
  my $doc = $LaTeXML::Post::DOCUMENT;
  my $cr = (ref $head ? $head->getAttribute("cr") : "fun");
  $head->setAttribute("role", "SKIP");
  my $operator = pmml(@args);
  return undef unless $operator;    #bootstrap
  if ($$operator[0] =~ /^m:m[io]$/) {    #Unwrap if only a mi or mo
    $operator = $$operator[2];
    ['m:mo', { 'cr' => $cr },
      $operator]; }
  else {
    #If structure is present, add cr attribute to top level element
    $$operator[1]{'cr'} = $cr;
    $operator;
  } }
#Experiment: CROSSREFOP
DefMathML("Apply:CROSSREFOP:?", \&pmml_decoratedOperator, undef);
DefMathML("Token:SKIP:?", sub { undef; }, sub { undef; });

which looks exactly like the postprocessing we need.

It seems that we only need to integrate that into the sTeX plugin, but that does not have any post-processing yet, and I am not sure how to do that.

Any pointers would be very welcome.

Jazzpirate commented 4 years ago

Fixed locally by copying the experimental code from the KWARC fork of LaTeXML into my clone of brucemiller/LaTeXML. Seems to solve the problem for me, but not a long-term solution, obviously

kohlhase commented 4 years ago

you should probably commit that to master anyway.

Jazzpirate commented 4 years ago

Done: e113ac5adf2dc4907e94416f4d97cdec71386002