mkhan45 / CalcuLaTeX

A pretty printing calculator language with support for units. Makes calculations easier and more presentable with real time LaTeX output, along with support for units, variables, and mathematical functions.
https://calcula.tech
Mozilla Public License 2.0
396 stars 16 forks source link

Use as a pandoc filter plugin #51

Open colindean opened 3 years ago

colindean commented 3 years ago

It would be really awesome to be able to use CalcuLaTeX as a pandoc filter plugin.

A document might look something like this:


Given a rock with mass $m_{rock}$ thrown by a force of $F_0$ acting over a duration $dt_{force}$,
calculate its airtime and the max height it achieves.

Given:

~~~ {calculatex #eq:facts}
g = 9.81 m/s^2
m_{rock} = 10 kg
F_0 = 1000 N
dt_{force} = 0.1 s
~~~

Solution:

~~~ {calculatex #eq:velocity}
y_{vel} = F_0 / m_{rock} * dt_{force} = ?
~~~
~~~ {calculatex #eq:airtime}
airtime = y_{vel} / g * 2 = ?
~~~
~~~ {calculatex #eq:heightmax}
height_{max} = y_{vel} * airtime / 4 = ? cm
~~~

and the output would essentially be this:


Given a rock with mass $m_{rock}$ thrown by a force of $F_0$ acting over a duration $dt_{force}$,
calculate its airtime and the max height it achieves.

Given:

$$
g = 9.81 m/s^2
m_{rock} = 10 kg
F_0 = 1000 N
dt_{force} = 0.1 s
$$ {#eq:facts}

Solution:

$$
y_{vel} = F_0 / m_{rock} * dt_{force} = 10 m/s
$$ {#eq:velocity}

$$
airtime = y_{vel} / g * 2 = 2.039 s
$$ {#eq:airtime}

$$
height_{max} = y_{vel} * airtime / 4 = 5.097 m
$$  {#eq:heightmax}

Passing additional code block classes through to the generated equation block enables compatibility with pandoc-crossref, too.

It'd be assumed that the calculatex block creates one environment per document. However, I'll bet you could add some kind of class with a key-value attribute that can assign calculatex code blocks to a certain environment or clear the state of the default.

mkhan45 commented 3 years ago

This is a really good idea and seems like a great way for CalcuLaTeX to be used in research. I definitely want to do this but it'll have to wait for the core functionality to be done.