Giter Site home page Giter Site logo

justcodebase / handcalcs.jl Goto Github PK

View Code? Open in Web Editor NEW

This project forked from co1emi11er2/handcalcs.jl

0.0 0.0 0.0 2.14 MB

Julia package for converting Julia calculations into rendered latex.

Home Page: https://co1emi11er2.github.io/Handcalcs.jl/stable/

License: MIT License

Julia 100.00%

handcalcs.jl's Introduction

Handcalcs

Stable Dev Build Status Build Status Coverage Coverage Status

Introduction

This is a package for generating LaTeX maths and designed to improve documentation for your calculations. This package was designed to work in both jupyter and pluto.

This package supplies macros to generate \LaTeX formatted strings from mathmatical formulas. This package takes inspiration from handcalcs.py which is a python package that works best in jupyter notebooks. The goal is to get the functionalities of that package and bring them to Julia. The current version of Handcalcs.jl is working for typical algebraic formulas. Future plans are to integrate the package with Unitful.jl, and get recursion working for function calls. This package is an extension of Latexify.jl. The @latexdefine macro is similar to the main @handcalcs macro, but instead of only a symbolic rendering it also renders the numeric substitution.

Note: This package now renders properly in Quarto/Weave!! You can change the default settings to your liking. See docs for more info.

Basic Demo

handcalc demo

Basic example:

Single line expression

using Handcalcs
a = 3
b = 4
@handcalcs c = sqrt(a^2 + b^2)

or

@handcalcs begin c = sqrt(a^2 + b^2) end

You may want to do the latter in Pluto. This will supress the assignment callout in the top left of the output cell.

This generates a LaTeXString (from LaTeXStrings.jl) which, when printed looks like:

$c = \sqrt{a^{2} + b^{2}} = \sqrt{3^{2} + 4^{2}} = 5.0$

And when this LaTeXString is displayed in an environment which supports the tex/latex MIME type (Jupyter and Pluto notebooks, Jupyterlab and Hydrogen for Atom) it will automatically render as:

Also note c is evaluated as well.

Multi line expression

You can add comments to the side of the expression by adding a string beside the expression. Note: the variables being assigned in the expressions are evaluated (see docs for more details). See example below.

a = 2
b = 5
@handcalcs begin 
    c = a + b; "eq 1";
    d = a - c
end
$\begin{aligned}
c &= a + b = 2 + 5 = 7\;\text{  }(\text{eq 1})
\\[10pt]
d &= a - c = 2 - 7 = -5
\end{aligned}$

Function expression

This macro will generate LaTeX for a function that was called. The generated LaTeX would be the algebraic equations within the function.

b = 5
h = 15
@handcalcs Iy = calc_Ix(b, h) # calc_Ix is some function defined in another package
$\begin{aligned}
Ix &= \frac{b \cdot h^{3}}{12} = \frac{5 \cdot 15^{3}}{12} = 1406.25
\end{aligned}$

Note that Iy is evaluated (notIx). Also note that return statements are filtered out of the function body, so keep relevant parts separate from return statements.

Installation

This package is registered in the Julia registry, so to install it you can just run:

Pkg.add("Handcalcs")

Further information

For further information see the docs

handcalcs.jl's People

Contributors

co1emi11er2 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.