korsbo / Latexify.jl

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

latex keyword unsupported #34

Closed baggepinnen closed 6 years ago

baggepinnen commented 6 years ago

Im trying to latexify an array of strings, which Latexify complains about since they can not be parsed as latex math. The suggestion to add kwarg latex=false fails as well, saying that latex is not a supported keyword argument

julia> topics
20×6 Array{String,2}:
 "time"            "controller"   "model"        "robot"       "glucose"      "linear"
 "paper"           "process"      "combustion"   "force"       "insulin"      "time"
 "based"           "pid"          "engine"       "model"       "models"       "model"
 "applications"    "design"       "paper"        "based"       "students"     "optimal"
 "model"           "paper"        "cylinder"     "using"       "blood"        "paper"
 "software"        "based"        "pressure"     "industrial"  "data"         "feedback"
 "real"            "performance"  "controller"   "estimation"  "learning"     "stability"
 "performance"     "controllers"  "ignition"     "paper"       "course"       "method"
 "resource"        "tuning"       "operating"    "method"      "based"        "optimization"
 "design"          "method"       "based"        "motion"      "paper"        "based"
 "optimization"    "proposed"     "cycle"        "robots"      "innovation"   "using"
 "application"     "loop"         "temperature"  "sensor"      "prediction"   "function"
 "scheduling"      "processes"    "fuel"         "position"    "gt"           "algorithm"
 "modelica"        "model"        "production"   "approach"    "predictors"   "design"
 "implementation"  "time"         "injection"    "results"     "lt"           "proposed"
 "cloud"           "disturbance"  "using"        "proposed"    "patient"      "approach"
 "dynamic"         "using"        "low"          "time"        "technology"   "constraints"
 "resources"       "robustness"   "power"        "vehicle"     "time"         "loop"
 "simulation"      "closed"       "hcci"         "sensors"     "using"        "network"
 "approach"        "methods"      "models"       "models"      "development"  "distributed"

julia> latexify(topics)
ERROR: Error in Latexify.jl: You are trying to create latex-maths from a string that cannot be parsed as an expression. If you are trying to make a table or an array with plain text, try passing the keyword argument `latex=false`.
Stacktrace:
 [1] latexraw(::String) at /local/home/fredrikb/.julia/packages/Latexify/3shva/src/latexraw.jl:94
 [2] iterate at ./generator.jl:47 [inlined]
 [3] collect_to!(::Array{String,2}, ::Base.Generator{Array{String,2},typeof(latexraw)}, ::Int64, ::Int64) at ./array.jl:656
 [4] collect_to_with_first!(::Array{String,2}, ::String, ::Base.Generator{Array{String,2},typeof(latexraw)}, ::Int64) at ./array.jl:643
 [5] collect(::Base.Generator{Array{String,2},typeof(latexraw)}) at ./array.jl:624
 [6] latexraw at /local/home/fredrikb/.julia/packages/Latexify/3shva/src/latexraw.jl:78 [inlined]
 [7] #latexarray#3(::Symbol, ::Bool, ::Bool, ::Bool, ::Function, ::Array{String,2}) at /local/home/fredrikb/.julia/packages/Latexify/3shva/src/latexarray.jl:25
 [8] latexarray(::Array{String,2}) at /local/home/fredrikb/.julia/packages/Latexify/3shva/src/latexarray.jl:17
 [9] #latexify#2(::Symbol, ::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}, ::Function, ::Array{String,2}) at /local/home/fredrikb/.julia/packages/Latexify/3shva/src/latexify_function.jl:4
 [10] latexify(::Array{String,2}) at /local/home/fredrikb/.julia/packages/Latexify/3shva/src/latexify_function.jl:2
 [11] top-level scope at none:0

julia> latexify(topics, latex=false)
ERROR: MethodError: no method matching latexarray(::Array{String,2}; latex=false)
Closest candidates are:
  latexarray(::AbstractArray{T,2} where T; adjustment, transpose, double_linebreak, starred) at /local/home/fredrikb/.julia/packages/Latexify/3shva/src/latexarray.jl:17 got unsupported keyword argument "latex"
  latexarray(::AbstractArray...; kwargs...) at /local/home/fredrikb/.julia/packages/Latexify/3shva/src/latexarray.jl:41
  latexarray(::AbstractArray{T,1} where T; kwargs...) at /local/home/fredrikb/.julia/packages/Latexify/3shva/src/latexarray.jl:40
  ...
Stacktrace:
 [1] kwerr(::NamedTuple{(:latex,),Tuple{Bool}}, ::Function, ::Array{String,2}) at ./error.jl:97
 [2] (::getfield(Latexify, Symbol("#kw##latexarray")))(::NamedTuple{(:latex,),Tuple{Bool}}, ::typeof(latexarray), ::Array{String,2}) at ./none:0
 [3] #latexify#2(::Symbol, ::Base.Iterators.Pairs{Symbol,Bool,Tuple{Symbol},NamedTuple{(:latex,),Tuple{Bool}}}, ::Function, ::Array{String,2}) at /local/home/fredrikb/.julia/packages/Latexify/3shva/src/latexify_function.jl:4
 [4] (::getfield(Latexify, Symbol("#kw##latexify")))(::NamedTuple{(:latex,),Tuple{Bool}}, ::typeof(latexify), ::Array{String,2}) at ./none:0
 [5] top-level scope at none:0
korsbo commented 6 years ago

Aah, I agree that this is not a very desirable outcome. It looks like the problem is that the default output environment of a simple matrix like this is an latex array. These are really made for maths, and I'm not sure that it's what you really want. Have you tried to also specify the output environment env = :table or env = :mdtable?

Regardless, the defaults, or the error message should be updated.

korsbo commented 6 years ago
latexify(topics, env=:mdtable, latex=false)

and

latexify(topics, env=:table, latex=false)

works well for me.

Would you say that it is sufficient to update the error message to reflect this? Tinkering with the defaults would have consequences for stuff like:

m = [ "x/y" "x_1"
      "a/b" "c^2"]
latexify(m)

which really should be latexified and placed in an array.

baggepinnen commented 6 years ago

Thanks, that does the trick here as well. An edit of the error message would be perfectly fine!