Giter Site home page Giter Site logo

pytexit's Introduction

Convert a Python expression to a LaTeX formula

PyPI Tests Coverage

Documentation

https://pytexit.readthedocs.io

Documentation Status

Install

pytexit is on PyPi:

pip install pytexit

Use

pytexit features the py2tex, for2tex for2py functions.

In a Terminal, use py2tex:

py2tex 'x = 2*sqrt(2*pi*k*T_e/m_e)*(DeltaE/(k*T_e))**2*a_0**2'

In a Python console, use py2tex:

from pytexit import py2tex
py2tex('x = 2*sqrt(2*pi*k*T_e/m_e)*(DeltaE/(k*T_e))**2*a_0**2')

returns the corresponding LaTeX formula (to re-use in papers):

$$x=2\\sqrt{\\frac{2\\pi k T_e}{m_e}} \\left(\\frac{\\Delta E}{k T_e}\\right)^2 a_0^2$$

and (in ipython console only) prints the equation:

https://github.com/erwanp/pytexit/blob/master/docs/output.png

References

Initial work from Geoff Reedy on StackOverflow: https://stackoverflow.com/a/3874621/5622825 . Kudos.

Similar projects:

pytexit's People

Contributors

alexhagen avatar alxy avatar anukaal avatar emetor avatar erwanp avatar mawenzy avatar ofirsiboni avatar phidi04 avatar turner-eng avatar wesdh avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pytexit's Issues

auto-deploy on pypi

Autodeploy on Pypi with Travis-CI after a successfull test on the Master branch. (and new version number, else the Pypi won't register)

See radis/radis#41

Negative Sign Before Parentheses

Hi!

First, this package is super great! Thank you!

I found something weird, if I do py2tex("a - (b - (c - d))"), I get '$$a-b-c-d$$'. Then both equations are not the same anymore. Maybe doing the whole distributive approach could be hard here, but maybe keeping the parantheses would be easier :)

Thank you!

Best,

Dave

pip installation issue

Somehow if I use

pip install pytexit

I get successful installation

user:user$ pip install pytexit
DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won't be maintained after that date. A future version of pip will drop support for Python 2.7.
Collecting pytexit
  Downloading https://files.pythonhosted.org/packages/62/4d/61536e30e8ebd537ad4f3dfb71e2ac595f4a9644d7dd85b5699b7025e9c9/pytexit-0.3.3-py2.py3-none-any.whl
Requirement already satisfied: six in /usr/local/lib/python2.7/site-packages (from pytexit) (1.12.0)
**Installing collected packages: pytexit**
Successfully installed pytexit-0.3.3

but I cannot use it since it cannot find it

In [2]: from pytexit import py2tex
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-2-20e6f2ec1c33> in <module>()
----> 1 from pytexit import py2tex

ImportError: No module named pytexit

I also cloned the git repository and I can run the code from there. I wonder if there is something wrong with installation.

extra parenthesis

Hello,
I don't know if that issue is connected to the new version of Python3.8 but when I try
py2tex('2+3'), I have an output with extra parenthesis.

`$ python
Python 3.8.2 (default, Apr 27 2020, 15:53:34)
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.

from pytexit import py2tex
py2tex('2+3')
$$\left(2\right)+\left(3\right)$$
'$$\left(2\right)+\left(3\right)$$'`

Prime not supported in variable name

I want to get N_{Rd}^{\prime} shown below, from variable name N_Rdˆprime, this is a feature similar to auto-recognition of greek letters, can we have this?
image

Unicode character documentation

Noticed while working on previous issue that perhaps a table listing supported Unicode characters would be useful to add to the Read the Docs. Maybe with a few additional examples? Example:

Supported Unicode Characters

Character Name As chr()
α alpha chr(945)
β beta chr(946)
And so on...

Please let me know if this is OK and I will create the table documentation. It looks as if docs/userguide.rst would need to be edited.

simplify_fractions doesn't work

