2

I am attempting to place latex-style math formulas into a haskell diagram.

The documentation pages http://projects.haskell.org/diagrams/doc/manual.html#essential-concepts and http://projects.haskell.org/diagrams/doc/tutorials.html suggest that one can use something called 'mathjax' to achieve this.

Is there an explanation or example somewhere of how to actually code this?


Attempting to follow the documentation at those links, my best guess for how would be something like:

mathDiagram :: Diagram B
mathDiagram = stroke $ textSVG "`2 + \sqrt{\pi}`:math:" 1

But this of course gives an error:

induction.hs:13:35: error:
    lexical error in string/character literal at character 's'
duplode
  • 33,731
  • 7
  • 79
  • 150
mherzl
  • 5,624
  • 6
  • 34
  • 75
  • Put `$` before and after the Latex code instead of `\`` – Code-Apprentice Oct 24 '16 at 23:38
  • 2
    The lexical error is easy to fix: escape your backslashes, as in ```"'2 + \\sqrt{\\pi}`:math:"```. No idea whether that's enough to reach your goal, though; probably not. – Daniel Wagner Oct 24 '16 at 23:41
  • 2
    I don't think there's any supported way to get LaTeX formulæ in diagrams. What the [diagrams tutorial](http://projects.haskell.org/diagrams/doc/tutorials.html) says about LaTeX is only meta, about _this particular documentation_, i.e. it says you can include LaTeX if you're editing `projects.haskell.org/diagrams/doc`, which as a browser-displayed page supports MathJax easily. I reckon it would _in principle_ also be possible to import math stuff as some MathJax-rendered SVG back into generic diagrams, but this is certainly not as simple as writing something like `textSVG "$2 + \\sqrt{\\pi}$"`. – leftaroundabout Oct 25 '16 at 00:09

1 Answers1

2

You can do this using the diagrams-pgf backend. Just use the text function and put dollar signs around your text. Also, see here for an explanation of how to include diagrams in a LaTeX document: http://projects.haskell.org/diagrams/doc/latex.html .

Brent Yorgey
  • 2,043
  • 16
  • 17