Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
co1emi11er2 committed May 7, 2024
2 parents ce417c7 + dfd3544 commit 46e2232
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 9 deletions.
Binary file modified .DS_Store
Binary file not shown.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,16 @@

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](https://github.com/connorferster/handcalcs) 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](https://painterqubits.github.io/Unitful.jl/stable/), and get recursion working for function calls. This package is an extension of [Latexify.jl](https://github.com/korsbo/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.
This package supplies macros to generate ``\LaTeX`` formatted strings from mathmatical formulas. This package takes inspiration from [handcalcs.py](https://github.com/connorferster/handcalcs) 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. At this point, I believe most (if not all) of the features from the python package are here. Future plans are to integrate the package with [Unitful.jl](https://painterqubits.github.io/Unitful.jl/stable/). This package is an extension of [Latexify.jl](https://github.com/korsbo/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](https://co1emi11er2.github.io/Handcalcs.jl/stable/) for more info.**

## Basic Demo

![handcalc demo](/assets/handcalcs_demo.gif)

*Note: In the gif, `@handfunc` is used for unrolling a function with algebraic expressions. It is now recommended to use the `@handcalcs` macro for this. See the [docs](https://co1emi11er2.github.io/Handcalcs.jl/stable/).*

## Basic example:

### Single line expression
Expand Down
12 changes: 8 additions & 4 deletions docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ CurrentModule = Handcalcs

## Introduction

This is the documentation for [Handcalcs.jl](https://github.com/co1emi11er2/Handcalcs.jl). This package supplies macros to generate ``\LaTeX`` formatted strings from mathmatical formulas. This package takes inspiration from [handcalcs.py](https://github.com/connorferster/handcalcs) 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](https://painterqubits.github.io/Unitful.jl/stable/), be able to render the algebraic expressions within a function, and many other things. This package is an extension of [Latexify.jl](https://github.com/korsbo/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.
This is the documentation for [Handcalcs.jl](https://github.com/co1emi11er2/Handcalcs.jl). This package supplies macros to generate ``\LaTeX`` formatted strings from mathmatical formulas. This package takes inspiration from [handcalcs.py](https://github.com/connorferster/handcalcs) 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. At this point, I believe most (if not all) of the features from the python package are here. Future plans are to integrate the package with [Unitful.jl](https://painterqubits.github.io/Unitful.jl/stable/). This package is an extension of [Latexify.jl](https://github.com/korsbo/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 examples below.**

Expand Down Expand Up @@ -178,10 +178,14 @@ You can see that it looks as though only the unit is being squared. This should

## Future Plans

There are a number of things that I would like to implement to the package. See [handcalcs.py](https://github.com/connorferster/handcalcs) for potential features. Here is a list of features I hope to add:
There are a number of things that I would like to implement to the package. Here is a list of features I hope to add:

- Maybe add a way to change color of expressions.
- Maybe a symbolic mode that would essentially be like @latexdefine but you get function unrolling and multiline support.
- A way to disable @handcalcs macro if you are wanting to run script for multiple iterations and not worried about rendering all iterations. That way you get speed for those situations.
- I have also thought about adding a setting that you could change if you were within the REPL and instead of latex (since it is not very readable) to instead output a simple string instead. For example: `I_x = b*h^3/12 = 5*15^3/12 = 1406.25`.


- Get recursion working for @handfunc macro
- A way to break down a ``\LaTeX`` equation that is too long to multiple lines

## References

Expand Down
13 changes: 9 additions & 4 deletions src/handfunc_macro.jl
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ end

function _initialize_kw_and_pos_args(found_func, func_args)
found_func_args = found_func.args[1]
found_func_args
found_kw_dict, found_pos_arr = parse_func_args(found_func_args, _extract_kw_args, _extract_arg)
kw_dict, pos_arr = parse_func_args(func_args, _extract_kw_args, _extract_arg)
kw_dict, pos_arr = _clean_args(kw_dict, pos_arr)
Expand Down Expand Up @@ -86,15 +87,17 @@ function parse_func_args(func_args, kw_func, pos_func)
end

function _extract_kw_args(arg::Expr)
iskw = true
dict = Dict()
if arg.head == :parameters # check if function keyword arguments
iskw = true
dict = Dict()
for kw in arg.args
dict = _extract_kw(kw, dict)
end
return iskw, dict
else
error("Not a keyword argument.")
iskw = false
dict = nothing
return iskw, dict
end
end

Expand Down Expand Up @@ -122,8 +125,10 @@ function _extract_arg(arg::Expr)
elseif arg.head == :(.)
append!(arr, [Any[arg nothing]])
return arr
elseif arg.head == :(::)
append!(arr, [Any[arg.args[1] nothing]])
else
error("Not a default argument.")
append!(arr, [Any[arg nothing]])
end
end

Expand Down
2 changes: 2 additions & 0 deletions test/handfunc_macro.jl
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ expected_Iy_3 = (L"$\begin{aligned}
Iy &= \frac{h \cdot b^{expo}}{denominator} = \frac{15 \cdot 5^{2}}{10} = 37.5
\end{aligned}$")
calc_Iy_3 = @handfunc x = TestHandcalcFunctions.calc_Iy(15,5;expo=2, denominator=10) # check kw arguments with ";"
calc_Iy_4 = @handfunc x = TestHandcalcFunctions.calc_Iy(10+5,5;expo=2, denominator=5+5) # check expressions
@test calc_Iy_3 == expected_Iy_3
@test calc_Iy_4 == expected_Iy_3
# ***************************************************


Expand Down

0 comments on commit 46e2232

Please sign in to comment.