korsbo / Latexify.jl

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

Integrate with LibTeXPrintf.jl #232

Open Suavesito-Olimpiada opened 1 year ago

Suavesito-Olimpiada commented 1 year ago

I just write a small wrapper around a C library called LibTeXPrinf.jl, for rendering LaTeX to a Unicode string, maybe this can be used to display in the terminal.

I'll be registering this in the next days.

gustaphe commented 1 year ago

Latexify.jl generates LaTeXStrings. How those are rendered is a question for LaTeXStrings.jl.

gustaphe commented 1 year ago

Okay, I'm slightly wrong. But I think it would be a lot more versatile if your package had a method to accept a LaTeXString. Then Latexify and other LaTeXStrings will work automatically, and the package import overhead is minimized.

Suavesito-Olimpiada commented 1 year ago

It does have methods accepting LaTeXString.

Suavesito-Olimpiada commented 1 year ago

What it does for LaTeXStrings is to remove the trailing and leading '$' by default from the underlying String representation and pass that to the C library. Then it captures the output and prints or from the Julia side, this is to be about to integrate with IO from Julia.

gustaphe commented 1 year ago

So texprintf(@latexify 3x^2 + y/z) already does the right thing?

gustaphe commented 1 year ago

Okay, I've played around with it a bit. It feels like a somewhat immature project: it supports a limited subset of TeX syntax, the errors are cryptic and documentation is lacking when it comes to available arguments. For instance, the root project, libtexprintf and its utftex command, has an option to set math in italics, which should certainly be the default for math being fed to the function.

When the package is a bit more mature it would certainly be possible, depending on its weight as a dependency, to create a render method with texprintf as the engine. Until then, I would suggest just using LibTeXPrintf and substituting texprintf for render.

stevengj commented 1 year ago

has an option to set math in italics, which should certainly be the default for math being fed to the function

I suspect that most people wanting plain-text output for don't want italic plain-text using Unicode italics. If you have $x+ y$ and you ask for a text rendering, would you want "x + y" or "𝑥 + 𝑦" as the "text/plain" output string? I'm guessing the former for most people?

Note that the underlying library here is GPL (https://github.com/Suavesito-Olimpiada/LibTeXPrintf.jl/issues/6), so you might want to be cautious about adding it as a hard dependency. However, it might be reasonable to add it as an optional depenency of LaTeXStrings, so that if you do using LibTexPrintf, LaTeXStrings it will use this for text/plain display.

Suavesito-Olimpiada commented 1 year ago

and substituting texprintf for render .

The package is now registered, but instead of render, it went like texstring (render is a lot better name, I just didn't see this).

I think this can be considered now that the concerns have been solved

I've basically rewriten the wrapper. The wrapper and underlying library are in better shape, thanks in part to stevengj, as he did several necessary contributions on both the wrapper and the library. :)