openmathdocs / precalc

Modelling-based approach to pre-calculus materials: exponential, logarithmic, polynomial, rational, piecewise-defined, and trigonometric functions; transformations and composition of functions; parametric curves. Emphasizing the rule of four: graphically, numerically, verbally, and algebraically
0 stars 1 forks source link

Cross referencing in html #3

Closed cmhughes closed 9 years ago

cmhughes commented 9 years ago

I'm working on a cross referencing for the .html. There are a lot of different ways that this could go, but which ever way I try, I can't get round the idea of either having an auxilary file, or else a two-stage process, i.e convert to xml once to get the labels correct, then convert to html from there.

Alex, do you have any thoughts on this?

Alex-Jordan commented 9 years ago

I haven't thought this out down to the dirty details. But I can imagine there might be a way to use js, coupled with ids on the HTML elements.

So the HTML itself would not end up with any numbering hard-coded. Instead an element would jsut have its id tag. Then js would process the page looking for elements that should be enumerated, and create a look-up table for what ids go to what numbers, as well as output the numbers in the appropriate format to be seen on screen. The numbers could load near last, like how MathJax loads last. Then elsewhere, if there is a reference to that tag, js would look up its printed number.

This is only theoretical. I don't have enough experience with js to say if this outline is plausible.

I think the difficulty here may be one reason why Rob "enumerates" his theorems with acronyms instead of numbers.

cmhughes commented 9 years ago

That was actually my first thought as well :) I put together the following MWE yesterday--the .html, including the Figure and Table numbers was generated through an .xsl sheet (not posted here).

myfile.html

<?xml version="1.0" encoding="utf-8"?>
<html><script type="text/javascript" src="myfile.js"/><body onload="setupCrossRefs()">
  <div>
    <div class="figure" id="figure-function-derivative" cref="Figure 1">
      figure code goes here
      <caption>Figure 1: A function and its derivative</caption>
    </div>

    <div class="figure">
      figure code goes here
      <caption>Figure 2: A function and its derivative</caption>
    </div>
    <div class="table" id="tab-firsttablereference" cref="Table 1">
      table code goes here
      <caption>Table 1: tables are awesome</caption>
    </div>
  </div>
  <div>
    <div class="figure" id="figure-function-derivativecm" cref="Figure 1">
      figure code goes here
      <caption>Figure 1: A function and its derivative</caption>
    </div>

    <div class="figure">
      figure code goes here
      <caption>Figure 2: A function and its derivative</caption>
    </div>

    have a look at <cref object="figure-function-derivative"/>

    have a look at <cref object="???"/>

    <cref object="tab-firsttablereference"/>
  </div>
</body></html>

and here's the corresponding Javascript file:

myfile.js

function setupCrossRefs()
{
  var crossReferences = document.getElementsByTagName('cref');
  var crossRefId;
  var crossRefText;
  for(var i=0; i<crossReferences.length; i++ ){
    crossRefId = crossReferences[i].getAttribute('object');
    if(document.getElementById(crossRefId)!=null){
        crossRefText = document.getElementById(crossRefId).getAttribute('cref');
        crossReferences[i].innerHTML = ""+crossRefText+"";
    } else {
        crossReferences[i].innerHTML = "???";
    }
  }
}

It works fine, but I think I'll also explore other routes, for the following reasons:

I think I'll work towards more of a LaTeX approach: process the .xml file once, generate a 'cross reference' file (which could, itself, be xml), then process the original xml file again so as to update cross references.

Alex-Jordan commented 9 years ago

Ah OK. Sounds good. And I guess arara can help streamline with the extra processing.

Just as one last thought though, might there be a CSS solution? Even if there is, it likely has some of the downsides that you are considering. But it's perhaps worth a thought.

What you are working on here would likely be good for MBX in general. Have you considered posting about this on https://groups.google.com/forum/?fromgroups#!forum/mathbook-xml-support?

On Fri, Dec 5, 2014 at 7:40 AM, cmhughes notifications@github.com wrote:

That was actually my first thought as well :) I put together the following MWE yesterday--the .html, including the Figure and Table numbers was generated through an .xsl sheet (not posted here). myfile.html

<?xml version="1.0" encoding="utf-8"?>

Githubissues.
  • Githubissues is a development platform for aggregating issues.