Skip to content

Commit

Permalink
Merge pull request #1 from turner-eng/turner-eng-issue#5
Browse files Browse the repository at this point in the history
Update userguide.rst
  • Loading branch information
turner-eng authored Feb 14, 2021
2 parents b18e0f6 + 7b58b5a commit fb4c28a
Showing 1 changed file with 62 additions and 46 deletions.
108 changes: 62 additions & 46 deletions docs/userguide.rst
Original file line number Diff line number Diff line change
Expand Up @@ -32,49 +32,6 @@ and (in ipython console only) prints the equation:

.. image:: output.png


Notes
-----

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)


``pytexit`` can also convert FORTRAN formulas to Python (:func:`~pytexit.core.fortran.for2py`)
and LaTeX (:func:`~pytexit.pytexit.for2tex`)::

from pytexit import for2tex
for2tex(r'2.8d-11 * exp(-(26500 - 0.5 * 1.97 * 11600 )/Tgas)')

Finally, ``pytexit`` output can be made compatible with Word equation editor with
the ``output='word'`` option of :func:`~pytexit.pytexit.py2tex`::

from pytexit import py2tex
py2tex(r'2*sqrt(2*pi*k*T_e/m_e)*(DeltaE/(k*T_e))**2*a_0**2', output='word')
The latest output will typically replace all brackets {} with parenthesis () that are correctly
interpreted by Word, and keep keywords that are correctly evaluated by Word (`\pi` or `\cdot`)


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.

Current Features
----------------

Expand Down Expand Up @@ -113,13 +70,29 @@ Arbitrary syntax:
.. math::
\sum_{i=1}^{100} i^2=338350
- 'a_p' variables are converted with "p" as subscript::
- 'a_subˆsuper' variables are converted with "sub" as subscript and "super" as superscript, note that "ˆ" is the circumflex accent instead of the caret sign "^"::

py2tex('a_subˆsuper')

.. math::
a_{sub}^{super}
complex sub/superscript such as second order sub/superscript and comma are supported::
py2tex('k_i__1_i__2ˆj__1ˆj__2')
py2tex('k_i__1_i__2ˆj__1ˆj__2')
.. math::
k_{i_1,i_2}^{j_1,j_2}
more detailed rules::
python -> latex::
k_i_j -> k_i,j::
k_i__j -> k_(i_j)::
k_iˆj -> k_i^j::
k_iˆˆj -> k_(i^j)::
k_i__1_i__2ˆj__1ˆˆj__2 -> k_(i_1,i_2)^(j_1,j_2)::
Also note that iPython uses auto-completion to convert most of the latex
identifiers in their Unicode equivalent::

Expand All @@ -138,6 +111,49 @@ identifiers in their Unicode equivalent::
Word mode here was just about replacing those LaTeX {} with Word ()::

py2tex('sqrt(5/3)',output='word')
Notes
-----

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)


``pytexit`` can also convert FORTRAN formulas to Python (:func:`~pytexit.core.fortran.for2py`)
and LaTeX (:func:`~pytexit.pytexit.for2tex`)::

from pytexit import for2tex
for2tex(r'2.8d-11 * exp(-(26500 - 0.5 * 1.97 * 11600 )/Tgas)')

Finally, ``pytexit`` output can be made compatible with Word equation editor with
the ``output='word'`` option of :func:`~pytexit.pytexit.py2tex`::

from pytexit import py2tex
py2tex(r'2*sqrt(2*pi*k*T_e/m_e)*(DeltaE/(k*T_e))**2*a_0**2', output='word')
The latest output will typically replace all brackets {} with parenthesis () that are correctly
interpreted by Word, and keep keywords that are correctly evaluated by Word (`\pi` or `\cdot`)


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.



Test
Expand Down Expand Up @@ -173,4 +189,4 @@ Todo:
- code for numbered equations

- export all the conversions on an external text file


0 comments on commit fb4c28a

Please sign in to comment.