(defn latex
" Returns the given LaTeX equation rendered as an java.awt.Image.
Options:
:color (default java.awt.Color/black) -- the text color
Examples:
(use '(incanter core charts stats latex))
(def latex-img (latex \"\\\\frac{(a+b)^2} {(a-b)^2}\"))
(save latex-img \"/tmp/latex-example1.png\")
(view \"file:///tmp/latex-example1.png\")
(view (latex \"f(x)=\\\\frac {1} {\\\\sqrt {2\\\\pi \\\\sigma ^2}} e^{\\\\frac {-(x - \\\\mu)^2}{2 \\\\sigma ^2}}\"))
(view (latex \"\\\\begin{pmatrix}
a & b & c \\\\\\\\
d & e & f \\\\\\\\
g & h & i
\\\\end{pmatrix}\"))
"
([latex-txt & options]
(let [opts (apply hash-map options)
color (or (:color opts) java.awt.Color/black)
formula (org.scilab.forge.jlatexmath.TeXFormula. latex-txt)
icon (doto (.createTeXIcon formula TeXConstants/STYLE_DISPLAY 20)
(.setInsets (java.awt.Insets. 5 5 5 5)))
image (java.awt.image.BufferedImage. (.getIconWidth icon)
(.getIconHeight icon)
java.awt.image.BufferedImage/TYPE_INT_ARGB)
g2 (doto (.createGraphics image)
(.setColor (java.awt.Color. 0 0 0 0))
(.fillRect 0 0 (.getIconWidth icon) (.getIconHeight icon)))
label (doto (javax.swing.JLabel.)
(.setForeground color))]
(do
(.paintIcon icon label g2 0 0)
image))))
Vars in
incanter.latex/latex:
defn
let
Used in 0 other vars
Comments top
No comments for latex. Log in to add a comment.