3

I have started putting Mathematica code in the annotations portion of on my website, but right now I am editing the code manually. Is there an more robust automated way to do this? Example HTML page shows annotations in menu.

<!doctype html><script type="text/x-mathjax-config">
MathJax.Hub.Config({
  MathMenu: {
    semanticsAnnotations: {
      Mathematica:["Mathematica"]
    }
  }
});
</script><script type="text/javascript" async
  src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-MML-AM_CHTML">
</script>
<math xmlns='http://www.w3.org/1998/Math/MathML'>
 <semantics>
 <mrow>
  <mi>sin</mi>
  <mo>&#8289;</mo>
  <mo>(</mo>
  <mi>x</mi>
  <mo>)</mo>
 </mrow>
 <annotation encoding="Mathematica">Sin[x]</annotation>
 </semantics>
</math>

I am just looking to automate the generation of the MathML portion of the code.

William
  • 7,595
  • 2
  • 22
  • 70
  • 2
    Notice that without your answer it is not very clear what kind of answer would you like to get. What can be a possible input etc. – Kuba Aug 11 '18 at 06:53

1 Answers1

1

Here is a rather lazy way that works okay for regular input equations but needs some editing to work with any cell.

equation = Sin[x];
"<math xmlns='http://www.w3.org/1998/Math/MathML'><semantics>" <> 
 StringJoin[Drop[Drop[StringSplit[
     ExportString[equation, "MathML"], "\n"], -1], 1], 
  ""] <> "<annotation encoding=\"Mathematica\">" <> 
 ToString@InputForm[
   equation] <> "</annotation>" <> "</semantics></math>"
William
  • 7,595
  • 2
  • 22
  • 70