PR #4253 (enhanced VR plugin) now in devel

102 views
Skip to first unread message

Edward K. Ream

unread,
Jan 2, 2025, 10:02:52 AM1/2/25
to leo-editor

Per PR #4253, Leo's VR plugin now handles the following kinds of nodes: @language katex, @language mathjax, @language typst, and @pdf. See the PR for details.


I've merged this PR so we can all test it more easily. Please report any problems immediately. A follow-on PR will fix any complaints.


Edward

Thomas Passin

unread,
Jan 2, 2025, 11:34:18 AM1/2/25
to leo-editor
Please explain what these node types are supposed to do.  Should we only enter LaTeX?  Can we enter Markdown with embedded LaTeX?  Do we need to install a pdf processor and if so, which one?  Are there differences in what we should enter between the various node types? Do we need an internet connection to use @katex and @typst (I know that mathjax can be set up not to need an I/N connection)?

Edward K. Ream

unread,
Jan 2, 2025, 12:31:47 PM1/2/25
to leo-e...@googlegroups.com
On Thu, Jan 2, 2025 at 10:34 AM Thomas Passin <tbp1...@gmail.com> wrote:

> Please explain what these node types are supposed to do. 

Great questions! One set of answers is in math.leo but here are some more direct answers:

> Should we only enter LaTeX?

You can enter various flavors of LaTeX in @language latex, @language katex, and @language typst nodes.

Rendering LaTeX (mathjax, katex, and typst) requires QWebEngineView, an implementation of the Google Chromium renderer. The three renderers are similar. They get their text from c.p.b, add a header (configurable by `@data` nodes), then pass the result to the QWebEngineView.

mathjax, katex, and typst produce different results, perhaps because their installation (headers) differ. I found the katex and typst installation instructions confusing. Those languages might give much better results in more expert hands.

I'm using mathjax because it seems to work the best. But that may be because the katex and typst headers are buggy. I'm a newbie with all three languages.

@pdf nodes are different. The body text should contain a path to a .pdf file. The path can be absolute or relative to the outline's directory. VR simply renders the pdf file.

> Can we enter Markdown with embedded LaTeX?

Afaik, the answer is "no". Iirc, katex and typst allow embedded html.

> Do we need to install a pdf processor and if so, which one?

QWebEngineView is probably the only processor needed.

> Are there differences in what we should enter between the various node types?

> Do we need an internet connection to use @katex and @typst (I know that mathjax can be set up not to need an I/N connection)?

I don't know for sure. Installing mathjax, katex, and typst locally is probably possible, but I haven't done so.

Summary

I created math.leo using trial and error. All the nodes render correctly for me.

Please download the file and try rendering all the nodes using the VR plugin.

I welcome any suggestions for improving the language-related headers.

Please feel free to ask more questions. There is plenty of time for improvements.

Edward

Thomas Passin

unread,
Jan 2, 2025, 12:55:22 PM1/2/25
to leo-editor
The external files in math.leo are not usable for anyone else but you because all they are @file types and the actual files are not in the repo.

Thomas Passin

unread,
Jan 2, 2025, 1:21:59 PM1/2/25
to leo-editor
All the @mathjax and @katex nodes display nicely in VR3 except that %comments are rendered, if 1) the "Default Kind" is set to MD, and 2) the "$" delimiters are doubled ("$$"). That's even though VR3 knows nothing about katex and renders the node using Mathjax.

See attached screen shots, which show the VR (right) and VR3 (next left) renderings.
mathjax-VR3.png
katex-VR3.png

Thomas Passin

unread,
Jan 2, 2025, 2:12:54 PM1/2/25
to leo-editor
On Thursday, January 2, 2025 at 1:21:59 PM UTC-5 Thomas Passin wrote:
All the @mathjax and @katex nodes display nicely in VR3 except that %comments are rendered, if 1) the "Default Kind" is set to MD, and 2) the "$" delimiters are doubled ("$$"). That's even though VR3 knows nothing about katex and renders the node using Mathjax.

See attached screen shots, which show the VR (right) and VR3 (next left) renderings.

You need to add two settings to turn on math for MD nodes:

@bool vr3-md-math-output = True

You can use any version of mathjax you like.  VR3 doesn't care.

Edward K. Ream

unread,
Jan 2, 2025, 5:06:33 PM1/2/25
to leo-e...@googlegroups.com
On Thu, Jan 2, 2025 at 11:55 AM Thomas Passin <tbp1...@gmail.com> wrote:
The external files in math.leo are not usable for anyone else but you because all they are @file types and the actual files are not in the repo.

The external files are in the EKR-Math repo.

Edward

lewis

unread,
Jan 3, 2025, 5:26:55 PM1/3/25
to leo-editor
The @pdf node renders a pdf file. Thanks for this VR feature.
However the VR3 plugin needs to be disabled. If VR and VR3 are both enabled the @pdf node does not render.

Thomas Passin

unread,
Jan 3, 2025, 6:07:19 PM1/3/25
to leo-editor
On Friday, January 3, 2025 at 5:26:55 PM UTC-5 lewis wrote:
The @pdf node renders a pdf file. Thanks for this VR feature.
However the VR3 plugin needs to be disabled. If VR and VR3 are both enabled the @pdf node does not render.

On my Win11 system I can have VR3 enabled and have VR display a pdf file at the same time. Do you see the VR3 pane but it doesn't show the pdf, or do you not see the VR pane at all?

lewis

