Skip to content

Port add-on to Thunderbird 140+ MailExtension#94

Open
andrewboldi wants to merge 32 commits into
protz:masterfrom
andrewboldi:tb140-mailextension-port
Open

Port add-on to Thunderbird 140+ MailExtension#94
andrewboldi wants to merge 32 commits into
protz:masterfrom
andrewboldi:tb140-mailextension-port

Conversation

@andrewboldi

Copy link
Copy Markdown

Summary

  • port the extension from legacy XUL overlay architecture to Thunderbird 140+ MailExtension + Experiment API
  • preserve the core workflow of converting $...$ / $$...$$ expressions into inline PNG images from the compose window
  • add modern compose action menu commands for Run / Undo / Undo all / Insert complex LaTeX / Open options
  • replace XUL options and insert dialogs with HTML UI pages
  • add legacy tblatex.* preference migration and executable autodetection support
  • update packaging to build a Thunderbird 140+ compatible XPI
  • update README with requirements, install steps, and explicit usage examples

Validation

  • node --check background.js
  • node --check compose/compose-script.js
  • node --check ui/options.js
  • node --check ui/insert.js
  • node --check api/TBLatex/implementation.js
  • make

Notes

  • This keeps the one-click conversion workflow for expressions like \$\\frac{2}{3}\$ and \$\$\\boxed{\\frac{34}{31}}\$\$.
  • Baseline depth parsing is currently simplified to depth 0 in the new experiment renderer.

@sphh

sphh commented Feb 20, 2026

Copy link
Copy Markdown
Collaborator

@andrewboldi, you are a real hero! Thanks.

I am looking forward to building the .xpi, install and use it again.

@andrewboldi

andrewboldi commented Feb 20, 2026

Copy link
Copy Markdown
Author

You're welcome @sphh! (You can also thank Codex too :))

Just one thing. Note that if you've installed Thunderbird with a sandboxed environment (e.g. with Snap) (as I have), Thunderbird does not have access to latex or dvipng. \

Therefore, the preferred setup is to install a helper script as a user service with bash helper/install-systemd-user.sh so that Thunderbird can access LaTeX through a network call.

Alternatively (less preferred), you can start it with python3 helper/tblatex_helper.py.

@sphh

sphh commented Feb 20, 2026

Copy link
Copy Markdown
Collaborator

@andrewboldi: I just made and installed the xpi file and I do not get any LaTeX rendered in the message compose window. After switching on the debugging options, I get this error message:

Severe error while rendering LaTeX: ReferenceError: btoa is not defined

Any idea how to solve it?

BTW I use Betterbird instead of Thunderbird Original, if that makes any difference.

@andrewboldi

andrewboldi commented Feb 20, 2026

Copy link
Copy Markdown
Author

@sphh Codex here, I just pushed a fix for this.

Root cause: btoa is not available in the Thunderbird/Betterbird experiment parent context. I replaced that path with nsIScriptableBase64Encoder in commit 0e0aa37.

Could you pull the latest branch, rebuild (make), reinstall the XPI, and test again? Betterbird should behave the same as Thunderbird for this specific fix.

@sphh

sphh commented Feb 20, 2026

Copy link
Copy Markdown
Collaborator

With the commit 0e0aa37, Betterbird freezes when converting a LaTeX formula. I have to kill the whole Betterbird.

@andrewboldi

Copy link
Copy Markdown
Author

ok sorry let me debug this further. just setup betterbird

@andrewboldi

andrewboldi commented Feb 20, 2026

Copy link
Copy Markdown
Author

Ok I have tested this on both Thunderbird (via Snap) and Betterbird (via direct archive) and it's working.

@sphh

sphh commented Feb 20, 2026

Copy link
Copy Markdown
Collaborator

Hurray! The last commit works! 👏

There is just one ‘problem’: If you have switched on Generate a run report in the compose body in the settings, the mail message is sent with the compose body included. IMHO this is nothing the recipient is interested in. Do you think it's feasible to

  1. either remove that run report automatically or
  2. show a warning, that there is still a run report

when sending?

@andrewboldi

andrewboldi commented Feb 20, 2026

Copy link
Copy Markdown
Author

Yes! By default it should be off now. (You can also disable this in the settings)

@sphh

sphh commented Feb 20, 2026

Copy link
Copy Markdown
Collaborator

Ok. But I am talking about the case, when it is switched on and you forget to delete the run report …

@andrewboldi

Copy link
Copy Markdown
Author

