#proc-macro #convert #latex #align #tex-expr #tex-equation #latex-code

macro bin math_dsl_macro

Proc-macro that converts LaTeX-code to rust-code

1 unstable release

0.1.0 Oct 16, 2021

#23 in #align

MIT/Apache

29KB
712 lines

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;

Dependencies

~7MB
~131K SLoC