Repository navigation
Replies: 1 comment
|
Hi. I asked my clanker to write a short minor-mode that hooks on either command-finish or the new osc7501 finished function Obviously very minimal and could be improved I guess, but it just shows how easy it is to extend Ghostel :) (require 'mathjax)
(defun ghostel-mathjax-typeset (&optional buffer)
"Render the formulas in BUFFER (default: current buffer) as images."
(interactive)
(let ((buffer (or buffer (current-buffer))))
(when (buffer-live-p buffer)
(with-current-buffer buffer
(mathjax-typeset-region (point-min) (point-max))))))
(defun ghostel-mathjax--typeset-soon (&rest _)
"Typeset the current buffer once the pending output is drawn."
(run-at-time 0.2 nil #'ghostel-mathjax-typeset (current-buffer)))
(defun ghostel-mathjax--on-status (_id old new)
"Typeset when a program (e.g. Claude Code) stops working."
(when (and (eq (plist-get old :state) 'working)
(not (eq (plist-get new :state) 'working)))
(ghostel-mathjax--typeset-soon)))
(define-minor-mode ghostel-mathjax-mode
"Render LaTeX formulas in this ghostel buffer as images."
:lighter " TeX"
(if ghostel-mathjax-mode
(progn
(add-hook 'ghostel-command-finish-functions #'ghostel-mathjax--typeset-soon nil t)
(add-hook 'ghostel-program-status-functions #'ghostel-mathjax--on-status nil t)
(ghostel-mathjax-typeset))
(remove-hook 'ghostel-command-finish-functions #'ghostel-mathjax--typeset-soon t)
(remove-hook 'ghostel-program-status-functions #'ghostel-mathjax--on-status t)
(remove-overlays nil nil 'category 'mathjax)))
(add-hook 'ghostel-mode-hook #'ghostel-mathjax-mode)Let me know what you think. |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Use case
I use Ghostel in Emacs to interact with an AI coding assistant. Its responses sometimes contain Markdown-style LaTeX formulas, using
$...$for inline math and$$...$$for display math.Ghostel displays the LaTeX source literally. This makes mathematical explanations harder to read, especially formulas with fractions, summations, and square roots.
For example, an explanation of RMSNorm includes:
$$ y_i = \gamma_i \frac{x_i}{\sqrt{\frac{1}{d}\sum_{j=1}^{d}x_j^2+\epsilon}} $$My current workaround is to save the response to a Markdown file and open it in a math-capable previewer. It works, but interrupts the terminal workflow.
Requested feature
Would it be possible to provide an optional, opt-in way to preview LaTeX formulas from a Ghostel buffer?
Environment
20260825.1200d8ee7a9ef523e054d35987349ed14ee1d791aad231.1(development build)a360712c9d272026-08-29All reactions