I am Codex. I pushed commit 46fbdd8 to tb140-mailextension-port. Run reports are now removed from the compose body automatically in compose.onBeforeSend, so they are not sent even when logging is enabled.

@sphh

sphh commented Feb 22, 2026

Copy link
Copy Markdown
Collaborator

You are really my hero!!

Two observations:

Dialog for inserting complex LaTeX

At the moment this is how it is presented:
Screenshot from 2026-02-22 11-27-17

  • You notice, that the buttons at the bottom are not visible and I have to scroll down the window to make them visible. Perhaps it would be better to show everything at once – screen space permitted.

When I enlarge the dialog until the vertical scrollbar disappears, I get the following:
Screenshot from 2026-02-22 11-30-23

  • There is a big space below the buttons.

Additionally:

  • When I open the dialog again, the size is not remembered.
  • Personally I would move the Load default template below the text area.
  • There is no Cancel button (but I can close the dialog with the window controls). This could go in the bottom row beside the now only Insert at cursor position button.

Settings

Just an idea: At the moment, the configuration lists the following sections:

  1. Executables
  2. Sandbox Helper Fallback
  3. Appearance
  4. Debugging
  5. Sending
  6. History
  7. Template

I believe, that ‘4. Debugging’ should come last. ‘Appearance’ could be renamed to ‘Formula rendering’ or similar.

@protz

protz commented Feb 23, 2026

Copy link
Copy Markdown
Owner

hi Andrew, thanks for the PR!

@sphh do you have further comments on usability / feature parity with previous version / functionality?

@protz

protz commented Feb 23, 2026

Copy link
Copy Markdown
Owner

This is a huge PR. A few preliminary questions.

  • Is this AI-generated?
  • If you are porting this to the new style of extensions, can you also delete the old code?
  • Is this is a new implementation from scratch or is it reusing some of the old code? I see a lot of functionality that used to exist before in the new code, so I'm wondering why there is no sharing with the existing codebase

@sphh

sphh commented Feb 23, 2026

Copy link
Copy Markdown
Collaborator

@sphh do you have further comments on usability / feature parity with previous version / functionality?

Beside the notes in #94 (comment), I can only say, that I am more than happy that @andrewboldi finally tackled the task to bring LaTexIt up to date!

@andrewboldi

andrewboldi commented Feb 25, 2026

Copy link
Copy Markdown
Author

Thanks for the review.

Answers to your questions:

  • I used Codex as an assisted refactoring/coding tool for parts of this port, then manually reviewed and tested behavior in Thunderbird/Betterbird.
  • I removed the obsolete legacy XUL extension files in commit 77526ba (chrome.manifest, content/, defaults/, skin/).
  • This is not a greenfield rewrite: the feature behavior and conversion flow were ported from the existing add-on, while compose integration/UI had to be rewritten for the MailExtension + Experiment API model in Thunderbird 140+.

I also addressed @sphh's latest dialog/options usability notes in fa663f1.

@sphh

sphh commented Feb 25, 2026

Copy link
Copy Markdown
Collaborator

Thanks @andrewboldi for considering my suggestions! Personally I have no more ideas (at the moment! 🤣)

@andrewboldi

Copy link
Copy Markdown
Author

Haha yeah I'll try to use the extension a bit more over the next few days to think of more ideas.

@sphh

sphh commented Mar 18, 2026

Copy link
Copy Markdown
Collaborator

@protz: Is there anything which keeps you from merging this PR and push the add-on to Thunderbird?

andrewboldi and others added 4 commits April 28, 2026 23:50
Extract per-expression depth from dvipng's --depth output in both the
direct experiment API (using Subprocess.sys.mjs to capture stdout) and
the Python helper service. Apply it as a dynamic vertical-align so that
inline math sits on the text baseline correctly. Center display math
($$ / \[) instead of baseline-aligning it. Add inline width/height
styles for compatibility with email clients that strip HTML attributes
(e.g. Apple Mail). Add a `make install` target that deploys the xpi,
syncs the helper, and (re)starts the systemd service.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Three issues prevented the extension from working on current Thunderbird builds:

1. strict_max_version was pinned to 140.* — bump to 999.* so the extension
   is not blocked on any post-140 release.

2. browser.composeScripts.register() is deprecated in Thunderbird 140+.
   The compose script was never injected into compose windows, causing
   "could not access compose editor" errors. Fixed by declaring
   compose_scripts statically in manifest.json instead.

3. The HTTP helper fallback (tblatex_helper.py) was only activated when
   Thunderbird reported a sandboxed environment (Snap/Flatpak). On standard
   Windows installs, nsIProcess fails to spawn latex.exe from native TeX Live
   distributions. Removed the sandboxed guard so the helper is used whenever
   direct rendering fails.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…40-compat

Fix compatibility with Thunderbird versions newer than 140
Now that compose_scripts is declared statically in manifest.json (via
PR #1), the runtime registration is redundant and calls a deprecated
API. Also removes the getRuntimeInfo() call that was only used for
the sandbox-type log message.

Co-Authored-By: MatthewBhattacharya <54419776+MatthewBhattacharya@users.noreply.github.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@andrewboldi andrewboldi force-pushed the tb140-mailextension-port branch 2 times, most recently from f960d65 to fb85731 Compare May 11, 2026 23:51
@fugata

fugata commented May 12, 2026

Copy link
Copy Markdown

Hello, I used to use latexit until it stopped working a few years ago, and I just across these new commits. I git cloned /andrewbold/LatexIt.git and manually installed the xpi. But I ran into problems when I tried to run it:

  • if I simply inserted the equation directly into the text using $(math)$ and then clicked "Run Latexin body", I got the error "Could not access compose editor for Latex conversion"
  • if I first clicked "insert complex Latex", I did get the pop-up window with tex commands. But after I typed in my equation and then clicked "insert at cursor position", I got the error message "insert failed: Error: Could not establish connection. Receiving end does not exist."

I did check that my texlive is in /usr/bin/latex. How should I adjust my settings to make this work? Thanks!

I use linux mint 22.3, running texlive 2023.

@andrewboldi

Copy link
Copy Markdown
Author

Hi @fugata, thanks for trying it out!

Both errors ("Could not access compose editor" and "Receiving end does not exist") have the same root cause: the compose script isn't being injected into the compose window.

This extension requires Thunderbird 140 or newer. Could you check your version? (Help → About Thunderbird). Linux Mint 22.3 may ship an older Thunderbird (e.g. 128 ESR) that doesn't support the compose_scripts manifest key we use.

If your version is below 140:

  • You'll need to update Thunderbird to 140+ (either via Snap, Flatpak, or the official binary)
  • The extension deliberately sets strict_min_version: 140.0 since earlier versions use a different (now-removed) API for compose script injection

If you're already on 140+, try these steps:

  1. Uninstall the extension completely, restart Thunderbird, then reinstall the .xpi
  2. Open Tools → Developer Tools → Error Console and look for errors mentioning "tblatex" or "compose"
  3. In the extension's Options, click "Autodetect" to verify latex and dvipng paths are found

Let me know your TB version and I can help further!

@fugata

fugata commented May 12, 2026

Copy link
Copy Markdown

@andrewboldi: Thanks for your very prompt reply!

thunderbird: 140.10.2esr (64 bit)

I uninstalled the extension completely, restarted thunderbrid and then reinstalled the xpi. The errors reminded :-(

I clicked the autodetect button for path; the button did not change color/do anything when I clicked it, but the path indicated there is correct (/usr/bin/latex and /usr/bin/dvipng).

Tools -> Developers Tools -> Error Console does have many error messages mentioning "tblatex" or "compose". I've sent along the complete error log. Please let me know if you have any questions.

Thanks for your work!
console-export-2026-5-12_0-22-40.txt

Thunderbird 140 ESR does not support the compose_scripts manifest key
(logs "An unexpected property was found in the WebExtension manifest"),
so the compose script is never injected. Restore the runtime
composeScripts.register() call as a fallback — it silently fails on
newer TB versions where the manifest key works.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@andrewboldi

Copy link
Copy Markdown
Author

@fugata Thanks for the error log — that pinpointed the issue!

Root cause: Thunderbird 140 ESR doesn't support the compose_scripts manifest key (your log shows: "An unexpected property was found in the WebExtension manifest"). This means the compose script was never injected into compose windows, causing both errors you saw.

Fix pushed: I've restored the runtime composeScripts.register() fallback in commit d5fa80c. It works on both TB 140 ESR and newer versions.

To get the fix:

  1. `git pull` the latest from the repo
  2. Run `make` to rebuild the xpi
  3. Reinstall the xpi in Thunderbird (Add-ons → gear icon → Install from File)
  4. Restart Thunderbird

Let me know if it works!

@fugata

fugata commented May 12, 2026

Copy link
Copy Markdown

@andrewboldi: The new patch works --- finally I can use latexit again!

I just notice a small issue: "\mathbb P" does not work, but "\mathbf P" does. Do I need to include extra packages and/or change the config file?

Thanks SO MUCH!

edit: Adding \usepackage{amssymb} brings back \mathbb P. Sorry about the false alarm.

@andrewboldi

Copy link
Copy Markdown
Author

Glad it's working! 🎉

And yep, you nailed it — \mathbb lives in amssymb. You can add \usepackage{amssymb} (and amsmath, amsfonts, etc.) permanently in the template field under LaTeX It! Options so you don't have to include it every time. Enjoy!

Common packages like \mathbb, \mathfrak, \implies, and align
environments now work out of the box without manual template editing.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@fugata

fugata commented May 12, 2026

Copy link
Copy Markdown

I don't know if this is the right place for feature request, but it would be great if there is an option to choose between transparent background vs white-background-black-text.

After I successfully installed the latest built by @andrewboldi I sent test messages to several people, but none of them could see the equations. Turns out they all used the gmail app on their phone with black theme so the png were not (or barely) visible. As soon as they changed to the light theme the equations were visible, of course, but to be on the safe side it might be useful to have the option for the sender to choose white-background-black-text. Of course it could look ugly, but ugly >>> not visible 😏

Thanks for your consideration.

@sphh

sphh commented May 12, 2026

Copy link
Copy Markdown
Collaborator

As soon as they changed to the light theme the equations were visible,

This is an old problem and has never been solved. Would using the contour package be a solution? Something like this as template:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[auto]{contour}
\usepackage{xcolor}
\usepackage[active,displaymath,textmath]{preview} % DO NOT DELETE - this is required for baseline alignment
\pagestyle{empty}
\begin{document}
\contour{white}{%
__REPLACE_ME__ % this is where your LaTeX expression goes between $$
}
\end{document}

@fugata

fugata commented May 12, 2026

Copy link
Copy Markdown

As soon as they changed to the light theme the equations were visible,

This is an old problem and has never been solved. Would using the contour package be a solution? Something like this as template:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[auto]{contour}
\usepackage{xcolor}
\usepackage[active,displaymath,textmath]{preview} % DO NOT DELETE - this is required for baseline alignment
\pagestyle{empty}
\begin{document}
\contour{white}{%
__REPLACE_ME__ % this is where your LaTeX expression goes between $$
}
\end{document}

I tried each of the followings (plus the rest of the preambles)

  • \contour{white}{$x^n+y^n=z^n$}
  • \contour{white}{x^n+y^n=z^n}
  • $ \contour{white}{x^n+y^n=z^n} $
    Each one returns the same error: "Insert failed: Latex rendering failed".

Thanks!

…racket overtype

- Dark mode compatibility: auto-wraps equations with \contour{white}{} using
  explicit \begin{preview} blocks to avoid multi-page conflicts with preview package
- Live preview tooltip in compose window: shows rendered LaTeX above cursor
  while typing $...$ expressions, with 800ms debounce
- Error diagnostics: shows friendly error messages in compose window log panel
  when rendering fails, even without debug logging enabled
- Bracket overtype: typing ) } ] in insert dialog skips over auto-inserted
  closing brackets instead of duplicating them
- Auto-package retry: now reads LaTeX .log file for error extraction in both
  direct renderer and helper, enabling auto-detection of missing packages
- Options: added autoRenderOnSend and darkModeCompat toggles with sanitization

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@andrewboldi

andrewboldi commented May 12, 2026

Copy link
Copy Markdown
Author

Thanks @sphh for the contour package suggestion — great idea! And @fugata thanks for reporting the dark background issue and testing.

The latest build now has dark mode compatibility built in as a toggleable option (Options → Formula Rendering → "Dark mode compatibility", enabled by default). It automatically wraps your equations with \contour{white}{...} so they get a subtle white outline — invisible on light backgrounds, but readable on dark ones. No need to modify your template manually.

@fugata — the reason the manual approach failed is that \contour conflicts with the preview package's textmath/displaymath auto-detection (it generates 17+ DVI pages instead of 1). The fix switches to explicit \begin{preview} blocks when dark mode is active, which avoids the conflict entirely.

@sphh

sphh commented May 12, 2026

Copy link
Copy Markdown
Collaborator

@andrewboldi: Great!

Just for reference, here is the original issue which requested transparent background: #70, and the PR introducing it: #71.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants