Closed nathanrboyer closed 1 year ago
Possibly related to #131 ?
This one is tricky to debug, like you point out the function runs fine when called by itself.
The issue with @latexdefine
is that it expects things to have a :raw
representation (because it does something akin to "\$x = $(latexify(x; env=:raw))\$"
). DataFrames don't have this, but only "latexify" as latexify(df; env=:mdtable)
. Of course you cannot put one of those inside an equation anyway so it's not much of a loss, but perhaps the error message is a bit unhelpful.
Do you need to print latex versions of all of these calls on package import? Perhaps try wrapping the printing in a function (__init__
?), should make the whole thing easier to debug.
I don't need printing on package import. I only need printing when I Weave. I just can't figure out how to solve all these competing requirements.
julia> KM620.H
H (generic function with 1 method)
julia> latexify(KM620.H) ERROR: AssertionError: latexify does not support objects of type typeof(KM620.H). Stacktrace: [1] _latexraw(args::Function; kwargs::Base.Pairs{Symbol, Symbol, Tuple{Symbol}, NamedTuple{(:env,), Tuple{Symbol}}}) @ Latexify C:\Users\nboyer.AIP.julia\packages\Latexify\2QVWl\src\latexraw.jl:109
julia> @latexrun H(σ_t, σ_ys, σ_uts, K) = @. 2 (σ_t - (σ_ys + K (σ_uts - σ_ys))) / (K * (σ_uts - σys)) L"$H\left( \sigma{t}, \sigma{ys}, \sigma{uts}, K \right) = \frac{2 \cdot \left( \sigma{t} - \left( \sigma{ys} + K \cdot \left( \sigma{uts} - \sigma{ys} \right) \right) \right)}{K \cdot \left( \sigma{uts} - \sigma{ys} \right)}$"
2. Latexify requires that I print the data frame definitions after I define them:
```julia
julia> table = DataFrame(x=1:3)
3×1 DataFrame
Row │ x
│ Int64
─────┼───────
1 │ 1
2 │ 2
3 │ 3
julia> latexify(table)
x
–
1
2
3
julia> @latexdefine table = DataFrame(x=1:3)
ERROR: AssertionError: latexify does not support objects of type DataFrame.
module
and end #module
statements into a different file. Also, if I call weave
on a file that just has latexify(x)
calls, I will get undefined errors unless x
is also defined in that file. Okay I don't know what Weave does or how, so I'm not sure about any of this.
Perhaps what you need is someting like a macro that stores a function and its definition in the same object, which can then be latexified like
@latexrecipe f(x::FunctionAndExpr) = x.ex
But I don't know how sensible that would be. Does Weave really require you to latexify every line manually?
When it comes to the dataframes, it really doesn't make sense to put a table on the right hand side in a LaTeX equation. latexify(::DataFrame)
doesn't produce valid LaTeX code but a markdown table, so if Weave expects LaTeX that's a dead end.
It is my first time using Weave.jl, so I am not totally clear on how it works. I think there is an intermediate markdown step: .jl -> .md -> .tex -> .pdf. It captures the output from running a .jl file and renders that to a PDF. In this case, I want the output to be latexified equations and tables, so I am manually latexifying everything. There might be a better way.
This discussion did help me to figure out a work-around for the error though. I have a working version of my code here! I moved the DataFrame definitions into their own file, and I moved the latexify(df)
calls to their own file too. The downside is it now generates three separate PDF files, but I can combine those with a post-processing shell command. I will write more about it here.
I wrote a package which defines some functions and constant tables. I am using Weave.jl on it from a file in the test folder to generate a PDF output. The Weave half is now working great (besides this Weave issue). However, I am getting a strange error now when I try to load my package with
using KM620
on the linelatexify(select(coefficients_table_forprinting, 1))
.That line works fine when I run it in the REPL, so I don't understand why Latexify is telling me it does not support objects of type DataFrame.
I initially tried to use
@latexdefine
in front of the DataFrame definition instead of callinglatexify
separately later, but that yielded a different error.Again, everything runs perfectly fine when I run
weave
on the file.