Latexify.jl icon indicating copy to clipboard operation
Latexify.jl copied to clipboard

Integrate with LibTeXPrintf.jl

Open Suavesito-Olimpiada opened this issue 2 years ago • 8 comments

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.

Suavesito-Olimpiada avatar Sep 24 '22 00:09 Suavesito-Olimpiada

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

gustaphe avatar Sep 24 '22 03:09 gustaphe

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.

gustaphe avatar Sep 24 '22 08:09 gustaphe

It does have methods accepting LaTeXString.

Suavesito-Olimpiada avatar Sep 24 '22 18:09 Suavesito-Olimpiada

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.

Suavesito-Olimpiada avatar Sep 24 '22 19:09 Suavesito-Olimpiada

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

gustaphe avatar Sep 25 '22 07:09 gustaphe

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.

gustaphe avatar Sep 26 '22 12:09 gustaphe

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.

stevengj avatar May 21 '23 19:05 stevengj

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

  • the library is lightweight, now only depends on libtexprint_jll,
  • the library is in better shape and can render even more TeX
  • all the errors detected by the library are returned now, although I need to improve the formatting
  • you can pass fail=false to log and error instead of thowing it, this way the function still returns the string formed, this helps in finding the bad formatting.

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. :)

Suavesito-Olimpiada avatar Jun 08 '23 17:06 Suavesito-Olimpiada