Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LaTeX sqrt does not work #17

Closed
fonsp opened this issue Nov 7, 2024 · 1 comment
Closed

LaTeX sqrt does not work #17

fonsp opened this issue Nov 7, 2024 · 1 comment

Comments

@fonsp
Copy link
Contributor

fonsp commented Nov 7, 2024

Hi! Super cool package!

Small bug report: if I use \sqrt instead of sqrt in Julia, something does not work:

j%                                                                              ➜  ~ julia
               _
   _       _ _(_)_     |  Documentation: https://docs.julialang.org
  (_)     | (_) (_)    |
   _ _   _| |_  __ _   |  Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 1.11.1 (2024-10-16)
 _/ |\__'_|_|_|\__'_|  |  Official https://julialang.org/ release
|__/                   |

(@v1.11) pkg> activate --temp
  Activating new project at `/var/folders/v_/fhpj9jn151d4p9c2fdw2gv780000gn/T/jl_x3fpZB`
a
(jl_x3fpZB) pkg> add Handcalcs
    Updating registry at `~/.julia/registries/General.toml`
   Resolving package versions...
    Updating `/private/var/folders/v_/fhpj9jn151d4p9c2fdw2gv780000gn/T/jl_x3fpZB/Project.toml`
  [e8a07092] + Handcalcs v0.4.0
    Updating `/private/var/folders/v_/fhpj9jn151d4p9c2fdw2gv780000gn/T/jl_x3fpZB/Manifest.toml`
  [1520ce14] + AbstractTrees v0.4.5
  [da1fd8a2] + CodeTracking v1.3.6
  [1fa38f19] + Format v1.3.7
  [e8a07092] + Handcalcs v0.4.0
  [aa1ae85d] + JuliaInterpreter v0.9.36
  [b964fa9f] + LaTeXStrings v1.4.0
  [23fbe1c1] + Latexify v0.16.5
  [6f1432cf] + LoweredCodeUtils v3.0.5
  [1914dd2f] + MacroTools v0.5.13
  [bac558e1] + OrderedCollections v1.6.3
  [aea7be01] + PrecompileTools v1.2.1
  [21216c6a] + Preferences v1.4.3
  [ae029012] + Requires v1.3.0
  [295af30f] + Revise v3.6.2
  [6ba57fb7] + TestHandcalcFunctions v0.2.0
  [56f22d72] + Artifacts v1.11.0
  [2a0f44e3] + Base64 v1.11.0
  [ade2ca70] + Dates v1.11.0
  [8ba89e20] + Distributed v1.11.0
  [7b1f6079] + FileWatching v1.11.0
  [b77e0a4c] + InteractiveUtils v1.11.0
  [76f85450] + LibGit2 v1.11.0
  [8f399da3] + Libdl v1.11.0
  [d6f4376e] + Markdown v1.11.0
  [ca575930] + NetworkOptions v1.2.0
  [de0858da] + Printf v1.11.0
  [3fa0cd96] + REPL v1.11.0
  [9a3f8284] + Random v1.11.0
  [ea8e919c] + SHA v0.7.0
  [9e88b42a] + Serialization v1.11.0
  [6462fe0b] + Sockets v1.11.0
  [f489334b] + StyledStrings v1.11.0
  [fa267f1f] + TOML v1.0.3
  [cf7118a7] + UUIDs v1.11.0
  [4ec0a83e] + Unicode v1.11.0
  [e37daf67] + LibGit2_jll v1.7.2+0
  [29816b5a] + LibSSH2_jll v1.11.0+1
  [c8ffd9c3] + MbedTLS_jll v2.28.6+0

julia> using Handcalcs

julia> a = 1
1

julia> b = 2
2

