korsbo / Latexify.jl

Convert julia objects to LaTeX equations, arrays or other environments.
MIT License
544 stars 55 forks source link

3D arrays/tensors #284

Closed freemin7 closed 2 months ago

freemin7 commented 4 months ago
W = [
0 0.5 0 0 0 0 0 0 
0.5 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0;;;
0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0
0 0 0 0.5 0 0 0 0
0 0 0.5 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0;;;
0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0.5 0 0
0 0 0 0 0.5 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0;;;
0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0.5
0 0 0 0 0 0 0.5 0
]

latexify(W) crashes with:

ERROR: BoundsError: attempt to access 8×8×4 Array{String, 3} at index [1, 1] Stacktrace: [1] getindex(::Array{String, 3}, ::Int64, ::Int64) @ Base ./essentials.jl:14 [2] _latexarray(arr::Array{Float64, 3}; adjustment::Symbol, transpose::Bool, double_linebreak::Bool, starred::Bool, arraystyle::Symbol, kwargs::Base.Pairs{Symbol, Symbol, Tuple{Symbol}, NamedTuple{(:env,), Tuple{Symbol}}}) @ Latexify ~/.julia/packages/Latexify/rf2cZ/src/latexarray.jl:49 [3] _latexarray @ ~/.julia/packages/Latexify/rf2cZ/src/latexarray.jl:17 [inlined] [4] #_latexraw#46 @ ~/.julia/packages/Latexify/rf2cZ/src/latexraw.jl:112 [inlined] [5] process_latexify(args::Array{Float64, 3}; kwargs::Base.Pairs{Symbol, Symbol, Tuple{Symbol}, NamedTuple{(:env,), Tuple{Symbol}}}) @ Latexify ~/.julia/packages/Latexify/rf2cZ/src/latexify_function.jl:49 [6] process_latexify @ ~/.julia/packages/Latexify/rf2cZ/src/latexify_function.jl:40 [inlined] [7] #latexraw#40 @ ~/.julia/packages/Latexify/rf2cZ/src/latexraw.jl:58 [inlined] [8] latexraw @ ~/.julia/packages/Latexify/rf2cZ/src/latexraw.jl:58 [inlined] [9] _latexequation(eq::Array{Float64, 3}; starred::Bool, kwargs::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}) @ Latexify ~/.julia/packages/Latexify/rf2cZ/src/latexequation.jl:5 [10] _latexequation(eq::Array{Float64, 3}) @ Latexify ~/.julia/packages/Latexify/rf2cZ/src/latexequation.jl:4 [11] process_latexify(args::Array{Float64, 3}; kwargs::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}) @ Latexify ~/.julia/packages/Latexify/rf2cZ/src/latexify_function.jl:49 [12] process_latexify @ ~/.julia/packages/Latexify/rf2cZ/src/latexify_function.jl:40 [inlined] [13] latexify(args::Array{Float64, 3}; kwargs::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}) @ Latexify ~/.julia/packages/Latexify/rf2cZ/src/latexify_function.jl:27 [14] latexify(args::Array{Float64, 3}) @ Latexify ~/.julia/packages/Latexify/rf2cZ/src/latexify_function.jl:25 [15] top-level scope @ REPL[4]:1

gustaphe commented 3 months ago

It's unfortunate that this crashes with an indexing error, it should probably fail gracefully. Or would you expect this to show as something nicer?

freemin7 commented 3 months ago

I have no strong opinion on how to resolve this. Either is reasonable.

08.04.2024 17:39:42 gustaphe @.***>:

It's unfortunate that this crashes with an indexing error, it should probably fail gracefully. Or would you expect this to show as something nicer?

— Reply to this email directly, view it on GitHub[https://github.com/korsbo/Latexify.jl/issues/284#issuecomment-2043083521], or unsubscribe[https://github.com/notifications/unsubscribe-auth/AGBTNTDLM73VQE5DCFKEX3TY4K235AVCNFSM6AAAAABEJZV2HKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDANBTGA4DGNJSGE]. You are receiving this because you authored the thread. [Verfolgungsbild][https://github.com/notifications/beacon/AGBTNTCKHMTZJNGF5WS2RADY4K235A5CNFSM6AAAAABEJZV2HKWGG33NNVSW45C7OR4XAZNMJFZXG5LFINXW23LFNZ2KUY3PNVWWK3TUL5UWJTTZY35QC.gif]

hyrodium commented 2 months ago

This issue should be closed by #286, but we can still improve the error message with 0-dimensional arrays.

julia> using Latexify

julia> latexify(fill(42))
ERROR: MethodError: no method matching getindex(::String, ::Int64, ::Int64)

Closest candidates are:
  getindex(::String, ::Int64)
   @ Base strings/string.jl:429
  getindex(::AbstractString, ::Integer)
   @ Base strings/basic.jl:184
  getindex(::String, ::UnitRange{Int64})
   @ Base strings/string.jl:464
  ...

Stacktrace:
  [1] _latexarray(arr::Array{Int64, 0}; adjustment::Symbol, transpose::Bool, double_linebreak::Bool, starred::Bool, arraystyle::Symbol, kwargs::@Kwargs{env::Symbol})
    @ Latexify ~/.julia/dev/Latexify/src/latexarray.jl:50
  [2] _latexarray
    @ ~/.julia/dev/Latexify/src/latexarray.jl:17 [inlined]
  [3] #_latexraw#46
    @ ~/.julia/dev/Latexify/src/latexraw.jl:112 [inlined]
  [4] process_latexify(args::Array{Int64, 0}; kwargs::@Kwargs{env::Symbol})
    @ Latexify ~/.julia/dev/Latexify/src/latexify_function.jl:49
  [5] process_latexify
    @ ~/.julia/dev/Latexify/src/latexify_function.jl:40 [inlined]
  [6] latexraw
    @ ~/.julia/dev/Latexify/src/latexraw.jl:58 [inlined]
  [7] _latexequation(eq::Array{Int64, 0}; starred::Bool, kwargs::@Kwargs{})
    @ Latexify ~/.julia/dev/Latexify/src/latexequation.jl:5
  [8] _latexequation(eq::Array{Int64, 0})
    @ Latexify ~/.julia/dev/Latexify/src/latexequation.jl:4
  [9] process_latexify(args::Array{Int64, 0}; kwargs::@Kwargs{})
    @ Latexify ~/.julia/dev/Latexify/src/latexify_function.jl:49
 [10] process_latexify
    @ ~/.julia/dev/Latexify/src/latexify_function.jl:40 [inlined]
 [11] latexify(args::Array{Int64, 0}; kwargs::@Kwargs{})
    @ Latexify ~/.julia/dev/Latexify/src/latexify_function.jl:27
 [12] latexify(args::Array{Int64, 0})
    @ Latexify ~/.julia/dev/Latexify/src/latexify_function.jl:25
 [13] top-level scope
    @ REPL[3]:1