0

This is a bit of a newbie question. I am not quite sure what words to search for...

I am currently using latexml to generate html pages from latex documents. Since the html documents are procedurally generated (and should be regenerated whenever the latex files change) manually editing them is not an option. Now to make proofs collapsible I essentially replace the div tags with details and convert the headline into the summary:

// https://stackoverflow.com/a/65090521/6662425
function changeTag (node, tag) {
    const clone = document.createElement(tag);
    for (const attr of node.attributes) {
      clone.setAttributeNS(null, attr.name, attr.value);
    }
    while (node.firstChild) {
      clone.appendChild(node.firstChild);
    }
    node.replaceWith(clone);
    return clone;
}

window.addEventListener("load", function() {
    const proofs = document.getElementsByClassName("ltx_proof");

    if(proofs.size != 0){
        for(let proof of proofs) {
            proof = changeTag(proof, "details");
            proof_name = changeTag(proof.children[0], "summary");
            proof_name.classList.remove("ltx_runin");
        }
    }
})

which is in some sense tragic, as it waits for the site to load to modify the site once and then pretend it never existed. The html document could have been served like that in the first place of course. So the question is: Is there a way to execute java script server side to realize these static modifications as an html document?

Or would I have to use a different language for that?

Felix B.
  • 905
  • 9
  • 23
  • The normal way to do this is to configure the generator to generate what you want in the first place. – Mat Mar 28 '22 at 09:04
  • @Mat not an option - it is not configurable enough. I can not even ask it to put the javascript at the end of the html (which is why it currently registers as an event listener for the page to fully load). – Felix B. Mar 28 '22 at 09:08
  • Apparently my previous comment is wrong: you can load the javascript at the end (https://github.com/brucemiller/LaTeXML/issues/1834#issuecomment-1086684821) `--xsltparameter=LATEJS:true` – Felix B. Apr 02 '22 at 20:54

0 Answers0