julia> @handcalc x = √(a^2 + b^2)
[ Info: tracking Base
ERROR: AssertionError: latexify does not support objects of type DataType.
Stacktrace:
  [1] _latexraw(args::Type; kwargs::@Kwargs{convert_unicode::Bool, env::Symbol})
    @ Latexify ~/.julia/packages/Latexify/ieukI/src/latexraw.jl:109
  [2] process_latexify(args::Type; kwargs::@Kwargs{convert_unicode::Bool, env::Symbol})
    @ Latexify ~/.julia/packages/Latexify/ieukI/src/latexify_function.jl:49
  [3] process_latexify
    @ ~/.julia/packages/Latexify/ieukI/src/latexify_function.jl:40 [inlined]
  [4] latexraw
    @ ~/.julia/packages/Latexify/ieukI/src/latexraw.jl:58 [inlined]
  [5] (::Latexify.var"#64#66"{@Kwargs{convert_unicode::Bool, env::Symbol}})(i::Type)
    @ Latexify ~/.julia/packages/Latexify/ieukI/src/latexoperation.jl:21
  [6] iterate
    @ ./generator.jl:48 [inlined]
  [7] collect_to!(dest::Vector{…}, itr::Base.Generator{…}, offs::Int64, st::Int64)
    @ Base ./array.jl:838
  [8] collect_to_with_first!(dest::Vector{…}, v1::LaTeXStrings.LaTeXString, itr::Base.Generator{…}, st::Int64)
    @ Base ./array.jl:816
  [9] _collect(c::Vector{…}, itr::Base.Generator{…}, ::Base.EltypeUnknown, isz::Base.HasShape{…})
    @ Base ./array.jl:810
 [10] collect_similar
    @ ./array.jl:709 [inlined]
 [11] map
    @ ./abstractarray.jl:3371 [inlined]
 [12] latexoperation(ex::Expr, prevOp::Vector{Symbol}; kwargs::@Kwargs{convert_unicode::Bool, env::Symbol})
    @ Latexify ~/.julia/packages/Latexify/ieukI/src/latexoperation.jl:21
 [13] latexoperation
    @ ~/.julia/packages/Latexify/ieukI/src/latexoperation.jl:9 [inlined]
 [14] (::Latexify.var"#recurseexp!#44"{Bool, @Kwargs{env::Symbol}})(ex::Expr)
    @ Latexify ~/.julia/packages/Latexify/ieukI/src/latexraw.jl:98
 [15] _latexraw(inputex::Expr; convert_unicode::Bool, kwargs::@Kwargs{env::Symbol})
    @ Latexify ~/.julia/packages/Latexify/ieukI/src/latexraw.jl:102
 [16] process_latexify(args::Expr; kwargs::@Kwargs{env::Symbol})
    @ Latexify ~/.julia/packages/Latexify/ieukI/src/latexify_function.jl:49
 [17] process_latexify
    @ ~/.julia/packages/Latexify/ieukI/src/latexify_function.jl:40 [inlined]
 [18] _latexinline(x::Expr; kwargs::@Kwargs{})
    @ Latexify ~/.julia/packages/Latexify/ieukI/src/latexinline.jl:4
 [19] _latexinline(x::Expr)
    @ Latexify ~/.julia/packages/Latexify/ieukI/src/latexinline.jl:3
 [20] process_latexify(args::Expr; kwargs::@Kwargs{})
    @ Latexify ~/.julia/packages/Latexify/ieukI/src/latexify_function.jl:49
 [21] process_latexify
    @ ~/.julia/packages/Latexify/ieukI/src/latexify_function.jl:40 [inlined]
 [22] latexify(args::Expr; kwargs::@Kwargs{})
    @ Latexify ~/.julia/packages/Latexify/ieukI/src/latexify_function.jl:27
 [23] latexify(args::Expr)
    @ Latexify ~/.julia/packages/Latexify/ieukI/src/latexify_function.jl:25
 [24] top-level scope
    @ none:1
 [25] eval(m::Module, e::Any)
    @ Core ./boot.jl:430
 [26] top-level scope
    @ ~/.julia/packages/Handcalcs/AEy1d/src/handfunc_macro.jl:32
 [27] eval(m::Module, e::Any)
    @ Core ./boot.jl:430
 [28] macro expansion
    @ ~/.julia/packages/Handcalcs/AEy1d/src/handfunc_macro.jl:32 [inlined]
 [29] top-level scope
    @ ~/.julia/packages/Handcalcs/AEy1d/src/handcalc_marco.jl:33
Some type information was truncated. Use `show(err)` to see complete types.

julia> 

@co1emi11er2
Copy link
Owner

co1emi11er2 commented Nov 7, 2024

Hi @fonsp! Thanks for the bug. The reason behind this is the expression x = √(a^2 + b^2) fits the variable = function_name(args...; kwargs...) pattern (more detail about this here), so it is trying to unroll the function sqrt. This could be fixed by doing @handcalc x = √(a^2 + b^2) not_funcs = [√].

I added this symbol to the list that will automatically be passed over, so you shouldn't need to do that for this one with new update (v0.4.1). Here is the current list of symbols that get passed over.

const math_syms = [
    :*, :/, :^, :+, :-, :%,
    :.*, :./, :.^, :.+, :.-, :.%,
    :<, :>, Symbol(==), :<=, :>=,
    :.<, :.>, :.==, :.<=, :.>=,
    :sqrt, :sin, :cos, :tan, :sum, 
    :cumsum, :max, :min, :exp, :log,
    :log10,  :]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants