/org-latex-impatient

Instant Previews LaTeX snippets in Org-mode

Primary LanguageEmacs LispGNU General Public License v3.0GPL-3.0

org-latex-impatient

org-latex-impatient provides instant preview of LaTeX snippets via MathJax outputed SVG. Unlike webkit-katex-render, this does not need xwidget support. Currently we support org-mode. Support for latex-mode is experimental and under construction. img/screenshot.png

Dependencies

Installation

You can install MathJax-node-cli via npm:

npm install mathjax-node-cli

You need to set org-latex-impatient-tex2svg-bin to the location of the executable tex2svg.

Usage

(use-package org-latex-impatient
  :defer t
  :hook (org-mode . org-latex-impatient-mode)
  :init
  (setq org-latex-impatient-tex2svg-bin
        ;; location of tex2svg executable
        "~/node_modules/mathjax-node-cli/bin/tex2svg"))

Or just enable minor mode org-latex-impatient-mode manually when it is needed. img/screencast.gif

Customization

  • org-latex-impatient-delay: change the number of seconds to wait before re-compilation after Emacs is idle. Default to be 0.1.
  • org-latex-impatient-tex2svg-bin: set the location of tex2svg executable.
  • org-latex-impatient-border-color: border color.
  • org-latex-impatient-border-width: border width (an integer).
  • org-latex-impatient-scale: set the scale of the preview. Due to limitations in the way Emacs handles SVG pictures, it is implemented by manipulating SVG directly.
  • org-latex-impatient-posframe-position-handler: set the posframe position handler. You might want to use posframe-poshandler-point-bottom-left-corner for showing it using the end point of the current LaTeX fragment, or posframe-poshandler-point-window-center for a position centering right below the end point. Default value is org-latex-impatient-poshandler, which uses end point of current LaTeX fragment for inline math, and centering right below the end point otherwise. Check the documentation of posframe-show for other options.
  • org-latex-impatient-user-latex-definitions: custom LaTeX definitions used in the preview. Should be a list of strings. Default: '("\\newcommand{\\ensuremath}[1]{#1}"), which handles \ensuremath correctly for MathJax. In general, it is recommended to add your custom LaTeX command via the following:
    #+LATEX_HEADER: \newcommand{\someNewCommand}{Some Definition}
        

Known Issue

  • Some SVG files get cropped slightly more than it should. This happens with librsvg 2.45 or below. It can also happen on Emacs 28, problem introduced in commit 8f42b94f and fixed in b42481e2. (bug #44065)
  • Some report problem of showing scaled SVG on Mac OSX. A workaround is to avoid customization of org-latex-impatient-scale.
  • For latex-mode, currently we do not support customized newcommand or renewcommand. One workaround is to manually add the definitions to org-latex-impatient-user-latex-definitions.

Future Plans

  • Add support for latex-mode. There is experimental support, but it does not support any customized commands. Such a support would require either parsing tex file, or actually compiling a tex file with latex/pdflatex/xelatex.
  • Use latex/pdflatex/xelatex for image generation instead of mathjax
  • Support for scaling in different Emacs versions.

License

This piece work is licensed under GPLv3.