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

Question on extension and latexraw vs. _latexraw #185

Closed
ranocha opened this issue Oct 7, 2021 · 3 comments
Closed

Question on extension and latexraw vs. _latexraw #185

ranocha opened this issue Oct 7, 2021 · 3 comments

Comments

@ranocha
Copy link
Contributor

ranocha commented Oct 7, 2021

First of all, thank for this nice package!

I tried to use Latexify with one of my own types. For example, I would like to get the following to work.

julia> using Pkg; Pkg.activate(temp=true); Pkg.add("Latexify")

julia> using Latexify

julia> struct Foo end

julia> foo = Foo()
Foo()

julia> latexify(foo) # will fail as expected
ERROR: AssertionError: latexify does not support objects of type Foo.
[...]

julia> latexify( [foo] ) # this will of course also fail
ERROR: AssertionError: latexify does not support objects of type Foo.
[...]

Thus, I looked at the source code of plugins and found the simplest one to be the one for SymEngine.jl. Thus, I tried to copy that strategy.

julia> Latexify.latexraw(::Foo; kwargs...) = "your LaTeX string goes here"

julia> latexify( [foo] ) # this works
L"\begin{equation}
\left[
\begin{array}{c}
your LaTeX string goes here \\
\end{array}
\right]
\end{equation}
"

julia> latexify(foo) # this still fails
ERROR: AssertionError: latexify does not support objects of type Foo.

However, everything seems to work if I overload _latexify instead.

julia> Latexify._latexraw(::Foo; kwargs...) = "your LaTeX string goes here"

julia> latexify( [foo] ) # this works
L"\begin{equation}
\left[
\begin{array}{c}
your LaTeX string goes here \\
\end{array}
\right]
\end{equation}
"

julia> latexify(foo) # this also works
L"$your LaTeX string goes here$"

So my questions are:

  1. Is this intended behavior?
  2. Can I consider _latexraw as stable API to use for this use case or should I write a @latexrecipe instead?
  3. Is there a way to hook into this machinery without using Requires.jl or having Latexify.jl (and indirectly also all of its dependencies) as dependency of a package?

The problem with questions 2 and 3 is that I can't use @require from Requires.jl with @latexrecipe since I get the error that @latexrecipe is not defined.

@gustaphe
Copy link
Collaborator

gustaphe commented Oct 8, 2021

The best way is to create a recipe. The "plugins" here are poor models to emulate as they predate that system. I don't think _latexraw can be considered stable, it just recently went through a fairly major overhaul.

The clash between @require and @latexrecipe is news to me. I can't get @require to work sensibly for anything right now, so I can't really debug this, but try putting the recipe in it's own file and do @require ... include("thatfile.jl")?

@korsbo
Copy link
Owner

korsbo commented Oct 18, 2021

Hi, sorry that I'm late in noticing the issue.

Overloading _latexraw should work but is not part of the API and should not be considered stable.

That said, as soon as I can carve out a little bit of time from work (maybe December) I'm intending to overhaul latexify quite a bit. So if you have some hacky solution that works for now, one strategy would be to just wait until the Latexify overhaul which should allow you more control when you extend latexify to work with your types.

The Requires stuff predates the ability of external packages to extend Latexifys functionality and will be removed before a 1.0 release (hopefully not too far off, but then again, I've been saying that for a while).

@ranocha
Copy link
Contributor Author

ranocha commented Oct 18, 2021

Okay, thanks for the information! I will use the approach based on recipes as suggested above in my own packages. By the way, it would be great to prepare PRs to packages currently using the old infrastructure from within Latexify.jl when you switch to a new system (I am mostly thinking about SymEngine.jl).

@ranocha ranocha closed this as completed Oct 18, 2021
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

3 participants