slatex / sTeX

A semantic Extension of TeX/LaTeX
50 stars 9 forks source link

complex bvars do not work in \symdef #36

Closed kohlhase closed 9 years ago

kohlhase commented 10 years ago

In smlomg/linear-algebra/source/matrix.en we have

  \symdef[bvars={2,3},bargs={4,5,6,7}]{cmatrix}[7]{[#1]_{#4\leq{#2}\leq{#5},#6\leq{#3}\leq{#7}}}

and that generates

   <omdoc:symbol name="cmatrix" xml:id="cmatrix.sym" about="#cmatrix.sym" stex:srcref="smglom/linear-algebra/source/matrix.tex#textrange(from=11;0,to=11;96)"/>
    <omdoc:notation cd="matrix" name="cmatrix">
      <omdoc:prototype>
        <om:OMBIND>
          <om:OMA>
            <om:OMS cd="matrix" cr="fun" name="cmatrix"/>
            <omdoc:expr name="arg4"/>
            <omdoc:expr name="arg5"/>
            <omdoc:expr name="arg6"/>
            <omdoc:expr name="arg7"/>
          </om:OMA>
          <om:OMBVAR>
            <omdoc:exprlist name="args">
              <omdoc:expr name="arg"/>
            </omdoc:exprlist>
          </om:OMBVAR>
          <omdoc:expr name="arg1"/>
        </om:OMBIND>
      </omdoc:prototype>
      <omdoc:rendering>
        <m:msub>
          <m:mrow>
            <m:mo stretchy="false">[</m:mo>
            <omdoc:render name="arg1"/>
            <m:mo stretchy="false">]</m:mo>
          </m:mrow>
          <m:mrow>
            <m:mrow xml:id="XM1e.pmml">
              <omdoc:render name="arg4"/>
              <m:mo xml:id="XM1a.pmml">&#x2264;</m:mo>
              <omdoc:render name="arg2"/>
              <m:mo xml:id="XM1c.pmml">&#x2264;</m:mo>
              <omdoc:render name="arg5"/>
            </m:mrow>
            <m:mo>,</m:mo>
            <m:mrow xml:id="XM2e.pmml">
              <omdoc:render name="arg6"/>
              <m:mo xml:id="XM2a.pmml">&#x2264;</m:mo>
              <omdoc:render name="arg3"/>
              <m:mo xml:id="XM2c.pmml">&#x2264;</m:mo>
              <omdoc:render name="arg7"/>
            </m:mrow>
          </m:mrow>
        </m:msub>
      </omdoc:rendering>
  </notation>

(elided the variant, since it is similar). It seems that the treatment of bvar={2,3} is wrong, since that should generate

<om:OMBVAR>
   <omdoc:expr name="arg2"/>
   <omdoc:expr name="arg3"/>
</om:OMBVAR>

instead of an expression ist. Correspondingly, the generated semantic macro does not work, used in

 $A=\cmatrix{\livar{a}{i,j}}ij1n1m$

this generates

<om:OMOBJ stex:srcref="smglom/linear-algebra/source/matrix.en.tex#textrange(from=21;76,to=22;45)">
  <om:OME>
    <om:OMS cd="ambiguous" name="fragments"/>
    <om:OMS cd="unknown" name="A"/>
    <om:OMS cd="equal" name="equal"/>
    <om:OMBIND>
      <om:OMA>
    <om:OMS cd="matrix" name="cmatrix"/>
    <om:OMI>1</om:OMI>
    <om:OMV name="n"/>
    <om:OMI>1</om:OMI>
    <om:OMV name="m"/>
      </om:OMA>
      <om:OMBVAR>
    <om:OMV name="name.cvar.2" xml:id="cvar.2d.om"/>
      </om:OMBVAR>
      <om:OMV name="i"/>
    </om:OMBIND>
  </om:OME>
</om:OMOBJ>
kohlhase commented 9 years ago

I think I know the culprit: in sTeX/sty/modules/modules.dtx line 386ff we find

  if (scalar(@bvars) || scalar(@bargs)) {
    $document->openElement('om:OMBVAR');
    if ((scalar(@bvars)==1) && ($bvars[0] != $assocarg)) {
      $document->insertElement('omdoc:expr',undef,(name=>"arg".$bvars[0]));
    } else {
      $document->openElement('omdoc:exprlist',(name=>"args"));
      $document->insertElement('omdoc:expr',undef,(name=>"arg"));
      $document->closeElement('omdoc:exprlist');
    }
    $document->closeElement('om:OMBVAR');
  }

this generates the <om:OMBVAR> element in the prototype. It is missing a case: the case where scalar(@bvars)> 1, but they are a list. I think the code must be generalized to the following (pseudocode)

foreach i in  @bvars {
     {if $i = $assocarg 
                <omdoc:exprlist name="args"><omdoc:expr name="arg"/></omdoc:exprlist>
      else 
                <omdoc:expr name="arg$i"/>
      end}

that should be all that is needed. The generation of the <rendering> should be unaffected, since there is always only one assocarg. And that is treated as before.

dginev commented 9 years ago

Your solution sounds just right, I have implemented it.