phfaist / pylatexenc

Simple LaTeX parser providing latex-to-unicode and unicode-to-latex conversion
https://pylatexenc.readthedocs.io
MIT License
301 stars 37 forks source link

behavior when keep_inline_math=True #14

Closed furutaka closed 6 years ago

furutaka commented 6 years ago

[furutaka@Furutaka-3 ~]$ conda list|grep pylatexenc pylatexenc 1.2 [furutaka@Furutaka-3 ~]$ python Python 2.7.14 |Anaconda, Inc.| (default, Dec 7 2017, 17:05:42) [GCC 7.2.0] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> from pylatexenc.latex2text import LatexNodes2Text >>> latex=r"""$\gamma$""" >>> print LatexNodes2Text(keep_inline_math=True).latex_to_text(latex) $γ$

Is this the intended behavior of the function?

I expected $\gamma$...

Kazuyoshi

furutaka commented 6 years ago

Wow! (after reading the sources)

>>> print LatexNodes2Text(keep_inline_math=True).latex_to_text(latex) $γ$ >>> print LatexNodes2Text().latex_to_text(latex,keep_inline_math=True) \gamma >>> print LatexNodes2Text(keep_inline_math=True).latex_to_text(latex,keep_inline_math=True) $\gamma$

phfaist commented 5 years ago

Hi, and thanks for noting this issue earlier. This behavior is indeed not at all intuitive and these options were very poorly designed. I am currently working on a new version pylatexenc 2.0 where both keep_inline_math options for latexwalker and latex2text will be replaced by a single option math_mode= in latex2text. See updated doc here: https://pylatexenc.readthedocs.io/en/latest/latex2text/#pylatexenc.latex2text.LatexNodes2Text E.g.:

>>> latex2text.LatexNodes2Text(math_mode='text').latex_to_text(r'If $\alpha=1$ and $\beta=2$, then $\alpha+\beta=3$')
'If α=1 and β=2, then α+β=3'
>>> latex2text.LatexNodes2Text(math_mode='with-delimiters').latex_to_text(r'If $\alpha=1$ and $\beta=2$, then $\alpha+\beta=3$')
'If $α=1$ and $β=2$, then $α+β=3$'
>>> latex2text.LatexNodes2Text(math_mode='verbatim').latex_to_text(r'If $\alpha=1$ and $\beta=2$, then $\alpha+\beta=3$')
'If $\\alpha=1$ and $\\beta=2$, then $\\alpha+\\beta=3$'

I'd be happy to hear if you have any feedback.