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

Latest release breaks Latexify of expressions with unicode exponents/subscripts #1314

Closed
isaacsas opened this issue Oct 20, 2024 · 11 comments
Closed

Comments

@isaacsas
Copy link
Contributor

isaacsas commented Oct 20, 2024

@ChrisRackauckas the latest release (6.15.1) breaks Latexify with unicode subscripts/superscripts. (I noticed this as suddenly Catalyst doc builds are failing):

using Symbolics, Latexify
@variables t Gᴾ(t)
latexraw( 0 ~ Gᴾ)

now gives

julia> latexraw( 0 ~ Gᴾ)
ERROR: MethodError: no method matching convert_subscript
The function `convert_subscript` exists, but no method is defined for this combination of argument types.

Closest candidates are:
  convert_subscript(::String; snakecase, function_name, kwargs...)
   @ Latexify ~/.julia/packages/Latexify/ieukI/src/latexoperation.jl:266
  convert_subscript(::Symbol, Any...) got unsupported keyword arguments "function_name", "convert_unicode", "index", "cdot", "safescripts", "fmt", "snakecase", "env"
   @ Latexify ~/.julia/packages/Latexify/ieukI/src/latexoperation.jl:281

Stacktrace:
  [1] latexoperation(ex::Expr, prevOp::Vector{…}; kwargs::@Kwargs{…})
    @ Latexify ~/.julia/packages/Latexify/ieukI/src/latexoperation.jl:170
  [2] latexoperation
    @ ~/.julia/packages/Latexify/ieukI/src/latexoperation.jl:9 [inlined]
  [3] (::Latexify.var"#recurseexp!#44"{Bool, @Kwargs{…}})(ex::Expr)
    @ Latexify ~/.julia/packages/Latexify/ieukI/src/latexraw.jl:98
  [4] _latexraw(inputex::Expr; convert_unicode::Bool, kwargs::@Kwargs{…})
    @ Latexify ~/.julia/packages/Latexify/ieukI/src/latexraw.jl:102
  [5] process_latexify(args::Num; kwargs::@Kwargs{convert_unicode::Bool, index::Symbol, env::Symbol})
    @ Latexify ~/.julia/packages/Latexify/ieukI/src/latexify_function.jl:49
  [6] process_latexify
    @ ~/.julia/packages/Latexify/ieukI/src/latexify_function.jl:40 [inlined]
  [7] latexraw
    @ ~/.julia/packages/Latexify/ieukI/src/latexraw.jl:58 [inlined]
  [8] (::Latexify.var"#64#66"{@Kwargs{convert_unicode::Bool, index::Symbol, env::Symbol}})(i::Num)
    @ Latexify ~/.julia/packages/Latexify/ieukI/src/latexoperation.jl:21
  [9] iterate
    @ ./generator.jl:48 [inlined]
 [10] collect_to!(dest::Vector{String}, itr::Base.Generator{Vector{…}, Latexify.var"#64#66"{…}}, offs::Int64, st::Int64)
    @ Base ./array.jl:838
 [11] collect_to_with_first!(dest::Vector{…}, v1::String, itr::Base.Generator{…}, st::Int64)
    @ Base ./array.jl:816
 [12] _collect(c::Vector{…}, itr::Base.Generator{…}, ::Base.EltypeUnknown, isz::Base.HasShape{…})
    @ Base ./array.jl:810
 [13] collect_similar
    @ ./array.jl:709 [inlined]
 [14] map
    @ ./abstractarray.jl:3371 [inlined]
 [15] latexoperation(ex::Expr, prevOp::Vector{Symbol}; kwargs::@Kwargs{convert_unicode::Bool, index::Symbol, env::Symbol})
    @ Latexify ~/.julia/packages/Latexify/ieukI/src/latexoperation.jl:21
 [16] latexoperation
    @ ~/.julia/packages/Latexify/ieukI/src/latexoperation.jl:9 [inlined]
 [17] (::Latexify.var"#recurseexp!#44"{Bool, @Kwargs{index::Symbol, env::Symbol}})(ex::Expr)
    @ Latexify ~/.julia/packages/Latexify/ieukI/src/latexraw.jl:98
 [18] _latexraw(inputex::Expr; convert_unicode::Bool, kwargs::@Kwargs{index::Symbol, env::Symbol})
    @ Latexify ~/.julia/packages/Latexify/ieukI/src/latexraw.jl:102
 [19] process_latexify(args::Equation; kwargs::@Kwargs{env::Symbol})
    @ Latexify ~/.julia/packages/Latexify/ieukI/src/latexify_function.jl:49
 [20] process_latexify
    @ ~/.julia/packages/Latexify/ieukI/src/latexify_function.jl:40 [inlined]
 [21] latexraw(args::Equation)
    @ Latexify ~/.julia/packages/Latexify/ieukI/src/latexraw.jl:58
 [22] top-level scope
    @ REPL[3]:1
Some type information was truncated. Use `show(err)` to see complete types.
@isaacsas
Copy link
Contributor Author

No issues on 6.15.0.

@ChrisRackauckas
Copy link
Member

  convert_subscript(::Symbol, Any...) got unsupported keyword arguments "function_name", "convert_unicode", "index", "cdot", "safescripts", "fmt", "snakecase", "env"
   @ Latexify ~/.julia/packages/Latexify/ieukI/src/latexoperation.jl:281

that looks like a bug in latexify: it should be splatting the kwargs not the args?

@isaacsas
Copy link
Contributor Author

isaacsas commented Oct 20, 2024

I haven't investigated. I just found that it is broken with 6.15.1 when it previously worked (and I checked it works on 6.15).

@isaacsas
Copy link
Contributor Author

(I agree that does look like a Latexify bug.)

