This Engineering Notebook post discusses recent experiments using Leo as a mathematical notebook.
My goal was to eliminate all friction from my mathematical workflow. This post tells how I did it.
References
PR #4253 contains improvements to VR. The public math.leo outline contains recent experiments, including tests of all aspects of VR related to mathematics.
Using LaTeX and pdf
The Overleaf website was a great way to learn LaTeX, but it can't be the basis of my workflow. Cutting snippets from the website to math.leo quickly becomes intolerable.
Overleaf renders LaTeX by generating an internal pdf file using pdflatex and then rendering that file. My first thought was to emulate that approach. However, that approach wasn't good enough. The PostScript contains the gruesome details.
Using mathjax
Another problem with pdf files became apparent only in retrospect. As stated here, TeX/LaTeX is a print layout engine. When using Overleaf, I spent considerable time configuring the page layout to look good on the Overleaf web page. But that work isn't necessary!
Instead of futzing with page layout, mathjax renders only LaTeX math mode. To quote from the link above, "MathJax expects that you will use standard HTML tags to handle formatting the text of your page."
This approach is exactly what we need in the VR pane. The PR renders @mathjax nodes (nodes containing @language mathjax) in the VR pane. Changes in p.b render automatically (and quickly) in the VR pane.
mathjax has its quirks. There are subtle differences between mathjax and LaTeX. In particular, it appears best to use mathjax 2 rather than 3.
Summary
The general goal of eliminating friction produced a surprise. mathjax, not LaTeX, is a better fit for Leo. The PR creates a friction-free environment for doing mathematics in Leo.
Edward
P.S. Some details:
Problems using pdf files.
math.leo contains @button render-latex. This script assumes that c.p.b contains LaTeX code. The script:
- Converts c.p.b to a pdf file whose name is a sanitized version of c.p.h.
- Searches the outline for a corresponding @pdf node, creating the node if necessary.
The body text of this node contains the full path to the generated pdf file.
The PR adds support for @pdf nodes. Selecting the node will render the named pdf file.
Alas, @pdf doesn't work well enough. Qt does render the pdf file, but there is no way to set a default magnification of the rendered text! This defect quickly becomes intolerable. Furthermore, using two separate nodes is way too clumsy.
About the QWebEngineView class
The revised VR plugin uses the QWebEngineView class for all html-related nodes. This class is a wrapper around the Chromium open-source browser. This browser should have enough firepower.
Alas, Qt's support for pdf files uses a hidden pdf plugin. This plugin is inaccessible via any programming API. Hours of googling and experimentation failed to find any access points.
Interference from GE Force Experience
The VR3 plugin raises a bizarre warning on my machine. With the revised VR plugin, I got the same warning! This message originates from the GE Force Experience package, a part of the NVidia video driver.
Somehow, instantiating the QWebEngineView class triggered a notification from the NVidia package! Turning off the notification eliminated the message. The NVidia package is obsolete, so I removed it.
Hangs on Exit
Earlier versions of the PR could hang when Leo shut down. As a workaround, the PR deletes all known objects related to the QWebEngineView class.
Leo no longer hangs since I removed the GE Force experience package. In any case, the bug appears to have been caused outside of Leo and the VR plugin.
EKR
Interference from GE Force Experience
The VR3 plugin raises a bizarre warning on my machine. With the revised VR plugin, I got the same warning! This message originates from the GE Force Experience package, a part of the NVidia video driver.
Somehow, instantiating the QWebEngineView class triggered a notification from the NVidia package! Turning off the notification eliminated the message. The NVidia package is obsolete, so I removed it.
About the QWebEngineView class
The revised VR plugin uses the QWebEngineView class for all html-related nodes. This class is a wrapper around the Chromium open-source browser. This browser should have enough firepower.
Alas, Qt's support for pdf files uses a hidden pdf plugin. This plugin is inaccessible via any programming API. Hours of googling and experimentation failed to find any access points.
I suppose you already found this, but in case you didn't, you can set up the QWebEngineView for the pdf viewer like this:settings = qwev.settings() # qwev = QWebEngineView instance
settings.setAttribute(settings.WebAttribute.PluginsEnabled, True)
settings.setAttribute(settings.WebAttribute.PdfViewerEnabled, True)
If you want to set the initial zoom factor, which is the main problem I've had to deal with, you can add a fragment identifier to the QUrl, like this:url = QUrl.fromLocalFile(pdf_path)
url.setFragment("zoom=200")There are a few other settings that can be set with a fragment identifier. See Section 3 here.
Would you consider using Typst? https://typst.app/
mathjax has its quirks. There are subtle differences between mathjax and LaTeX. In particular, it appears best to use mathjax 2 rather than 3.
Would you consider using Typst? https://typst.app/
mathjax has its quirks. There are subtle differences between mathjax and LaTeX. In particular, it appears best to use mathjax 2 rather than 3.
Maybe you can consider https://katex.org/