jupyter / notebook

Jupyter Interactive Notebook
https://jupyter-notebook.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
11.79k stars 5.01k forks source link

Broken Latex rendering of sympy symbols with primes and subscripts #1225

Open artdavis opened 8 years ago

artdavis commented 8 years ago

When using a sympy symbol with a prime and a subscript, Latex rendering of the equation sometimes breaks. For instance:

import sympy as sym
from IPython.display import display
from sympy.interactive import printing
printing.init_printing(pretty_print=True, use_latex=True)

avar = sym.symbols("a'_1")

eq1 = sym.cos(avar)
eq2 = eq1.replace(sym.cos(avar), 1 - avar**2)

display(eq1, eq2)

Workaround is to define avar = sym.symbols("{a'}_1") instead. But it was very difficult tracking this down as the source of the rendering problem.

System info

python -c "import IPython; print(IPython.sys_info())"

{'commit_hash': u'b573435',
 'commit_source': 'installation',
 'default_encoding': 'UTF-8',
 'ipython_path': '/usr/lib/python2.7/site-packages/IPython',
 'ipython_version': '4.1.2',
 'os_name': 'posix',
 'platform': 'Linux-4.4.5-1-ARCH-x86_64-with-glibc2.2.5',
 'sys_executable': '/usr/bin/python2',
 'sys_platform': 'linux2',
 'sys_version': '2.7.11 (default, Mar  3 2016, 11:00:04) \n[GCC 5.3.0]'}
willingc commented 8 years ago

@artdavis Thanks for the report and including a workaround that may help others.

This issue may be related to nbconvert issue 271

parleur commented 8 years ago

I test it and it fail in plain notebook.

I think it is related with sympy/printing/preview.py. Before the equation being passed to mathjax, sympy call the good old latex command for "preview" (useless but it does). And latex fail about double superscript, e.g. $a'^2$ is interpreted as $a^'^2$ which fail on latex.

It is related with issue 271 because nbconvert use latex for rendering too.

The confusing point is mathjax allowing things like $a^'^2$ despite latex does not.

willingc commented 8 years ago

@parleur Thanks for testing and confirming the relationship to issue 271. You're doing good work on other PRs in the project too. :smile: