3
$\begingroup$

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.

$\endgroup$
  • 2
    $\begingroup$ 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. $\endgroup$ – Kuba Aug 11 '18 at 6:53
1
$\begingroup$

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>"
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.