Menu

Putting HTML in TeX

2009-05-19
2013-04-29
  • Nathan Carter

    Nathan Carter - 2009-05-19

    I want to do some post-processing of the HTML created by jsMath using my own JavaScript routines.  To this end, it would be handy to be able to mark specific portions of the TeX source with flags that somehow get preserved in the final output.  For instance, I might like to do something like this

        $\frac{\MARK{6,MyNumerator}}{7}$

    and get an output that was like the following (note that most of this is right out of http://www.math.union.edu/~dpvc/jsMath/jsMath-lab.html but I just added two lines, clearly marked).

    <SPAN CLASS="typeset">
      <nobr>
        <span class="scale">
          <span class="spacer" style="margin-left:0.12em"></span>
          <span style="position: relative; top:0.344em;">
            <span class="size2">
              <span class="cmr10">3</span>
            </span>
          </span>

          <SPAN MARK="MyNumerator">    <!--  THIS LINE IS NEW  -->

            <span style="position: relative; margin-left:-0.364em; top:-0.393em;">
              <span class="size2">
                <span class="cmr10">6</span>
              </span>
            </span>

          </SPAN>    <!--  THIS LINE IS NEW  -->

          <span style="position: relative; margin-left:-0.364em; top:-0.27em;">
            <span class="blank" style="border-left:0.364em solid;height:1.5px;"></span>
          </span>
          <span class="spacer" style="margin-left:0.12em"></span>
          <span class="blank" style="height:1.289em;vertical-align:-0.394em"></span>
        </span>
      </nobr>
    </SPAN>

    This would make it much easier to find in the output things that you're looking for from the input.  Alternatively, rather than wrapping in yet another span, the existing span at that level could simply have the MARK attribute added.

    I looked through the jsMath source to try to find a way to do this, but it wasn't clear to me how.  Perhaps there already is a way?

    Thanks for any help available.

    Nathan

    PS: I'm not intending this for web use, but for use within a Webkit widget embedded in a math-aware application.

     
    • Davide P. Cervone

      You can get something very similar to this via the \cssId macro that is part of the HTML extension, which is loaded automatically when first used.  Something like

      \frac{\cssId{MyNumerator}{6}}{7}

      would produce HTML like what you had above, but with <SPAN ID="MyNumerator"> not <SPAN MARK="MyNumerator">.  Then you can use document.getElementById("MyNumerator") to obtain the DOM element for the SPAN you have marked.

      If you really need it to use MARK rather than ID, then you can look in jsMath/extensions/HTML.js for the implementation of \cssId and roll your own \MARK macro.

      Davide

       
      • Nathan Carter

        Nathan Carter - 2009-05-19

        Excellent!  No, MARK was not essential--anything would do just fine.  Assuming you can nest these things (\cssId{\frac{\cssId{...}}{...}}) then I'm all set for my project.  No need to reply...I'll test that one out on my own.  Thanks a lot!

        Nathan

         

Log in to post a comment.