References
Disclaimer
Note that there are 3 macros exported. It is recommended to use @handcalcs
mainly. The singular @handcalc
macro is used by the @handcalcs
macro. You may find @handcalc
useful on certain occasions where you don't define a variable. For example:
using Handcalcs
a = 2
b = 3
@handcalc a + b
\[a + b = 2 + 3 = 5\]
Besides this use case, @handcalcs
macro can be used. The @handfunc
macro should not be used anymore.
References
Handcalcs.get_handcalcs
Handcalcs.left_align_in_pluto
Handcalcs.left_align_in_pluto
Handcalcs.reset_handcalcs
Handcalcs.set_handcalcs
Handcalcs.@handcalc
Handcalcs.@handcalcs
Handcalcs.@handfunc
Handcalcs.get_handcalcs
— Functionget_handcalcs()
Get a Dict with the user-specified default kwargs for handcalcs, set by set_handcalcs
.
Kwargs
cols
: sets the number of columns in the outputspa
: sets the line spacinglen
: can set to:long
and it will split equation to multiple linesh_env
: Choose between "aligned" (default), "align" and other LaTeX optionsprecision
: formats numbers to a max precision. Givenprecision = 2
,2.567
will show as2.57
, while2.5
would show as2.5
not_funcs
: Name the functions you do not want to "unroll"parse_pipe
: a boolean value (default=true) to remove pipe from equation. This is intended for unitful equations.parse_ifs
: a boolean value (default=true) to unroll if statements. Function unrolling works and it only shows the parts of the if statement that were met.disable
: disable handcalcs rendering to run simulations and turn it back on when needed.
Handcalcs.left_align_in_pluto
— Methodleft_align_in_pluto()
Returns html that changes mathjax settings in pluto. This results in equations that are left aligned instead of centered.
Handcalcs.reset_handcalcs
— Methodreset_handcalcs()
Reset user-specified default kwargs for handcalcs, set by set_handcalcs
.
Handcalcs.set_handcalcs
— Methodset_default(; kwargs...)
Set default kwarg values for handcalcs.
This works for all keyword arguments. It is additive such that if you call it multiple times, defaults will be added or replaced, but not reset.
Kwargs
cols
: sets the number of columns in the outputspa
: sets the line spacinglen
: can set to:long
and it will split equation to multiple linescolor
: change the color of the output (:blue
,:red
, etc)precision
: formats numbers to a max precision. Givenprecision = 2
,2.567
will show as2.57
, while2.5
would show as2.5
h_env
: choose between "aligned" (default), "align" and other LaTeX optionsnot_funcs
: name the functions you do not want to "unroll"parse_pipe
: a boolean value (default=true) to remove pipe from equation. This is intended for unitful equations.parse_ifs
: a boolean value (default=true) to unroll if statements. Function unrolling works and it only shows the parts of the if statement that were met.disable
: disable handcalcs rendering to run simulations and turn it back on when needed.
Example:
set_handcalcs(cols = 2, spa = 5)
To reset the defaults that you have set, use reset_handcalcs
. To see your specified defaults, use get_handcalcs
.
Handcalcs.@handcalc
— Macro@handcalc expression
Create LaTeXString
representing expression
. The expression being a vaiable followed by an equals sign and an algebraic equation. Any side effects of the expression, like assignments, are evaluated as well. The RHS can be formatted or otherwise transformed by supplying a function as kwarg post
.
Examples
julia> a = 2
2
julia> b = 5
5
julia> @handcalc c = a + b
L"$c = a + b = 2 + 5 = 7$"
julia> c
7
Handcalcs.@handcalcs
— Macro@handcalcs(expressions, kwargs)
Create LaTeXString
representing expressions
. The expressions representing a number of expressions. A single expression being a vaiable followed by an equals sign and an algebraic equation. Any side effects of the expression, like assignments, are evaluated as well. The RHS can be formatted or otherwise transformed by supplying a function as kwarg post
. Can also add comments to the end of equations. See example below.
Kwargs
- cols: sets the number of columns in the output
- spa: sets the line spacing
- len: can set to
:long
and it will split equation to multiple lines - color: change the color of the output (
:blue
,:red
, etc) - h_env: choose between "aligned" (default), "align" and other LaTeX options
- not_funcs: name the functions you do not want to "unroll"
Examples
julia> a = 2
2
julia> b = 5
5
julia> e = 7
7
julia> @handcalcs begin
c = a + b; "eq 1";
d = a - c
e
end
L"$\begin{aligned}
c &= a + b = 2 + 5 = 7\;\text{ }(\text{eq 1})
\\[10pt]
d &= a - c = 2 - 7 = -5
\\[10pt]
e &= 7
\end{aligned}$"
julia> c
7
julia> d
-5
Handcalcs.@handfunc
— Macro@handfunc expression
Create LaTeXString
representing expressions
. These expressions represent a number of expressions that exist within the function that was called. A single expression being a variable followed by an equals sign and the function being called. The expression is evaluated as well (not the expressions within the function). The RHS can be formatted or otherwise transformed by supplying a function as kwarg post
.
Examples
julia> @handfunc Iy = calc_Ix(5, 15)
L"$\begin{aligned}
Ix &= \frac{b \cdot h^{3}}{12} = \frac{5 \cdot 15^{3}}{12} = 1406.25
\end{aligned}$"
julia> Iy
1406.25
Note how Iy is evaluated but Ix is not.