• Stars
    star
    385
  • Rank 111,464 (Top 3 %)
  • Language
    Rust
  • License
    Mozilla Public Li...
  • Created almost 4 years ago
  • Updated about 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

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.

CalcuLaTeX

Test Status Crates.io

Try it out at https://calcula.tech/app

Example

'''
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


''' Solution: '''
y_{vel} = F_0 / m_{rock} * dt_{force} = ?

airtime = y_{vel} / g * 2 = ?
height_{max} = y_{vel} * airtime / 4 = ? cm

Outputs:

example 1

''' 
CalcuLaTeX:

Write an expression followed by = ? to evaluate it:
'''

50 g + 1 kg = ?

'''
You can suggest a unit if it outputs the wrong one. \\
Make sure it's correct otherwise the document won't \\
compile!
'''

5 m/s^2 * 3 kg = ?
5 m/s^2 * 3 kg = ? N

'''
Assign variables with =

They support some LaTeX formatting
'''
a_b = 5
c = 10 kg
a_b * c = ?
z = a_b kg + c = ?

'''
You can also add aliases for hard to type variables
'''
alias dx \frac{dx}{dt}
alias dt \Delta{t}

dx = 10 m/s
dt = 14 days
x = dx * dt = ?

'''
Set the output digits or use scientific notation \\
by using !digits \{n\} or !scientific 
'''

1 / 3 = ?

!digits 10
1 / 3 = ?

!digits 1
!scientific
1 kg = ? mg

'''
Basic mathematical functions are supported.

Additionally, builtin constants include $\pi$ and $e$.
'''

sin(\pi) = ?
cos(\pi) = ?
e = ?

'''
Escape raw latex with three single quotes.

There's still plenty of bugs, so feel free to \\
open an issue at \\
https://github.com/mkhan45/CalcuLaTeX
'''

Outputs:

tutorial


CLI Usage

Assuming the binary is called calculatex, running calculatex [input] [output.pdf] will watch the input file and output to output.pdf on change. This is meant for use with a PDF viewer which updates in realtime.

To run the CalcuLaTeX cli, you'll also need pandoc and a texlive installation.


Compiling

To build CalcuLaTeX, you need a nightly Rust compiler and Cargo, preferably through rustup. After that, it's as simple as:

git clone [email protected]:mkhan45/CalcuLaTeX.git
cd CalcuLaTeX

# both of these output to target/release/
cargo build --release # builds the library only
cargo build --features build-binary --release # builds the CLI

Contributing

If you'd like to contribute, feel free to open an issue or send me an email. The code base is very messy right now but it's small enough to be pretty understandable. Performance suggestions are welcome, but only if they don't introduce any extra complexity. I haven't benchmarked anything but LaTeX compilation is pretty much guaranteed to take an order of magnitude longer than the interpreter.

For guidelines, read CONTRIBUTING.md

More Repositories

1

tinyvm

An MVP stack based bytecode VM
Rust
86
star
2

SIMple-Gravity

Gravity simulator using Newton's Law of Universal Gravitation, made to help teach physics
Rust
41
star
3

RustScript2

RustScript is a functional scripting language with as much relation to Rust as Javascript has to Java.
OCaml
36
star
4

SIMple-Mechanics

An educational physics sim for high school physics, part of the SIMple Physics project
Rust
30
star
5

RustScript

RustScript is a functional scripting language with as much relation to Rust as Javascript has to Java.
Java
28
star
6

slang-v2

Simple scripting language interpreter
Rust
23
star
7

SIMple-Electronics

digital logic sim
Rust
16
star
8

CalcuLaTeX-Web

Basic web frontend for CalcuLaTeX
JavaScript
11
star
9

ssshmup

super small shoot 'em up
Rust
10
star
10

flappy-bird-android

Flappy bird clone with some extra stuff for school
Java
9
star
11

SIMple-Physics

Metarepo for SIMple Physics, a set of educational physics simulators
CSS
8
star
12

javascripth

stupid json eval lang
JavaScript
7
star
13

gravity-sim-rs

Gravity simulator using Newton's Law of Universal Gravitation
Rust
5
star
14

learning_synthesis

PBE Synthesis with VSAs
Rust
4
star
15

statistically-correct-python

An approximate Python interpreter
Python
3
star
16

ggez-pong-tutorial

Pong tutorial with ggez and Rust
Rust
3
star
17

expr_eval

arithmetic expression evaluator in a few languages
C++
2
star
18

rustscript_site

Personal resume/portfolio site written in RustScript
HTML
2
star
19

pumice

A vulkano-made light and brittle game engine that rocks
Rust
2
star
20

rocket_sim

An interactive rocket simulator inspired by Kerbal Space Program
Rust
2
star
21

elixir_parser

a arithmetic parser and evaluator in elixir
Elixir
2
star
22

tetrs

Tetris in Rust with ggez
Rust
2
star
23

clothsim

Rust
1
star
24

zeus

converts between commented python and ipynb
Python
1
star
25

crypto

cryptography stuff for school
Python
1
star
26

twitch-discord-clippy

Take twitch clip from a channel and put them in discord
Go
1
star
27

canvas

Draw on an image and blur it with FFT
Java
1
star
28

flappy-godot

flappy bird with godot engine
GAP
1
star
29

programming_paradigm_presentation

JavaScript
1
star
30

tetrisbot

tetris bot for jstris.jezevec10.com
Jupyter Notebook
1
star
31

godot-platformer

super simple demo platformer in godot engine to prepare for HackTJ 2020
GAP
1
star