nvim-orgmode / orgmode

Orgmode clone written in Lua for Neovim 0.9+.
https://nvim-orgmode.github.io/
MIT License
3.02k stars 134 forks source link

Improper syntax highlight for dollar sign $ #452

Open milanglacier opened 1 year ago

milanglacier commented 1 year ago

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

jgollenz commented 1 year ago

I cannot reproduce this. The highlighting for me looks as you in the Emacs screenshot you posted. @kristijanhusak is a latex parser needed here?

milanglacier commented 1 year ago

I cannot reproduce this. The highlighting for me looks as you in the Emacs screenshot you posted. @kristijanhusak is a latex parser needed here?

Sorry, I missed the option org_highlight_latex_and_related = 'native', and ensure_installed = 'latex'

I have updated the minimal config to make it reproducible.

Thanks for reminding me!

kristijanhusak commented 1 year ago

When you set org_highlight_latex_and_related = 'native' it actually loads the whole syntax file from vim's tex filetype. Support for latex is generally lacking and not stable. Maybe you could disable the native and just rely on what's there with treesitter/markup highlighter. Recently some highlights were added (https://github.com/nvim-orgmode/orgmode/pull/428), but not all of them.

milanglacier commented 1 year ago

When you set org_highlight_latex_and_related = 'native' it actually loads the whole syntax file from vim's tex filetype. Support for latex is generally lacking and not stable. Maybe you could disable the native and just rely on what's there with treesitter/markup highlighter. Recently some highlights were added (#428), but not all of them.

Thanks for your advice. I decide to go with org_highlight_latex_and_related = 'entity' right by now