in progress pretty printing calculator language

Overview

CalcuLaTeX

Test Status Crates.io

Try it out at https://mkhan45.github.io/CalcuLaTeX-Web/

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 =
'''
x = 5
y = 10 kg
x * y = ?
z = x kg + y = ?

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

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

Comments
  • Tests failing

    Tests failing

    main.rs/tests::test_basic fails at this assertion

            assert_eq!(
                full_eval("5 kilograms + 4 grams").to_string(),
                "5004 g".to_string()
            );
    

    With the following message:

    thread 'tests::test_basic' panicked at 'assertion failed: `(left == right)`
      left: `"9000 g"`,
     right: `"5004 g"`', src/main.rs:57:9
    note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
    
    opened by mjhouse 3
  • More sign shenanigans

    More sign shenanigans

    X = -10
    X*(1) = ?
    X/(1) = ?
    (X+1)/(1) = ?
    (X-1)/(1) = ?
    -X = ?
    

    gives

    X*(1) = -10   // yes
    X/(1) = 10    // no...
    (X+1)/(1) = -9  // yes!
    (X-1)/(1) = 11  // no...
    -X = ?    // Invalid statement -X = ?
    

    I like CalcuLatex, but CalcuLatex doesn't like negative variables... :-)

    opened by fabianlischka 2
  • Implement negation as a prefix operator instead of as a parsing rule

    Implement negation as a prefix operator instead of as a parsing rule

    Right now the number and integer parsing rules allow for a '-' at the start so parse::<f64> just parses it in but this makes it weird to work with negating variables etc.

    opened by mkhan45 2
  • Weird sign error

    Weird sign error

    Hi, I've been hit by this weird bug. Smallest example I managed to make is this below.

    Input:

    k = -8
    p = 8
    
    lo = 0 + k*p  = ?
    hi = 0 - k*p  = ?
    
    k = -8
    p = 10
    
    lo = 0 + k*p  = ?
    hi = 0 - k*p  = ?
    

    Output:

    k=−8 p=8

    lo=0+k×p=64 % note: wrong, should be -64 hi=0−k×p=−64 % note: wrong, should be +64

    k=−8 p=10

    lo=0+k×p=−80 % note: correct hi=0−k×p=80 % note: correct

    opened by fabianlischka 2
  • What is the rendener of math?

    What is the rendener of math?

    Thanks for this interesting work. I'm curious about how you render the math. Do you use some external library like pandoc? Or it's implement in the code?

    opened by linwaytin 2
  • Adds tests for Unit struct

    Adds tests for Unit struct

    Overview

    Added a bunch of simple tests for Unit structs. A lot of them are pretty trivial, but I thought the obvious stuff should be covered. If these changes are accepted, you'll have to make sure they pass when you change Unit in the future.

    Blocking issues

    There was some unexpected behavior when dividing- you get empty output (unit.to_string() = "") for dividing meters^4 by meters^2, which should give "m^2" as the output unless I'm missing something. You get the same output when dividing two identical Unit instances, but that seems acceptable for identical numerator and denominator.

    I left example tests (w/ commented assertions) for both of those cases. If you clarify what's intended and/or fix the behavior, I'll add tests for those cases as well.

    opened by mjhouse 2
  • Fix copy/paste prefix error

    Fix copy/paste prefix error

    UNIT_PREFIXES previously used a power of 21 for the "yotta" prefix; this PR changes it to the correct value of 24. No test failures were introduced, which makes me think that a test for this should be added, but I don't have the time to do it right now.

    The issue can be revealed by typing 1 yottawatt / (1 exawatt) into the CalcuLaTeX demo website, which yields 1000 instead of the expected 1000000. Incidentally, I tried to test this with 1 yottawatt / (1 zettawatt) but was met with an error message, which probably also warrants investigation.

    opened by Aehmlo 1
  • Roots of small numbers

    Roots of small numbers

    Hi Mikhail, thanks for fixing that weird sign bug! Now I calculated some more and stumbled across another issue:

    4^0.5 = ?
    0.25^0.5 = ?
    

    Output is:

    4^0.500=2 % correct

    0.250^{0.500} = 1.581 % incorrect, should be sqrt(1/4) = 1/2 = 0.5

    opened by fabianlischka 1
  • Variable aliases

    Variable aliases

    CalcuLaTeX supports declaring a variable using latex syntax, e.g. m_0 and \frac{x}{y} are valid variable names and will be rendered properly, but they're annoying to type. It should be possible to alias a variable to LaTeX.

    This is probably related to #2 since I'd imagine we use a separate statement to set a variable's display LaTeX

    enhancement 
    opened by mkhan45 1
  • Compiling/usage informaion in README

    Compiling/usage informaion in README

    Would it be possible to add to the README (or elsewhere) information about how to compile and run this program for those who aren't familiar, and what libraries / tools are required to do so? Thank you!

    documentation 
    opened by nobodywasishere 1
  • Unit typesetting

    Unit typesetting

    According to standards, units must be typeset in upright font. Consider typesetting units using \mathrm{} or even better, siunitx package if possible.

    See for example SI Brochure:

    Unit symbols are written using roman (upright) type, regardless of the type used in the surrounding text

    opened by ilyapopov 1
  • CalcuLaTeX 2.0

    CalcuLaTeX 2.0

    CalcuLaTeX has potential, but it's held back by messy code and a badly designed arbitrary precision unit math system.

    Arbitrary precision unit math is a pain. There are a number of libraries for it in Rust, but many of them are either made for type safe compile-time usecases, or are text based calculators.

    An obvious solution is to use one of these text based calculators with a custom parser and then compile the result to LaTeX. However, an easier and less efficient solution is to use the language as an IR.

    For example, with fend, we could compile CalcuLaTeX input to fend input, run fend, and then re-parse fend output and display it with LaTeX. It would probably be easier to intercept a FendResult on the output end and compile it to LaTeX. However, on the input side I believe it would be a lot easier to generate a fend input string than to actually create a Fend IR.

    Using this method, a lot of CalcuLaTeX's general design might stay the same. Right now, input expressions (left side of the = ?), are basically directly translated to LaTeX, and that won't change.

    opened by mkhan45 1
  • LaTeX output should try to be human readable

    LaTeX output should try to be human readable

    Right now it's very messy. One thing which might be nice is adding comments which are just the corresponding CalcuLaTeX line that produces the LaTeX line

    opened by mkhan45 0
  • Truth table generator

    Truth table generator

    This is super long term since CalcuLaTeX doesn't even support booleans yet, but I wanted to write out a general plan.

    Basically, user defined functions need to have an option to inline themselves in the LaTeX. We also need LaTeX string interpolation to work. This way, truth tables can be implemented as just syntax sugar and just expand to a table.

    enhancement 
    opened by mkhan45 0
🦀 Rust library for printing human readable, relative time differences

?? Rust library for printing human readable, relative time differences

Herbert Lu 31 Aug 6, 2022
🧮 Super duper simple calculator

calce ?? Visit Website To Use Calculator Example ?? Visit Website To Use Calculator 2 + 2 sin( 90 ) + cos ( 120 ) sqrt(144) + 12 ceil ( 12.12 ) + 22

Bejolithic 0 Dec 23, 2021
Easily sync your clipboard between devices. This is a work in progress app.

Clipboard Sync Description Easily sync your clipboard between devices. This is a work in progress app. Stack Frontend: React Tauri isomorphic-ws TSX,

Steveplays 2 Mar 2, 2022
Language Integrated Query in Rust.

Linq in Rust Language Integrated Query in Rust (created by declarative macros). Inspired by LINQ in .NET. What's LINQ This project is under developmen

StardustDL 91 Dec 8, 2022
Fegeya Gretea (aka green tea), new generation programming language.

Fegeya Gretea Gretea (aka green tea), new generation programming language. A taste of Gretea's syntax: import tea.green.fmt module hello { fn hel

Ferhat Geçdoğan 13 Sep 28, 2022
An experimental programming language for exploring first class iterators.

An experimental programming language for exploring first class iterators.

Miccah 4 Nov 23, 2021
A formal, politely verbose programming language for building next-gen reliable applications

vfpl Pronounced "Veepl", the f is silent A politely verbose programming language for building next-gen reliable applications Syntax please initialize

VFPL 4 Jun 27, 2022
Cookiecutter templates for Serverless applications using AWS SAM and the Rust programming language.

Cookiecutter SAM template for Lambda functions in Rust This is a Cookiecutter template to create a serverless application based on the Serverless Appl

AWS Samples 24 Nov 11, 2022
Rust language bindings for Bitcoin secp256k1 library.

Full documentation rust-secp256k1 rust-secp256k1 is a wrapper around libsecp256k1, a C library by Pieter Wuille for producing ECDSA signatures using t

Rust Bitcoin Community 250 Dec 18, 2022
The compiler of the okta programming language.

oktac The compiler of the okta programming language. For more information please visit the official website, and to quickly get okta running refer to

mikel 0 Dec 23, 2021
Aws-sdk-rust - AWS SDK for the Rust Programming Language

The AWS SDK for Rust This repo contains the new AWS SDK for Rust (the SDK) and its public roadmap. Please Note: The SDK is currently released as a dev

Amazon Web Services - Labs 2k Jan 3, 2023
lipsum-cli is a small terminal application written in Rust language.

lipsum-cli is a small terminal application written in Rust language. It's used for generating pseudo-Latin lorem ipsum filler text in terminal.

Civan Yavuzşen 5 Nov 28, 2022
jBread is a simple interpreted language

jBREAD jBread is a simple interpreted language, I'm creating to learn more about interpreters and how to design them. I probably won't fully complete

Samrid Pandit 7 Jan 12, 2023
A W.I.P desktop application for a new typesetting language, typst.

[WIP] typstudio A W.I.P desktop application for a new markup-based typesetting language, typst. Typstudio is built using Tauri. Features Syntax highli

Cubxity 40 Apr 25, 2023
Programming language just for fun, will kill LUA some day.

Loom Programming language just for fun, will kill LUA some day. Currently development of this language is algorithm driven. I'm trying to implement va

Mateusz Russak 5 Dec 4, 2023
High-performance, Reliable ChatGLM SDK natural language processing in Rust-Lang

RustGLM for ChatGLM Rust SDK - 中文文档 High-performance, high-quality Experience and Reliable ChatGLM SDK natural language processing in Rust-Language 1.

Blueokanna 3 Feb 29, 2024
A simple workshop to learn how to write, test and deploy AWS Lambda functions using the Rust programming language

Rust Lambda Workshop Material to host a workshop on how to build and deploy Rust Lambda functions with AWS SAM and Cargo Lambda. Intro What is Serverl

Luciano Mammino 13 Mar 28, 2024
Concrete is a simple programming language specifically crafted for creating highly scalable systems that are reliable, efficient, and easy to maintain.

The Concrete Programming Language Most ideas come from previous ideas - Alan C. Kay, The Early History Of Smalltalk In the realm of low-level programm

Lambdaclass 126 Nov 22, 2024
Debug2 is a pretty printing crate based on std::fmt

debug2 is a pretty printing crate based on std::fmt Why not just use Debug The Debug trait is good, but the problem is it is not very good at n

Nixon Enraght-Moony 18 Jun 23, 2022
Simple, automatic, and customizable tree pretty-printing in Rust.

display_tree Simple, automatic, and customizable tree pretty-printing in Rust. This crate provides tools to easily pretty-print data as a tree, includ

Cameron Delong 20 Dec 24, 2022