NRPy+'s LaTeX Interface to SymPy (CAS) for General Relativity
- automatic expansion of
- Einstein summation convention
- Levi-Civita and Christoffel symbols
- Lie and covariant derivatives
- metric inverse and determinant
- automatic index raising and lowering
- arbitrary coordinate system (default)
- exception handling and debugging
§ Installation
To install NRPyLaTeX using PyPI, run the following command in the terminal
$ pip install nrpylatex
§ Exporting (CAS)
If you are using Mathematica instead of SymPy, run the following code to convert your output
from sympy import mathematica_code
namespace = parse_latex(...)
for var in namespace:
exec(f'{var} = mathematica_code({var})')
If you are using a different CAS, reference the SymPy documentation to find the relevant printing function.
§ Interactive Tutorial (MyBinder)
Quick Start | NRPy+ Integration | Guided Example (BSSN Formalism)
§ Documentation and Usage
Getting Started and API Reference
Simple Example (Kretschmann Scalar)
Python REPL or Script (*.py)
>>> from nrpylatex import parse_latex
>>> parse_latex(r"""
... % ignore "\begin{align}" "\end{align}"
... \begin{align}
... % coord [t, r, \theta, \phi]
... % define gDD --dim 4 --zeros
... % define G M --const
... %% define Schwarzschild metric diagonal
... g_{t t} &= -\left(1 - \frac{2GM}{r}\right) \\
... g_{r r} &= \left(1 - \frac{2GM}{r}\right)^{-1} \\
... g_{\theta \theta} &= r^2 \\
... g_{\phi \phi} &= r^2 \sin^2{\theta} \\
... %% generate metric inverse gUU, determinant det(gDD), and connection GammaUDD
... % assign gDD --metric
... R^\alpha{}_{\beta \mu \nu} &= \partial_\mu \Gamma^\alpha_{\beta \nu} - \partial_\nu \Gamma^\alpha_{\beta \mu}
... + \Gamma^\alpha_{\mu \gamma} \Gamma^\gamma_{\beta \nu} - \Gamma^\alpha_{\nu \sigma} \Gamma^\sigma_{\beta \mu} \\
... K &= R^{\alpha \beta \mu \nu} R_{\alpha \beta \mu \nu}
... \end{align}
... """)
('G', 'GammaUDD', 'gDD', 'gUU', 'epsilonUUUU', 'RUDDD', 'K', 'RUUUU', 'M', 'r', 'theta', 'RDDDD', 'gdet')
>>> from sympy import simplify
>>> print(simplify(K))
48*G**2*M**2/r**6
IPython REPL or Jupyter Notebook
In [1]: %load_ext nrpylatex
In [2]: %%parse_latex
...: % ignore "\begin{align}" "\end{align}"
...: \begin{align}
...: % coord [t, r, \theta, \phi]
...: % define gDD --dim 4 --zeros
...: % define G M --const
...: %% define Schwarzschild metric diagonal
...: g_{t t} &= -\left(1 - \frac{2GM}{r}\right) \\
...: g_{r r} &= \left(1 - \frac{2GM}{r}\right)^{-1} \\
...: g_{\theta \theta} &= r^2 \\
...: g_{\phi \phi} &= r^2 \sin^2{\theta} \\
...: %% generate metric inverse gUU, determinant det(gDD), and connection GammaUDD
...: % assign gDD --metric
...: R^\alpha{}_{\beta \mu \nu} &= \partial_\mu \Gamma^\alpha_{\beta \nu} - \partial_\nu \Gamma^\alpha_{\beta \mu}
...: + \Gamma^\alpha_{\mu \gamma} \Gamma^\gamma_{\beta \nu} - \Gamma^\alpha_{\nu \sigma} \Gamma^\sigma_{\beta \mu} \\
...: K &= R^{\alpha \beta \mu \nu} R_{\alpha \beta \mu \nu}
...: \end{align}
Out[2]: ('G', 'GammaUDD', 'gDD', 'gUU', 'epsilonUUUU', 'RUDDD', 'K', 'RUUUU', 'M', 'r', 'theta', 'RDDDD', 'gdet')
In [3]: from sympy import simplify
In [4]: print(simplify(K))
Out[4]: 48*G**2*M**2/r**6
Metadata
Release files for nrpylatex 1.4.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| nrpylatex-1.4.0.tar.gz | 32.8 kB | Without provenance | Details |
Built distributions (wheels)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| nrpylatex-1.4.0-py3-none-any.whl | Python 3 | none | any | Details |
| nrpylatex-1.4.0-py2.py3-none-any.whl | Python 2, Python 3 | none | any | Details |
Total release size: 105.5 kB
Release files / nrpylatex-1.4.0.tar.gz
| Download URL | nrpylatex-1.4.0.tar.gz |
|---|---|
| Size | 32.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
56685c58b62f90875bf7a75d0115f2b7b9154c2554f1e0968dee5786ac334b8c
|
|
BLAKE2b-256 checksum How to use checksums |
d57bf374701590597a4b0a983599ba4db53dbfdc923b7ac48bc6f8492981ac04
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.7.1 CPython/3.12.8 Darwin/24.2.0
|
Release files / nrpylatex-1.4.0-py3-none-any.whl
| Download URL | nrpylatex-1.4.0-py3-none-any.whl |
|---|---|
| Size | 36.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
786f1c8529df21ef0e6f2e3323fc8d1ef92e40151e70b5186a6052284756962d
|
|
BLAKE2b-256 checksum How to use checksums |
46727a5d62aa8a4bd964814ef65707319ab5dbc97fabb7b216f4bb9440f842e8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.7.1 CPython/3.12.8 Darwin/24.2.0
|
Release files / nrpylatex-1.4.0-py2.py3-none-any.whl
| Download URL | nrpylatex-1.4.0-py2.py3-none-any.whl |
|---|---|
| Size | 36.4 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
a78943e579039c0371e90e3123afe2d35a4604c2c42fcdc857760f9e104b4a22
|
|
BLAKE2b-256 checksum How to use checksums |
9abcec27c8481714a73853d12fdde15b6a7321cec7a144e2df5e395f288ea491
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.7.1 CPython/3.12.8 Darwin/24.2.0
|
Security for nrpylatex 1.4.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.