Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Printing matrices in the qtconsole fails when LaTeX is not installed #10264

Closed
ghost opened this issue Dec 15, 2015 · 9 comments
Closed

Printing matrices in the qtconsole fails when LaTeX is not installed #10264

ghost opened this issue Dec 15, 2015 · 9 comments

Comments

@ghost
Copy link

ghost commented Dec 15, 2015

I have one computer with Anaconda 2.4.1, on which I can print symbolic matrices in latex on the Ipython console embedded in Spyder2 without raising any error. On this computer was installed another version of python 2.7.10 for other softwares.
Recently I got a new computer on which I installed the same anaconda distribution, and I can't print matrices anymore because of this error :

Python 2.7.11 |Anaconda 2.4.1 (64-bit)| (default, Dec  7 2015, 14:10:42) [MSC v.1500 64 bit (AMD64)]
Type "copyright", "credits" or "license" for more information.

IPython 4.0.1 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.
%guiref   -> A brief reference about the graphical user interface.

from sympy import Matrix

from sympy import init_printing

init_printing()

Matrix([0,0])
Out[4]: 
Traceback (most recent call last):

  File "C:\Users\Anaconda2\lib\site-packages\IPython\core\formatters.py", line 337, in __call__
    return printer(obj)

  File "C:\Users\Anaconda2\lib\site-packages\sympy\interactive\printing.py", line 127, in _print_latex_png
    return _matplotlib_wrapper(s)

  File "C:\Users\Anaconda2\lib\site-packages\sympy\interactive\printing.py", line 90, in _matplotlib_wrapper
    return latex_to_png(o)

  File "C:\Users\Anaconda2\lib\site-packages\IPython\lib\latextools.py", line 87, in latex_to_png
    bin_data = f(s, wrap)

  File "C:\Users\Anaconda2\lib\site-packages\IPython\lib\latextools.py", line 106, in latex_to_png_mpl
    mt.to_png(f, s, fontsize=12)

  File "C:\Users\Anaconda2\lib\site-packages\matplotlib\mathtext.py", line 3207, in to_png
    rgba, depth = self.to_rgba(texstr, color=color, dpi=dpi, fontsize=fontsize)

  File "C:\Users\Anaconda2\lib\site-packages\matplotlib\mathtext.py", line 3172, in to_rgba
    x, depth = self.to_mask(texstr, dpi=dpi, fontsize=fontsize)

  File "C:\Users\Anaconda2\lib\site-packages\matplotlib\mathtext.py", line 3145, in to_mask
    ftimage, depth = self.parse(texstr, dpi=dpi, prop=prop)

  File "C:\Users\Anaconda2\lib\site-packages\matplotlib\mathtext.py", line 3118, in parse
    box = self._parser.parse(s, font_output, fontsize, dpi)

  File "C:\Users\Anaconda2\lib\site-packages\matplotlib\mathtext.py", line 2374, in parse
    six.text_type(err)]))

ValueError: 
\left[\begin{smallmatrix}0\\0\end{smallmatrix}\right]
      ^
Expected "\right" (at char 6), (line:1, col:7)

Failed to render latex: 
\left[\begin{matrix}0\\0\end{matrix}\right]
      ^
Expected "\right" (at char 6), (line:1, col:7) 

On this topic (#9959) it is said that there is a work around to avoid matplotlib's mathtext issues, but as the printing works perfectly with others printers on my old computer I would like to know if you have any idea of what is missing in the new computer, meanings in the anaconda 2.4.0 package itself.

@moorepants
Copy link
Member

Do you know if Spyder is using the IPython qtconsole?

@moorepants
Copy link
Member

I just reproduced this with SymPy 0.7.6.1, Spyder 2.3.8, Python 3.5.1, IPython 4.0.1. Spyder uses an IPython qtconsole by default. If LaTeX is not installed and you try to print a Matrix, then it will default to the matplotlib backend, which can't print matrices, thus the error you see.

The only current solution for correct printing is to install LaTeX with dvipng and the qtconsole printing will work.

This is an outstanding issue that we haven't come up with a good solution for yet because IPython doesn't let you detect what the frontend of the kernel is.

@moorepants
Copy link
Member

The commit message in this pull request explains the issue: #9976

@moorepants
Copy link
Member

Also see this: #10005

@moorepants moorepants changed the title Printing matrices in latex Printing matrices in the qtconsole fails when LaTeX is not installed Dec 15, 2015
@moorepants
Copy link
Member

The other workaround is to use init_printing(use_latex='matplotlib'), but you will only get unicode printing of the matrices.

@ghost
Copy link
Author

ghost commented Dec 15, 2015

First, thank you very much for your fast answers !

So if I understood you well, I need to install dvipng https://www.ctan.org/tex-archive/dviware/dvipng (which is effectively installed on the computer without the error as I have miktex) to get back the alternative to mathtext printer ? In any case, I'm trying this and let you know asap.

@moorepants
Copy link
Member

Yes, the best solution is to install a LaTeX distribution that includes dvipng. The second solution is to use init_printing(use_lates='matplotlib') so that the pretty printing fall-back will work without errors.

@ghost
Copy link
Author

ghost commented Dec 15, 2015

Well it works perfectly ! I did it on two different computers, and the problem is solved. Thank you very much Mr.Moore.
If I may, I will redirect this user (http://stackoverflow.com/questions/33792174/spyder-failed-to-render-latex-when-rendering-a-sympy-matrix) to this page because I am apparently not the only guy who couldn't find easily this solution.

@asmeurer
Copy link
Member

asmeurer commented Feb 4, 2016

This is a bug in the upstream qtconsole that has been fixed jupyter/qtconsole#63. The workarounds that @moorepants describes above should work in the meantime.

@asmeurer asmeurer closed this as completed Feb 4, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants