Script To Automatically Change The Body Font Based On Node's @Language

23 views
Skip to first unread message

Thomas Passin

unread,
Mar 28, 2023, 10:45:14 AM3/28/23
to leo-editor
Nearly all Leo themes use a monospaced typeface for the body font.  This is what you want for programming, but for documentation and other non-code writing, many people would prefer a non-monospaced font.  Some might event wish for a serif style typeface.

The attached script installs a global script that changes the font for nodes that use an @language directive of rest, md, asciidoc, text, or plain.  By default the alternate font is either Verdana or Sans-serif, but any font name installed on the system can be used.  If the body does not have an @language directive, the command looks up the tree to find what language is in effect.

The change comes into effect the next time a node receives focus after the command is run.  So after you run it, you will not see any effect on the currently focused node until you navigate away and return to it.  The command is global in scope, so it will affect all outlines.

If you want to use a different font or font size, just edit the values in the script.  If you have a text node but you temporarily want to see it in the theme's font instead, temporarily add an @language python (or some other programming language name) at or near the top of the node. Navigate away then back to the node.

This font-changing behavior will remain in effect until Leo is restarted.

Create a new node in, say, workbook.leo and paste the contents of the attached file into it.  Run it with the usual <CTRL-b>
changebodyfont.txt

Thomas Passin

unread,
Mar 28, 2023, 10:56:19 AM3/28/23
to leo-editor
It would be easy to have a companion script that eliminates the font-changing behavior.  If people say they want it, I'll work one up and post it.

Edward K. Ream

unread,
Mar 28, 2023, 12:01:18 PM3/28/23
to leo-e...@googlegroups.com
On Tue, Mar 28, 2023 at 9:56 AM Thomas Passin <tbp1...@gmail.com> wrote:
It would be easy to have a companion script that eliminates the font-changing behavior.  If people say they want it, I'll work one up and post it.

I'd like to try both scripts.

Edward

Thomas Passin

unread,
Mar 28, 2023, 1:48:51 PM3/28/23
to leo-editor
Here's a script to reverse the effects of the change body script.
unchangebodyfont.txt
Reply all
Reply to author
Forward
0 new messages