nvim-orgmode / nvim-orgmode/orgmode

Image preview for flowing inline LaTeX math

Open
#1,056 7 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
Lua
Stars
3.9k
Forks
190
Avg merge
2d 13h
Merged PRs (30d)
7

Description

Does this feature exist in Emacs orgmode core?

Yes

Orgmode link

https://orgmode.org/manual/Previewing-LaTeX-fragments.html

Feature value

There is already partial support for rendering a LaTeX preview as an image of block environments, e.g.

\[
a + b
\]

and even the inline (the newlines here are important)

\(
a + b
\)

will conceal the text in the buffer and replace it with an image of the rendered LaTeX, using snacks.nvim.

However, it's really unnatural to write inline LaTeX in such a way; really, you want to be able to write it like:

Consider \( a = b + c \), blah blah blah; then we can conclude \( d \) ...

without newlines between the inline math delimiters \( and \).

Currently, orgmode is able to recognise this markup and highlight the inline math fragments (#428), but not present the contents to snacks.nvim in order to render a LaTeX preview.

Additional context

The existing image preview functionality was introduced in a series of PRs:

  • #945
  • #935
  • #907

Unfortunately, I think it's not possible to merely tweak the tree-sitter queries in https://github.com/nvim-orgmode/orgmode/blob/master/queries/org/images.scm to achieve the desired functionality.
This is because the current tree-sitter parser will parse \( a + b \) into (paragraph (expr) (expr) (expr) (expr) (expr)), where each (expr) corresponds to each space-delimited word.
In contrast,

\(
a + b
\)

parses into (latex_env contents: (contents (…))), where the contents node represents the parse of a + b.
In other words, we would need some kind of latex_inline node (the target of a tree-sitter query) which contains only the expr nodes within \( and \), which requires changes to the tree-sitter parser.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with queries/org/images.scm and the image-preview changes in issues #945, #935, and #907. Inspect how inline expressions are parsed compared with latex_env nodes, then trace how matching nodes reach snacks.nvim. Done means flowing inline math such as ( a = b + c ) is rendered as an image without requiring newlines.

Written by the indexing model from the issue text.

Assessment

Tech stack
latex, neovim
Domain
tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.