Convert a Python expression in a LaTeX formula
Project description
.. image:: https://img.shields.io/pypi/v/pytexit.svg
:target: https://pypi.python.org/pypi/pytexit
:alt: PyPI
.. image:: https://img.shields.io/travis/erwanp/pytexit.svg
:target: https://travis-ci.org/erwanp/pytexit
:alt: Tests
.. image:: https://codecov.io/gh/erwanp/pytexit/branch/master/graph/badge.svg
:target: https://codecov.io/gh/erwanp/pytexit
:alt: Coverage
=======
pytexit
=======
Description
-----------
Convert a Python expression in a LaTeX formula
Github::
https://github.com/erwanp/pytexit
This module isn't unit aware and isn't designed to perform calculations. It is
a mere translator from Python expressions into LaTeX syntax. The idea behind it
was I wanted my Python formula to be the same objects as the LaTeX formula I
write in my reports / papers. It allows me to gain time (I can write my LaTeX
formulas directly from the Python expression), and check my Python formulas are correct
(once printed LaTeX is much more readable that a multiline Python expression)
References
----------
Based on a code sample from Geoff Reedy on `StackOverflow <http://stackoverflow.com/questions/3867028/converting-a-python-numeric-expression-to-latex>`__
You may also be interested in the similar development from `BekeJ <https://github.com/BekeJ/py2tex>`__ that was built
on top of the same sample.
BekeJ's code is designed to be used exclusively in an iPython console using
%magic commands to perform unit aware calculations and return result in a nice
LaTeX format.
Sympy also has some nice LaTeX output, but it requires declaring your symbolic
variables and isn't as fast as a one-line console command in pytexit.
Install
-------
`pytexit` is on PyPi::
pip install pytexit
Use
---
In a Python console::
from pytexit import py2tex
py2tex('x = 2*sqrt(2*pi*k*T_e/m_e)*(DeltaE/(k*T_e))**2*a_0**2')
Will display the following equation:
.. image:: https://github.com/erwanp/pytexit/blob/master/docs/output.png
And the corresponding LaTeX formula::
$$x=2\\sqrt{\\frac{2\\pi k T_e}{m_e}} \\left(\\frac{\\Delta E}{k T_e}\\right)^2 a_0^2$$
You may also use it directly from a terminal::
py2tex 'x = 2*sqrt(2*pi*k*T_e/m_e)*(DeltaE/(k*T_e))**2*a_0**2'
Current Features
----------------
Successfully deal with most of the one or two parameter functions. Run the
_test() function to have an idea of what's possible.
Arbitrary syntax:
- Variables named after Greek names are turned into LaTeX syntax
- 'numpy.sin / math.sin / np.sin' syntax still work as expected (all standard
scientific module names are removed beforehand)
- quad() is converted into integrals
- list comprehensions are converted into LaTex syntaX.
- 'a_p' variables are converted with "p" as subscript
Also note that iPython uses auto-completion to convert most of the latex
identifiers in their Unicode equivalent::
\alpha --> [Tab] --> α
- pytexit will recognize those Unicode characters and convert them again in
latex expressions
- there is a mode to output Python expressions in Word syntax. From version 2007
Word converts most LaTeX expressions in its own graphical representation. The
Word mode here was just about replacing those LaTeX {} with Word ()::
py2tex('sqrt(5/3)',output='word')
Test
----
In order to enforce cross-version compatibility and non-regression, `pytexit` is
now tested with `pytest` and Travis. Run the test suite locally from a terminal with::
pip install pytest
pytest
Changes
-------
- 0.2.1 : full Python 2 support, added automated tests with pytest and Travis
- 0.1.11 : make it reliable: added pytest, Travis, code coverage
- 0.1.8 : fixed console script on Unix systems
- 0.1.4 : partial Python 2 support
Still WIP
---------
Todo:
- allow syntax "a*b = c" (not a valid Python expression, but convenient to type
some LaTeX formula)
- code for numbered equations
- export all the conversions on an external text file
Platform: any
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Science/Research
Classifier: License :: OSI Approved :: CEA CNRS Inria Logiciel Libre License, version 2.1 (CeCILL-2.1)
Classifier: Topic :: Scientific/Engineering
Classifier: Topic :: Text Processing
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 2.7
Classifier: Programming Language :: Python :: 3.4
Classifier: Programming Language :: Python :: 3.5
Classifier: Operating System :: OS Independent
:target: https://pypi.python.org/pypi/pytexit
:alt: PyPI
.. image:: https://img.shields.io/travis/erwanp/pytexit.svg
:target: https://travis-ci.org/erwanp/pytexit
:alt: Tests
.. image:: https://codecov.io/gh/erwanp/pytexit/branch/master/graph/badge.svg
:target: https://codecov.io/gh/erwanp/pytexit
:alt: Coverage
=======
pytexit
=======
Description
-----------
Convert a Python expression in a LaTeX formula
Github::
https://github.com/erwanp/pytexit
This module isn't unit aware and isn't designed to perform calculations. It is
a mere translator from Python expressions into LaTeX syntax. The idea behind it
was I wanted my Python formula to be the same objects as the LaTeX formula I
write in my reports / papers. It allows me to gain time (I can write my LaTeX
formulas directly from the Python expression), and check my Python formulas are correct
(once printed LaTeX is much more readable that a multiline Python expression)
References
----------
Based on a code sample from Geoff Reedy on `StackOverflow <http://stackoverflow.com/questions/3867028/converting-a-python-numeric-expression-to-latex>`__
You may also be interested in the similar development from `BekeJ <https://github.com/BekeJ/py2tex>`__ that was built
on top of the same sample.
BekeJ's code is designed to be used exclusively in an iPython console using
%magic commands to perform unit aware calculations and return result in a nice
LaTeX format.
Sympy also has some nice LaTeX output, but it requires declaring your symbolic
variables and isn't as fast as a one-line console command in pytexit.
Install
-------
`pytexit` is on PyPi::
pip install pytexit
Use
---
In a Python console::
from pytexit import py2tex
py2tex('x = 2*sqrt(2*pi*k*T_e/m_e)*(DeltaE/(k*T_e))**2*a_0**2')
Will display the following equation:
.. image:: https://github.com/erwanp/pytexit/blob/master/docs/output.png
And the corresponding LaTeX formula::
$$x=2\\sqrt{\\frac{2\\pi k T_e}{m_e}} \\left(\\frac{\\Delta E}{k T_e}\\right)^2 a_0^2$$
You may also use it directly from a terminal::
py2tex 'x = 2*sqrt(2*pi*k*T_e/m_e)*(DeltaE/(k*T_e))**2*a_0**2'
Current Features
----------------
Successfully deal with most of the one or two parameter functions. Run the
_test() function to have an idea of what's possible.
Arbitrary syntax:
- Variables named after Greek names are turned into LaTeX syntax
- 'numpy.sin / math.sin / np.sin' syntax still work as expected (all standard
scientific module names are removed beforehand)
- quad() is converted into integrals
- list comprehensions are converted into LaTex syntaX.
- 'a_p' variables are converted with "p" as subscript
Also note that iPython uses auto-completion to convert most of the latex
identifiers in their Unicode equivalent::
\alpha --> [Tab] --> α
- pytexit will recognize those Unicode characters and convert them again in
latex expressions
- there is a mode to output Python expressions in Word syntax. From version 2007
Word converts most LaTeX expressions in its own graphical representation. The
Word mode here was just about replacing those LaTeX {} with Word ()::
py2tex('sqrt(5/3)',output='word')
Test
----
In order to enforce cross-version compatibility and non-regression, `pytexit` is
now tested with `pytest` and Travis. Run the test suite locally from a terminal with::
pip install pytest
pytest
Changes
-------
- 0.2.1 : full Python 2 support, added automated tests with pytest and Travis
- 0.1.11 : make it reliable: added pytest, Travis, code coverage
- 0.1.8 : fixed console script on Unix systems
- 0.1.4 : partial Python 2 support
Still WIP
---------
Todo:
- allow syntax "a*b = c" (not a valid Python expression, but convenient to type
some LaTeX formula)
- code for numbered equations
- export all the conversions on an external text file
Platform: any
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Science/Research
Classifier: License :: OSI Approved :: CEA CNRS Inria Logiciel Libre License, version 2.1 (CeCILL-2.1)
Classifier: Topic :: Scientific/Engineering
Classifier: Topic :: Text Processing
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 2.7
Classifier: Programming Language :: Python :: 3.4
Classifier: Programming Language :: Python :: 3.5
Classifier: Operating System :: OS Independent
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
pytexit-0.2.4.tar.gz
(24.1 kB
view hashes)
Built Distribution
Close
Hashes for pytexit-0.2.4-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 976fb6c89ff695d594a0451190452dad74151fc868ed4a60f9b36af3e57e3970 |
|
MD5 | 3d1d01c37347eb3cf93e3970c0242eea |
|
BLAKE2b-256 | f67f42e705c5d7950fe8ad6f5466b17fb0201315b29c97081d898e8dc5aa8f4f |