@hersle
Copy link
Contributor

hersle commented Oct 20, 2024

Does it have anything to do with #1305 where this now returns a LaTeXString instead of a Symbol?

@isaacsas
Copy link
Contributor Author

That is the only change from 6.15 so I assume it does.

@ChrisRackauckas
Copy link
Member

string(::LaTeXString)::LaTeXString 😅 😅 😅 😅 😅 😅 😅 😅 😅 😅 😅 😅 😅

@ChrisRackauckas
Copy link
Member

Maybe it's better to capture this here.

Interesting.

string("\\texttt", "{", sym, "}"))
convert(String, LaTeXString(string("\\texttt", "{", sym, "}"))

fails with:

ERROR: in Latexify.jl:
You are trying to create latex-maths from a `String` that cannot be parsed as
an expression: `\texttt{{\delta}t}`.

`latexify` will, by default, try to parse any string inputs into expressions
and this parsing has just failed.

If you are passing strings that you want returned verbatim as part of your input,
try making them `LaTeXString`s first.

If you are trying to make a table with plain text, try passing the keyword
argument `latex=false`. You should also ensure that you have chosen an output
environment that is capable of displaying not-maths objects. Try for example
`env=:table` for a latex table or `env=:mdtable` for a markdown table.

Stacktrace:
  [1] error(s::String)
    @ Base ./error.jl:35
  [2] _latexraw(::Val{…}, i::String; kwargs::@Kwargs{})
    @ Latexify ~/.julia/packages/Latexify/ieukI/src/latexraw.jl:158
  [3] _latexraw(i::String; parse::Bool, kwargs::@Kwargs{})
    @ Latexify ~/.julia/packages/Latexify/ieukI/src/latexraw.jl:148
  [4] process_latexify(args::String; kwargs::@Kwargs{})
    @ Latexify ~/.julia/packages/Latexify/ieukI/src/latexify_function.jl:49
  [5] process_latexify
    @ ~/.julia/packages/Latexify/ieukI/src/latexify_function.jl:40 [inlined]
  [6] latexraw
    @ ~/.julia/packages/Latexify/ieukI/src/latexraw.jl:58 [inlined]
  [7] _latexequation(eq::String; starred::Bool, kwargs::@Kwargs{})
    @ Latexify ~/.julia/packages/Latexify/ieukI/src/latexequation.jl:5
  [8] process_latexify(args::Num; kwargs::@Kwargs{})
    @ Latexify ~/.julia/packages/Latexify/ieukI/src/latexify_function.jl:49
  [9] process_latexify
    @ ~/.julia/packages/Latexify/ieukI/src/latexify_function.jl:40 [inlined]
 [10] latexify(args::Num; kwargs::@Kwargs{})
    @ Latexify ~/.julia/packages/Latexify/ieukI/src/latexify_function.jl:27
 [11] latexify(args::Num)
    @ Latexify ~/.julia/packages/Latexify/ieukI/src/latexify_function.jl:25
 [12] top-level scope
    @ ~/Desktop/test.jl:107

caused by: ParseError:
# Error @ none:1:1
\texttt{{\delta}t}
╙ ── not a unary operator
Stacktrace:
  [1] #parse#3
    @ ./meta.jl:244 [inlined]
  [2] parse
    @ ./meta.jl:236 [inlined]
  [3] parse(str::String; filename::String, raise::Bool, depwarn::Bool)
    @ Base.Meta ./meta.jl:278
  [4] parse
    @ ./meta.jl:276 [inlined]
  [5] _latexraw(::Val{…}, i::String; kwargs::@Kwargs{})
    @ Latexify ~/.julia/packages/Latexify/ieukI/src/latexraw.jl:155
  [6] _latexraw(i::String; parse::Bool, kwargs::@Kwargs{})
    @ Latexify ~/.julia/packages/Latexify/ieukI/src/latexraw.jl:148
  [7] process_latexify(args::String; kwargs::@Kwargs{})
    @ Latexify ~/.julia/packages/Latexify/ieukI/src/latexify_function.jl:49
  [8] process_latexify
    @ ~/.julia/packages/Latexify/ieukI/src/latexify_function.jl:40 [inlined]
  [9] latexraw
    @ ~/.julia/packages/Latexify/ieukI/src/latexraw.jl:58 [inlined]
 [10] _latexequation(eq::String; starred::Bool, kwargs::@Kwargs{})
    @ Latexify ~/.julia/packages/Latexify/ieukI/src/latexequation.jl:5
 [11] process_latexify(args::Num; kwargs::@Kwargs{})
    @ Latexify ~/.julia/packages/Latexify/ieukI/src/latexify_function.jl:49
 [12] process_latexify
    @ ~/.julia/packages/Latexify/ieukI/src/latexify_function.jl:40 [inlined]
 [13] latexify(args::Num; kwargs::@Kwargs{})
    @ Latexify ~/.julia/packages/Latexify/ieukI/src/latexify_function.jl:27
 [14] latexify(args::Num)
    @ Latexify ~/.julia/packages/Latexify/ieukI/src/latexify_function.jl:25
 [15] top-level scope
    @ ~/Desktop/test.jl:107
Some type information was truncated. Use `show(err)` to see complete types.

only

LaTeXString(string("\\texttt", "{", sym, "}"))

works. @gustaphe can you help us figure out a good solution here?

@ChrisRackauckas
Copy link
Member

#1317 seems to fix it, thanks @hersle !

@gustaphe
Copy link
Contributor

Oh, did I miss it?
Let me know if there is still an issue on the Latexify side.

@hersle
Copy link
Contributor

hersle commented Oct 21, 2024

It hopefully works now, but I think we have room for improvement 😄

I suggest to keep the discussion in #1305.

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

4 participants