LaTeXcalc is a LaTeX-Calculation-library for python3 accepting an optional values-dict for variables
Project description
LaTeXcalc
What is this?
LaTeXcalc is a LaTeX-Calculation-library for python3.
This calculates a mathematical formula written as a LaTeX-string. It can use a given value-dict for variables in the formula. The return-value is int or float.
Supported features
LaTeXcalc can handle the following LaTeX-operations:
- apply
+
,-
,*
,/
operators and the-
as algebraic sign - multiplication and division first, then addition and subtraction
- power
^
- brackets
()
,[]
and{}
(also with\left(
..\right)
) - squareroot
\sqrt{}
- trigonometric functions like
\sin
or\arctan
- exponential numbers linke
1e+12
\log
ande^
\pi
orpi
ande
as default-valuesmath.pi
andmath.e
\frac{}{}
(works as abbreviated\frac 1 2
as well)
make sure you always use *
(or \cdot
), because xy
!= x*y
, in that case xy would be a value!
How to use
You can install this by using pip: pip install latexcalc
or alternatively by including the folder latexcalc
in your python3-project.
Then all you need to do is
import latexcalc
c = latexcalc.calc('\sqrt{3^2+4^2}')
# or with variables:
c = latexcalc.calc(\sqrt(a^2+b^2)', {'a':3,'b':4})
print(c) # 5
Limitations
All testet cases work, but there might still be wrong calculations in special cases, so test it for your needs!
Something missing?
Feel free to submit an issue if you find a bug or if you think something important is missing.
In that case please add a Line for the test.py
to show the desired operation!
Alternatives
There are some other libraries out there doing similar things, but at time of writing I didn't find anything that fulfilled my needs (lightweight, working with variables, ...). So depending on your requirements this or maybe something else might be the right choise, thank's for cheching this out!
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
Built Distribution
File details
Details for the file latexcalc-0.8.0.tar.gz
.
File metadata
- Download URL: latexcalc-0.8.0.tar.gz
- Upload date:
- Size: 16.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.7.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f688a4ee4c37e3338600fe5b553980973116a589718126ba42eb674c74d8d3ff |
|
MD5 | 58f216262a78d381c192a3b76b8b9940 |
|
BLAKE2b-256 | 7fe195001a5f9eba1f2de58851b8c5e79efa23b022a993971a54502adb292b61 |
File details
Details for the file latexcalc-0.8.0-py3-none-any.whl
.
File metadata
- Download URL: latexcalc-0.8.0-py3-none-any.whl
- Upload date:
- Size: 17.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.7.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 88c991cd9f084650fb7a283b27c3eb00405a6274281c78589fd2a7267ecee2bc |
|
MD5 | 57a5d6231cf3cc55e5eb0ad77db4683a |
|
BLAKE2b-256 | 6ddaebc89ee8f3a9fc55c207f394cd99fdc8d4dfc8f3efa37cb5afcc90d16d98 |