How are @latex nodes used?

52 views
Skip to first unread message

tbp1...@gmail.com

unread,
Nov 14, 2021, 12:49:40 PM11/14/21
to leo-editor
Viewrendered can render @latex nodes in a restricted way.  I was reminded of this by an issue of @LewisNeal. VR3 does not at present but it would be easy to duplicate VR's capability.  I have two questions about it before I move to enable it in VR3.  One is minor, the other more existential.  The minor one first:

The code claims that in Windows/python the rendering is not available. But all the rendering code does is to insert the node's text into a basic html string that includes an import for the MathJax script.  That does not depend on Windows or the python version in any way.  So why is this restriction there?  It makes me think that @latex nodes used to be able to do more at some time in the past.

The more existential question is: what is this capability for, anyway?  What is the use case? It must mostly be for rendering math, but math almost always requires some text along with it.  Mathjax can render plain text using the \\text{} macro, but this is awkward  and limited.

VR3 can already render math in ReStructured and Markdown text pages, and can mix text and math more easily.  I think that full latex rendering - beyond what Mathjax can do - is not going to be in the cards for VR/VR3.  You would have to use a full-fledged latex processor, and they are very slow and finicky about the content. TexWorks, for example, sometimes requires manual input to deal with hiccups.

So before I enable @latex nodes in VR3, I'd appreciate some guidance about  how people want to use it.

Edward K. Ream

unread,
Nov 14, 2021, 4:16:55 PM11/14/21
to leo-editor
On Sun, Nov 14, 2021 at 11:49 AM tbp1...@gmail.com <tbp1...@gmail.com> wrote:

So before I enable @latex nodes in VR3, I'd appreciate some guidance about  how people want to use it.

I never use LaTex, so I will be no help :-)

Edward

tbp1...@gmail.com

unread,
Nov 15, 2021, 2:13:00 PM11/15/21
to leo-editor
I thought of a reason to use @latex nodes.  You could use them to help work out the details of getting the latex for your equations right.  You could do this with using ..math directives with ReStructuredText also, but RsT might be adding some macro you didn't want.

With that in mind, I've got working code for Viewrendered3.  The features go beyond what ViewRendered offers, but before I make a PR I'd like to get comments on them, including if I have missed something I should include:

1. Only a single node will be processed as an @latex node; the rest of a subtree will not be processed.
2. Some special characters, mainly "&", are replaced by their  HTML entities (e.g., "&amp;") inside math blocks, but not outside.  This lets you write arbitrary HTML outside math blocks.  It solves the problem of not being able to format your non-math text readably;
3. The rendering can be exported to the system browser using VR3's Export toolbar button;
4. The Mathjax URL is taken from your VR3 settings, or defaults to https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js;
5. VR3 uses the text and background colors from VR3's RsT stylesheet if it can find them.  This prevents unexpected changes in the appearance of the rendered pane when you switch from a non-@latex node to an @latex one.

Note that you should not use @language latex directives within other, non-@latex, nodes.  The results are not defined, and I have not written any code to handle that situation.  The limitation to a single node in Point 1 could be removed if there is enough interest.

Rob

unread,
Nov 15, 2021, 2:21:10 PM11/15/21
to leo-editor
I use LaTeX a lot, so my initial thoughts on this are:
  1. Rendering LaTeX code would be 'nice to have', but for me anyway, not 'need to have'.
  2. The only rendering that would make any sense would have to use the 'least common denominator' from the basic TEX commands and would never be able to render custom commands, which I use frequently.
  3. It seems that the effort to make it work in Leo would far exceed any potential benefit.
My 2 cents...
Rob...

tbp1...@gmail.com

unread,
Nov 15, 2021, 3:45:18 PM11/15/21
to leo-editor
That's definitely true - the "latex" rendering is only for what can be handled by Mathjax, and even those parts can be slightly different from standard latex.  This project started out to bring this part of the Viewrendered3 plugin up to par with Viewrendered.  Along the way I added a few more bits to make it more usable.  But I don't know who is actually using it (with VR) and how.

Edward K. Ream

unread,
Nov 15, 2021, 4:20:04 PM11/15/21
to leo-editor
On Mon, Nov 15, 2021 at 1:21 PM Rob <lar...@gmail.com> wrote:
I use LaTeX a lot, so my initial thoughts on this are:
  1. Rendering LaTeX code would be 'nice to have', but for me anyway, not 'need to have'.
  2. The only rendering that would make any sense would have to use the 'least common denominator' from the basic TEX commands and would never be able to render custom commands, which I use frequently.
  3. It seems that the effort to make it work in Leo would far exceed any potential benefit.
Thanks, Rob, for these comments. As I've just posted on another topic, it's useful to kill dubious ideas quickly!

Edward

Rob Keeney

unread,
Nov 15, 2021, 6:59:05 PM11/15/21
to leo-e...@googlegroups.com
Perhaps there's some value in rendering LaTeX math in Leo considering how difficult it is to see what the end result might look like after 'processing'. However, anything beyond that seems like a 'fool's errand' to me. For context, please know that I rarely use LaTeX for math, mostly for other writing, so my views on the subject may not represent a consensus.

Rob...

tbp1...@gmail.com

unread,
Nov 15, 2021, 7:30:15 PM11/15/21
to leo-editor
Thanks for your thoughts.  Yes, I mostly thought of math and equations.  It's pretty hard to get that working right until you learn all the tricks - that has been my experience, anyway - and quick feedback is a big help.
Reply all
Reply to author
Forward
0 new messages