On Mon, Nov 17, 2014 at 3:13 PM, <jeanbigbo...@gmail.com> wrote:

> Thanks for all the replies:
>
> Aaron Meurer:
> I tried preview.  It looks like a LaTeX installation is required and on
> this particular system I'm on, I am not allowed to install it - same with
> the other suggested package.  Is there a workaround, perhaps directing the
> use of MathJax?
>

A little Googling reveals https://github.com/agrbin/svgtex, which uses
MathJax to generate an SVG (there are plenty of tools you can then use to
convert that to PNG).

Also https://github.com/jmorais/mathjax-to-png, although I'm not really
clear how that works.


> Jason Moore:
> I looked at the source code you suggested and did some experimentation.
> It led me to:
>
> http://stackoverflow.com/questions/24223695/python-spyder-display-symbolic-math
>
> This is tantalizingly close to what I'd like.  It works for some
> expressions such as the one in the SO example.
>
> from IPython.display import Image, displayfrom IPython.lib.latextools import 
> latex_to_png
>
> eq = r'F(k) = \int_{-\infty}^{\infty} f(x) e^{2\pi i k} dx'
> data = latex_to_png(eq, wrap=True)
> display(Image(data=data))
>
> Expressions involving the \left and \right operators return errors:
> eq = r'\begin{bmatrix}\frac{1}{2 a} \left(- b + \sqrt{- 4 a c +
> b^{2}}\right), & - \frac{1}{2 a} \left(b + \sqrt{- 4 a c +
> b^{2}}\right)\end{bmatrix}'
>
> ...
>
> ValueError:
> \begin{bmatrix}\frac{1}{2 a} \left(- b + \sqrt{- 4 a c + b^{2}}\right), & - 
> \frac{1}{2 a} \left(b + \sqrt{- 4 a c + b^{2}}\right)\end{bmatrix}
> ^
> Unknown symbol: \begin (at char 0), (line:1, col:1)
>
> There is another case where \left and \right cause errors without there being 
> a matrix in the expression.
>
>
I guess this means it is using matplotlib under the covers, and it doesn't
support matrices.

Aaron Meurer

>
> In any case, supposing I can generate the PNG.  Is there a way to save the
> image programmatically?  (I tab-completed on several of the imported
> package functions but nothing jumped out at me).
>
> Thanks,
>
> -- JBB
>
> On Monday, November 17, 2014 11:33:06 AM UTC-8, Aaron Meurer wrote:
>>
>> I believe the preview() function does what you want.
>> http://docs.sympy.org/latest/modules/printing.html#
>> sympy.printing.preview.preview.
>>
>> Aaron Meurer
>>
>> On Mon, Nov 17, 2014 at 9:21 AM, Jason Moore <moore...@gmail.com> wrote:
>>
>>> There should be some functions in the ipython machinery in sympy that
>>> creates pngs from the latex printer using matplotlib. See:
>>>
>>> https://github.com/sympy/sympy/blob/master/sympy/
>>> interactive/printing.py#L34
>>>
>>>
>>> Jason
>>> moorepants.info
>>> +01 530-601-9791
>>>
>>> On Mon, Nov 17, 2014 at 9:23 AM, Dario Beraldi <dario....@gmail.com>
>>> wrote:
>>>
>>>>
>>>>
>>>> On Monday, November 17, 2014 8:13:56 AM UTC, jeanbi...@gmail.com wrote:
>>>>>
>>>>> I'd love to be able to save a sympy LaTeX-ified result as an image
>>>>> file to export into other documents.  In my business I have to create
>>>>> Powerpoint and am trying python-pptx for this.  It allows incorporating
>>>>> images programmatically.
>>>>>
>>>>> I've searched the sympy documentation and other sources but
>>>>> surprisingly have not found anything for equations.  I believe that plots
>>>>> can be saved.  I'm sure I've missed something.
>>>>>
>>>>> Suggestions greatly appreciated.
>>>>>
>>>>> --- JBB
>>>>>
>>>>
>>>> Google'ing around I found latexmath2png
>>>> <http://code.google.com/p/latexmath2png/> (*A versatile program and
>>>> Python module to allow conversion of LaTeX math equations in to PNG 
>>>> images*)
>>>> which seems to do what you are after? (I don't anything about it, just
>>>> found it right now).
>>>>
>>>> Hope it helps!
>>>>
>>>>
>>>>  --
>>>> You received this message because you are subscribed to the Google
>>>> Groups "sympy" group.
>>>> To unsubscribe from this group and stop receiving emails from it, send
>>>> an email to sympy+un...@googlegroups.com.
>>>> To post to this group, send email to sy...@googlegroups.com.
>>>> Visit this group at http://groups.google.com/group/sympy.
>>>> To view this discussion on the web visit https://groups.google.com/d/
>>>> msgid/sympy/faa755d6-1795-41c4-a523-f90092732537%40googlegroups.com
>>>> <https://groups.google.com/d/msgid/sympy/faa755d6-1795-41c4-a523-f90092732537%40googlegroups.com?utm_medium=email&utm_source=footer>
>>>> .
>>>>
>>>> For more options, visit https://groups.google.com/d/optout.
>>>>
>>>
>>>  --
>>> You received this message because you are subscribed to the Google
>>> Groups "sympy" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to sympy+un...@googlegroups.com.
>>> To post to this group, send email to sy...@googlegroups.com.
>>> Visit this group at http://groups.google.com/group/sympy.
>>> To view this discussion on the web visit https://groups.google.com/d/
>>> msgid/sympy/CAP7f1AgRJceWP7-bCsJE1MJAQqa14Tm9upzEabCnGnjKf
>>> qDpcQ%40mail.gmail.com
>>> <https://groups.google.com/d/msgid/sympy/CAP7f1AgRJceWP7-bCsJE1MJAQqa14Tm9upzEabCnGnjKfqDpcQ%40mail.gmail.com?utm_medium=email&utm_source=footer>
>>> .
>>>
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>>  --
> You received this message because you are subscribed to the Google Groups
> "sympy" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to sympy+unsubscr...@googlegroups.com.
> To post to this group, send email to sympy@googlegroups.com.
> Visit this group at http://groups.google.com/group/sympy.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/sympy/49fdfb37-572d-4e41-89f8-59497568385f%40googlegroups.com
> <https://groups.google.com/d/msgid/sympy/49fdfb37-572d-4e41-89f8-59497568385f%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"sympy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sympy+unsubscr...@googlegroups.com.
To post to this group, send email to sympy@googlegroups.com.
Visit this group at http://groups.google.com/group/sympy.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sympy/CAKgW%3D6LQiR2OWziP9-cgiYigD6ZenRRCMOE5ZkpE6zgrG9A-Lw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to