-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from co1emi11er2/default_kwargs
Update to work with Weave.jl
- Loading branch information
Showing
12 changed files
with
139 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
const default_h_kwargs = Dict{Symbol, Any}() | ||
|
||
""" | ||
set_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. | ||
Example: | ||
```julia | ||
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`. | ||
""" | ||
function set_handcalcs(; kwargs...) | ||
for key in keys(kwargs) | ||
default_h_kwargs[key] = kwargs[key] | ||
end | ||
end | ||
|
||
""" | ||
reset_handcalcs() | ||
Reset user-specified default kwargs for handcalcs, set by `set_handcalcs`. | ||
""" | ||
reset_handcalcs() = empty!(default_h_kwargs) | ||
|
||
""" | ||
get_handcalcs | ||
Get a Dict with the user-specified default kwargs for handcalcs, set by `set_handcalcs`. | ||
""" | ||
function get_handcalcs end | ||
get_handcalcs() = default_h_kwargs | ||
get_handcalcs(arg::Symbol) = default_h_kwargs[arg] | ||
get_handcalcs(args::AbstractArray) = map(x->default_h_kwargs[x], args) | ||
get_handcalcs(args...) = Tuple(get_handcalcs(arg) for arg in args) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# using Handcalcs | ||
# using LaTeXStrings, Unitful, UnitfulLatexify | ||
# using Test | ||
|
||
# use set_handcalcs | ||
# *************************************************** | ||
# *************************************************** | ||
expected =L"\begin{aligned} | ||
x &= 5 | ||
\\[5pt] | ||
y &= 4 | ||
\end{aligned}" | ||
set_handcalcs(spa=5) | ||
calc = @handcalcs begin | ||
x = 5 | ||
y = 4 | ||
end | ||
@test calc == expected | ||
@test Dict(:spa => 5) == get_handcalcs() | ||
reset_handcalcs() | ||
|
||
expected =LaTeXString("\\begin{align} | ||
x &= 5 | ||
\\\\[10pt] | ||
y &= 4 | ||
\\end{align}") | ||
set_handcalcs(h_env="align") | ||
calc = @handcalcs begin | ||
x = 5 | ||
y = 4 | ||
end | ||
@test calc == expected | ||
reset_handcalcs() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87b0634
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JuliaRegistrator register
Release notes:
This update adds the following:
Breaking changes
-- Now instead of the begin{align} environment, the begin{aligned} environment is used
-- You can still change back to the begin{align} environment if you prefer by:
set_handcalcs(h_env="align")
-- The reason it was changed was my preference for the equations to be left aligned in the document instead of centered
87b0634
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Registration pull request created: JuliaRegistries/General/104521
Tagging
After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.
This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via: