math_dsl_macro

Crates.iomath_dsl_macro
lib.rsmath_dsl_macro
version0.1.0
sourcesrc
created_at2021-10-16 00:55:06.033001
updated_at2021-10-16 00:55:06.033001
descriptionProc-macro that converts LaTeX-code to rust-code
homepage
repositoryhttps://gitlab.com/volkerweissmann/math_dsl_macro
max_upload_size
id465700
size35,714
(Volker-Weissmann)

documentation

README

For example

# #[macro_use]
# extern crate math_dsl_macro;
# fn main() {
# let psi = 1f64;
tex_expr!(r"\frac\pi 3 (1-\cos^2\psi)^2");
# }

Gets expanded zu something close to

# let psi = 1f64;
std::f64::consts::PI / 3f64  * ( 1f64 - psi.cos().powi(2) ).powi(2);

Similarly,

# #[macro_use]
# extern crate math_dsl_macro;
# fn main() {
# let psi = 1f64;
tex_equation!(r"x=\frac\pi 3 (1-\cos^2\psi)^2");
# }

gets expanded to

# let psi = 1f64;
let x = std::f64::consts::PI / 3f64  * ( 1f64 - psi.cos().powi(2) ).powi(2);

If, for example, myinput.tex contains

Other \LaTeX code
\begin{align*}
x=\frac\pi 3 (1-\cos^2\psi)^2
\end{align*}
Other \LaTeX code
\begin{align*}
a=b+c
\end{align*}
Other \LaTeX code

then

from_latex_file!("myinput.tex");

gets expanded to

# let psi = 1f64;
# let b = 1f64;
# let c = 1f64;
let x = std::f64::consts::PI / 3f64  * ( 1f64 - psi.cos().powi(2) ).powi(2);
let a = b + c;
Commit count: 21

cargo fmt