korsbo / Latexify.jl

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

latexify does not support objects of type InlineStrings.String7 #272

Closed a2k42 closed 9 months ago

a2k42 commented 9 months ago

I was trying to convert a csv file to a markdown table and ran into an error whenever I had strings in my file (obviously a very common scenario)

Minimal example:

df = DataFrame(CSV.File("file.csv"))
latexify(df)

There's a discourse suggesting that you need to handle AbstractString instead of just String. The breaking change happened a couple of years ago so maybe I've missed something?

AssertionError: latexify does not support objects of type InlineStrings.String7. var"#_latexraw#45"(::Base.Pairs{Symbol, Symbol, Tuple{Symbol}, NamedTuple{(:env,), Tuple{Symbol}}}, ::typeof(Latexify._latexraw), ::InlineStrings.String7)@latexraw.jl:109 var"#process_latexify#156"(::Base.Pairs{Symbol, Symbol, Tuple{Symbol}, NamedTuple{(:env,), Tuple{Symbol}}}, ::typeof(Latexify.process_latexify), ::InlineStrings.String7)@latexify_function.jl:49 process_latexify@latexify_function.jl:40[inlined] var"#_latexinline#98"(::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}, ::typeof(Latexify._latexinline), ::InlineStrings.String7)@latexinline.jl:4 _latexinline(::InlineStrings.String7)@latexinline.jl:3 _broadcast_getindex_evalf@broadcast.jl:683[inlined] _broadcast_getindex@broadcast.jl:656[inlined] getindex@broadcast.jl:610[inlined] copyto_nonleaf!(::Matrix{LaTeXStrings.LaTeXString}, ::Base.Broadcast.Broadcasted{Base.Broadcast.DefaultArrayStyle{2}, Tuple{Base.OneTo{Int64}, Base.OneTo{Int64}}, typeof(Latexify._latexinline), Tuple{Base.Broadcast.Extruded{Matrix{Any}, Tuple{Bool, Bool}, Tuple{Int64, Int64}}}}, ::CartesianIndices{2, Tuple{Base.OneTo{Int64}, Base.OneTo{Int64}}}, ::CartesianIndex{2}, ::Int64)@broadcast.jl:1068 copy@broadcast.jl:920[inlined] materialize@broadcast.jl:873[inlined] var"#mdtable#115"(::Bool, ::Bool, ::Vector{Symbol}, ::Vector{Any}, ::Bool, ::Nothing, ::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}, ::typeof(Latexify.mdtable), ::Matrix{Any})@mdtable.jl:61 var"#mdtable#1"(::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}, ::typeof(Latexify.mdtable), ::DataFrames.DataFrame)@DataFramesExt.jl:21 mdtable(::DataFrames.DataFrame)@DataFramesExt.jl:18 var"#process_latexify#156"(::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}, ::typeof(Latexify.process_latexify), ::DataFrames.DataFrame)@latexify_function.jl:49 process_latexify@latexify_function.jl:40[inlined] var"#latexify#155"(::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}, ::typeof(Latexify.latexify), ::DataFrames.DataFrame)@latexify_function.jl:27 latexify(::DataFrames.DataFrame)@latexify_function.jl:25 top-level scope@Local: 3[inlined]

a2k42 commented 9 months ago

The correct usage was to use latexify(df, env=:mdtable, latex=false) as given by a later error message:

in Latexify.jl:
You are trying to create latex-maths from a String that cannot be parsed as
an expression: Hello World.

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 LaTeXStrings 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.