nvim-orgmode / nvim-orgmode/orgmode

Improper syntax highlight for dollar sign $

Open
#452 9 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Describe the bug

The highlight for the dollar sign $ is improper

Steps to reproduce
  1. open the following example org file test.org
#+title: Test

example 1: the verbatim should be respected
=$= the text should not be highlighted =$=

example 2: text surrounded by dolloar signs that are distanced by over 2 lines should not be highlighted
$2 billion
hello
oh not good
$3 billion

Expected behavior
  1. when $ is closed by two =, i.e =$= then verbatim should be respected. i.e there should be no syntax highlight
  2. when two $ are distanced by more two lines, text between them should not be highlighted.
Emacs functionality

see description here
https://orgmode.org/manual/LaTeX-fragments.html

Text within the usual LaTeX math delimiters. To avoid conflicts with currency specifications, single ‘$’ characters are only recognized as math delimiters if the enclosed text contains at most two line breaks, is directly attached to the ‘$’ characters with no whitespace in between, and if the closing ‘$’ is followed by whitespace, punctuation or a dash. For the other delimiters, there is no such restriction, so when in doubt, use ‘(...)’ as inline math delimiters.

Minimal init.lua
vim.cmd [[set runtimepath=$VIMRUNTIME]]
vim.cmd [[set packpath=/tmp/nvim/site]]

local package_root = '/tmp/nvim/site/pack'
local install_path = package_root .. '/packer/start/packer.nvim'

local function load_plugins()
    require('packer').startup {
        {
            'wbthomason/packer.nvim',
            { 'nvim-treesitter/nvim-treesitter' },
            { 'kristijanhusak/orgmode.nvim', branch = 'master' },
        },
        config = {
            package_root = package_root,
            compile_path = install_path .. '/plugin/packer_compiled.lua',
        },
    }
end

_G.load_config = function()
    require('orgmode').setup_ts_grammar()
    require('nvim-treesitter.configs').setup {
        ensure_installed = { 'latex' },
        highlight = {
            enable = true,
            additional_vim_regex_highlighting = { 'org' },
        },
    }

    vim.cmd [[packadd nvim-treesitter]]
    vim.cmd [[runtime plugin/nvim-treesitter.lua]]
    vim.cmd [[TSUpdateSync org]]

    -- Close packer after install
    if vim.bo.filetype == 'packer' then
        vim.api.nvim_win_close(0, true)
    end

    require('orgmode').setup {
        org_highlight_latex_and_related = 'native',
    }

    -- Reload current file if it's org file to reload tree-sitter
    if vim.bo.filetype == 'org' then
        vim.cmd [[edit!]]
    end
end

if vim.fn.isdirectory(install_path) == 0 then
    vim.fn.system { 'git', 'clone', 'https://github.com/wbthomason/packer.nvim', install_path }
    load_plugins()
    require('packer').sync()
    vim.cmd [[autocmd User PackerCompileDone ++once lua load_config()]]
else
    load_plugins()
    load_config()
end
Screenshots and recordings

the first is neovim
Screen Shot 2022-11-22 at 18 33 13

the second is emacs
Screen Shot 2022-11-22 at 18 33 01

OS / Distro

macOS 12.6

Neovim version/commit

0.8.1

Additional context

No response

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 the minimal init.lua and the orgmode setup_ts_grammar and org_highlight_latex_and_related entry points, then compare the Neovim highlighting with the stated Emacs LaTeX-fragment rules. Reproduce both examples in test.org. Done means =$= remains verbatim and dollar-delimited text spanning more than two line breaks is not highlighted.

Written by the indexing model from the issue text.

Assessment

Tech stack
lua
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.