[IPython-dev] More complicated LaTeX output in IPython notebook cells.

Mark Voorhies mark.voorhies@ucsf....
Tue Jun 18 12:17:47 CDT 2013


On 06/18/2013 09:58 AM, Thomas Kluyver wrote:
> On 18 June 2013 17:48, Rick Muller <rpmuller@gmail.com> wrote:
>
>> which doesn't display, I think because the xyqcirc.tex stuff isn't
>> supported by mathjax.
>> Does anyone know of a workaround for this, or should I start honing my SVG
>> skills to generate a more native option?
>>
>
> You're probably right about Mathjax - it's designed to handle a subset of
> TeX, and I doubt quantum circuit diagrams are in that subset ;-).
>
> If you need a workaround, you could write a wrapper that will do the LaTeX
> rendering in the kernel, and display it as a png.

One route for latex->png/svg is to use inkscape as a headless pdf renderer.
The default fonts are not beautiful, but it is pretty general, e.g.:

from IPython.core.display import Image, SVG

open("example.tex","w").write(r"""
\documentclass[12pt]{article}
\begin{document}
\begin{eqnarray}
1 - p_i &=& \left(1-\frac{p_m}{N_g}\right)^n \\
\log(1 - p_i) &=& \log\left[\left(1-\frac{p_m}{N_g}\right)^n\right] \\
\log(1 - p_i) &=& n\log\left(1-\frac{p_m}{N_g}\right) \\
\label{eq:n}
n &=& \frac{\log(1-p_i)}{\log(1-\frac{p_m}{N_g})}
\end{eqnarray}
\end{document}
""")

!pdflatex example.tex

!inkscape example.pdf --export-png=example.png
Image(filename="example.png")

!inkscape example.pdf --export-plain-svg=example.svg
SVG(filename = "example.svg")

--Mark




More information about the IPython-dev mailing list