You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
var =Variable("radius")
latexify(var) # outputs L"$radius$"latexify(var; font="rm") # outputs L"$\mathrm{radius}$"
But suppose I want the recipe to call a backend function. This is useful if the recipe is complicated, or I want several recipes to share a common backend function. In anticipation of more keyword arguments, I want the Latexify recipe to forward all keyword arguments kw..., so I don't have to spell them all out in several places:
using Latexify
struct Variable
name::Stringendfunctionbackend(var::Variable; font=nothing)
if!isnothing(font)
returnSymbol("\\math", font, "{", var.name, "}")
elsereturnSymbol(var.name)
endend@latexrecipefunctionf(var::Variable; kw...)
returnbackend(var; kw...)
end
This code fails with
ERROR: LoadError: BoundsError: attempt to access 1-element Vector{Any} at index [2]
Stacktrace:
[1] throw_boundserror(A::Vector{Any}, I::Tuple{Int64})
@ Base ./essentials.jl:14
[2] getindex
@ ./essentials.jl:916 [inlined]
[3] indexed_iterate(a::Vector{Any}, i::Int64, state::Int64)
@ Base ./tuple.jl:160
[4] create_kw_body(func_signature::Expr)
@ Latexify ~/.julia/packages/Latexify/ieukI/src/recipes.jl:36
[5] var"@latexrecipe"(__source__::LineNumberNode, __module__::Module, funcexpr::Any)
@ Latexify ~/.julia/packages/Latexify/ieukI/src/recipes.jl:162
in expression starting at /home/hermasl/.julia/dev/SymBoltz/bug.jl:15
The problem seems to be that forwarding kw... is not supported by @latexrecipe. It would be very nice it this worked!
The text was updated successfully, but these errors were encountered:
It might be possible to make this work, but it might be a bit more work than it's worth. For a workaround, the generated recipe function actually has a hidden keyword variable named kwargs, so
julia>@latexrecipefunctionf(var::Variable)
returnbackend(var; kwargs...)
end
julia>latexify(Variable("a"); font="rm")
L"$\mathrm{a}$"
A real solution to this issue would be to allow the author of a recipe to rename kwargs, or potentially to add more keyword lists.
Here is a working recipe for letting the user customize the font style of a rendered variable:
As expected:
But suppose I want the recipe to call a backend function. This is useful if the recipe is complicated, or I want several recipes to share a common backend function. In anticipation of more keyword arguments, I want the Latexify recipe to forward all keyword arguments
kw...
, so I don't have to spell them all out in several places:This code fails with
The problem seems to be that forwarding
kw...
is not supported by@latexrecipe
. It would be very nice it this worked!The text was updated successfully, but these errors were encountered: