From 7b58b5adaf269211b71d52fcb65801046de0c5c1 Mon Sep 17 00:00:00 2001 From: turner-eng <62496935+turner-eng@users.noreply.github.com> Date: Sun, 14 Feb 2021 17:35:17 +0800 Subject: [PATCH 1/2] Update userguide.rst --- docs/userguide.rst | 108 ++++++++++++++++++++++++++------------------- 1 file changed, 62 insertions(+), 46 deletions(-) diff --git a/docs/userguide.rst b/docs/userguide.rst index ea8dbd1..5762032 100644 --- a/docs/userguide.rst +++ b/docs/userguide.rst @@ -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 `__ - - -You may also be interested in the similar development from `BekeJ `__ 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 ---------------- @@ -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:: @@ -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 `__ + + +You may also be interested in the similar development from `BekeJ `__ 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 @@ -173,4 +189,4 @@ Todo: - code for numbered equations - export all the conversions on an external text file - \ No newline at end of file + From 0ca10c8502f8c869b14cb20dd2c0521ecabec700 Mon Sep 17 00:00:00 2001 From: turner-eng <62496935+turner-eng@users.noreply.github.com> Date: Sun, 14 Feb 2021 17:40:37 +0800 Subject: [PATCH 2/2] Update userguide.rst --- docs/userguide.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/userguide.rst b/docs/userguide.rst index 5762032..67f205d 100644 --- a/docs/userguide.rst +++ b/docs/userguide.rst @@ -1,5 +1,5 @@ -Convert a Python expression to a LaTeX formula +Convert a Python expression to a LaTeX formula Install -------