unread,
Jan 3, 2025, 9:16:23 PM1/3/25
to leo-editor
When I give the vr-show command the leo screen flashes temporarily but the VR pane does not display at all.

Leo 6.8.4-devel, build 9c0810cd50
Python 3.13.1, PyQt version 6.8.1
Windows 10

Thomas Passin

unread,
Jan 3, 2025, 11:09:17 PM1/3/25
to leo-editor
Yes, I get that too. It's because the current layouts have a slot for VRx, and if VR3 is available it goes into the slot, otherwise VR goes in.  We discussed how to cure that in an earlier thread (it's not hard) but AFAIK nothing has been decided about making a change to the "official" layouts yet.

Never fear, here's a script that will display VR alongside that slot in the layouts:

@language python
"""Toggle VR in main splitter without destroying the instance."""
from leo.core.leoQt import QtCore

def find_widget(name):
    return g.app.gui.find_widget_by_name(c, name)

def show_pane(w):
    w.setUpdatesEnabled(True)
    c.doCommandByName('vr-show')

c.doCommandByName('layout-initialize')
cache = find_widget('leo-layout-cache')

# Find or create VR widget
vr = find_widget('viewrendered_pane')
if not vr:
    import leo.plugins.viewrendered as v
    vr = v.getVr()

ms = find_widget('main_splitter')

if vr.parent() == ms:
    vr.setParent(cache)
else:
    ms.addWidget(vr)

    g.app.gui.equalize_splitter(ms)
    # Avoid flash each time VR pane is re-opened.
    QtCore.QTimer.singleShot(60, lambda: show_pane(vr))

If because of your layout you would rather have VR appear next to the secondary splitter, just change `main_splitter` to 'secondary_splitter'. I have a custom menu item to launch this command .

This command makes use of another custom command  named "layout-initialize". You can comment out this line but the VR pane will be better-behaved if you include it.  IIRC, I wrote this command before the layout system was finalized and it could probably be improved on.  Some of the dictionary keys don't even exist anymore so they get defaulted.  But it does the job for me. Here's the command, which you should add as an @command layout-initialize node to myLeoSettings.leo:

@language python
"""Initialize layout widget cache and dicts."""
from collections import OrderedDict
from leo.core.leoQt import QtWidgets, Orientation

CACHENAME = 'leo-layout-cache'
CACHEHOME = c.frame.top

cache = g.app.gui.find_widget_by_name(c, CACHENAME)
if not cache:
    cache = QtWidgets.QWidget(CACHEHOME)
    cache.hide()
    cache.setObjectName(CACHENAME)

ESSENTIALS = 'layout-essential-objects'
if not c.user_dict.get(ESSENTIALS):
    SPLITTERS = OrderedDict(
                    (('outlineFrame', 'secondary_splitter'),
                    ('logFrame', 'secondary_splitter'),
                    ('secondary_splitter', 'main_splitter'),
                    ('bodyFrame', 'main_splitter'))
                )
    c.user_dict[ESSENTIALS] = SPLITTERS

DEFAULT_ORIENTATIONS = 'layout-default-orientations'
if not c.user_dict.get(DEFAULT_ORIENTATIONS):
    ORIENTATIONS = {
        'main_splitter':Orientation.Horizontal,
        'secondary_splitter':Orientation.Vertical}
    c.user_dict[DEFAULT_ORIENTATIONS] = ORIENTATIONS


If these scripts don't quite work for you, let me know and we'll come up with a custom layout for you that can contain both VR and VR3.

BTW, did you know you can enable a different set of plugins for individual outlines? I didn't until a few days ago. You can copy the @enabled-plugins node to the @settings tree in an outline and change it, e.g., by commenting out VR3.  Only that outline will get the changes. The others will continue to get the plugins enabled in myLeoSettings.leo.

lewis

unread,
Jan 3, 2025, 11:59:29 PM1/3/25
to leo-editor
Thanks Thomas, I used your script to Toggle VR in main splitter slot.
It works well on Windows and WSL linux.

Edward K. Ream

unread,
Jan 4, 2025, 5:13:41 AM1/4/25
to leo-e...@googlegroups.com
On Fri, Jan 3, 2025 at 10:09 PM Thomas Passin <tbp1...@gmail.com> wrote:
Yes, I get that too. It's because the current layouts have a slot for VRx, and if VR3 is available it goes into the slot, otherwise VR goes in.  We discussed how to cure that in an earlier thread (it's not hard) but AFAIK nothing has been decided about making a change to the "official" layouts yet.

Thomas, is there an issue open on this subject?  If not, please create one.

Edward

Thomas Passin

unread,
Jan 4, 2025, 7:50:50 AM1/4/25
to leo-editor
All right. The main thing for us to decide is where to place the two VRx panes.  IMHO they should always open side-by-side, rather than one above the other.  This arrangement is nearly trivial to achieve with the vertical-thirds-like layouts. This policy will affect how to make the changes for some of the layouts, so we need to decide if it's the way to go.

Thomas Passin

unread,
Jan 6, 2025, 2:26:56 PM1/6/25
to leo-editor
Implemented by PR https://github.com/leo-editor/leo-editor/pull/4263 which is awaiting approval.

Edward K. Ream

unread,
Jan 7, 2025, 6:05:11 AM1/7/25
to leo-e...@googlegroups.com
Many thanks for this work. I have merged the PR into devel.

After-merge testing shows that VR and VR3 coexist well in both the "legacy" and "horizontal-thirds" layouts.

This is an important step forward for Leo. Thanks again.

Edward
Reply all
Reply to author
Forward
0 new messages