print(py2tex('theta = w_k * a ** 4 / t ** 4 / E',simplify_fractions=True)) prints out:

$$\theta=\frac{\frac{w_k a^4}{t^4}}{E}$$

instead of:

$$\theta=\frac{w_k a^4}{t^4E}$$

How to convert division symbol (u+00f7) or chr(247) to latex using py2tex?

In one of the maths equations, I am having division symbol (u+00f7) or chr(247) as below -

txt1 = '3/4' + ' ' + chr(247) + ' ' + '8/15'

When I use py2tex to convert it into latex, I am getting below error -

SyntaxError: invalid character '÷' (U+00F7)

Can anyone please suggest / help how to convert this character / such maths characters to LaTex using py2tex?

Display with dark themes

Hello!
Thank you for the package!

In Dark Themes IPython the display output is hardly readable because the text colour is black.

image

Does anyone know :

  • how to fix it?
  • how to automatically adapt to the user theme?

Treatment of pow(x,2) => x^2 (etc.)

First, thanks for all the work which has gone into developing this tool. It is a great idea and I am hoping to use it quite a bit.

I have run the test under spyder and there seem to been a few changes which are not reflected in the "Expected results."
These ARE trivial e.g. extra braces "{}" in the tex; a "\left( \right )" replacing a "( )"- obviously not real problems.

One feature request, please.
Please can we get "pow(x,2)" to map to "$$x^2$$".
The expression "power(x,2)" transforms into "$$x^2$$". I assume that is line 665 of core.py.
I don't understand the python function power( ).
To my shame, I have never done any serious object oriented programming, so I got lost in the coding of core.py
This would be great.

Sorry, I cannot offer a proper fix, Chris Thompson

How to process mixed fraction using py2tex for correct printing

I want to print a mixed fraction (say one and half 1 1/2 or two and three fifth 2 3/5) as a mixed fraction (and not as an improper fraction) in the latex output. But I am not able to figure out how to pass it to py2tex as input so that it is processed as a mixed fraction. Any pointers or help on this request is highly appreciated. Thanks

atan parentheses issue

atan function generate normal (...) whereas other functions, e.g. tan, produces \left(...\right).

To reproduce:

>>> from pytexit import py2tex
>>> py2tex('y=atan(x)')
$$y=\arctan(x)$$
>>> py2tex('y=tan(x)')
$$y=tan\left(x\right)$$

Not sure if this is intended but I personally prefer to keep the consistency, i.e. to always use \left(\right).

pow(x,y) doesn't work in py2tex()

py2tex("pow(a,b)") currently produces:
$$\operatorname{pow}\left(a, b\right)$$
instead of:
a^b

Do you want pow(a,b) to result completely like a**b?

If yes, we should do the following shown in the picture

  1. change the name "power" with "pow" in core.py->visit_Call() and
  2. in the same function, remove the "self.parenthesis()" around args[0]

image

reference
image

pyinstaller issue

An error is encountered after built with pyinstaller with pytexit imported.

The error is caused by the fact that pyinstaller does not include __version__.txt

I solved this by manually modifying __version__ == '0.3.3' in the __init__.py, i.e. not reading version data from __version__.txt

Might just put version info in a .py (i.e. __init__.py) file in lieu of a text file?

printing parameters

Hi I was playing with this package and was trying to set the printing parameters globally like this:

py2tex.print_formula = False

But it had no effect within my Jupyter Notebook (specifically Google Colab).
It only worked when done for each function call like this:

py2tex('x = 2*sqrt(2*pi*T_e/m_e)*(DeltaE/(T_e))**2*a_0**2 * k',print_latex=False, print_formula=True)

Is it possible to do it once at the start of a notebook and not have to add "print_latex=False, print_formula=True" on each function call?

problem with combination of exponents

pytexit.py2tex("(a**b)**c")
<IPython.core.display.Latex object>
$$a^b^c$$
u'$$a^b^c$$'

The answer should be something like
u'$${\left(a^b\right)}^c$$'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.