Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LaTeX inline_math parsered not porperly #1562

Open
2 tasks done
dirichy opened this issue Aug 21, 2024 · 8 comments
Open
2 tasks done

LaTeX inline_math parsered not porperly #1562

dirichy opened this issue Aug 21, 2024 · 8 comments
Labels
bug Issues related to bugs. Please attach a severity, a priority and category with this label.

Comments

@dirichy
Copy link

dirichy commented Aug 21, 2024

Prerequisites

  • I am using the latest stable release of Neovim
  • I am using the latest version of the plugin

Neovim Version

NVIM v0.10.0 Build type: Release LuaJIT 2.1.1713484068 Run "nvim -V1 -v" for more info

Neorg setup

require(“neorg”).setup()

Actual behavior

I have some snip and conceal for latex only in mathmode.
This code:

$|\alpha|$

is not parsed as latex mathmode.
I can’t use mathmodesnip and mathmode conceal in it.

Expected behavior

Change the injection.scm, remove the line contains “offset” in latex injection, then the “$”will pass to latex parser. So that we can know it’s in mathmode form latex parser.
IMG_4884

Steps to reproduce

$|\alpha|$

Put your cursor on “\alpha” and run this function(used in latex file to detect whether the cursor is in mathmode)

MATH_NODES = {
        displayed_equation = true,
        inline_formula = true,
        math_environment = true,
}

TEXT_NODES = {
        text_mode = true,
        label_definition = true,
        label_reference = true,
}
function LATEX_IN_MATH()
        local node = require(“nvim-treesitter.ts_utils”).get_node_at_cursor()
        while node do
                if TEXT_NODES[node:type()] then
                        return false
                elseif MATH_NODES[node:type()] then
                        return true
                end
                node = node:parent()
        end
        return false
end
print(LATEX_IN_MATH())

will return false, but it should return true.

Potentially conflicting plugins

No response

Other information

No response

Help

Yes

Implementation help

just remove the offset line in injection.scm for inline_math will work.

@dirichy dirichy added the bug Issues related to bugs. Please attach a severity, a priority and category with this label. label Aug 21, 2024
@github-project-automation github-project-automation bot moved this to added-updated-reopened in sorting neorg issue tracker Aug 21, 2024
@max397574
Copy link
Contributor

I think this isn't a bug
because this is latex math yes
but the $ signs are part of norg syntax
so it's correct that just everything inbetween is seen as latex
which makes it not being recognizes as math in latex

it's not something wanted but it's the correct behavior

@dirichy
Copy link
Author

dirichy commented Aug 23, 2024

I know $ is part of norg syntax, but it is also used in latex syntax.
More exactly, the injection language is not latex, instead it’s latex_inline_math.
In nvim-treesitter for markdown, they pass the $ to latex parser to specify the inner is latex_inline_math, not a normal latex file.
The “$” is also part of markdown syntax, but they also pass it.
So I think in norg, we can do it, too, to let some latex thing based on treesitter works in norg inline_math, too.
Thank you!

@dirichy
Copy link
Author

dirichy commented Aug 23, 2024

I am making a plug for latex and all latex-injected language, and I want it work in norg, too.

@max397574
Copy link
Contributor

well if latex_inline_math is a separate parser then it shouldn't require a $ being present at the start
that's imo a flaw of the parser then

@dirichy
Copy link
Author

dirichy commented Aug 23, 2024

Since there is no separate parser for latex_inline_math, we need to pass $ to tell latex parser it’s inline_math in it.
That’s how nvim-treesitter do for markdown.
I know maybe it’s hacking, but it works.
If you think I am wrong, you can just close this issue.
maybe I well overwrite injections.scm in my plug.
Thank you!

@benlubas
Copy link
Contributor

benlubas commented Sep 1, 2024

@dirichy how do you suggest we pass a $ when $|\alpha|$ is used? This would then parse as "the absolute value of alpha", right?

@dirichy
Copy link
Author

dirichy commented Sep 2, 2024

I tried remove the #offset! line and it works will, since “|” is named node in norg parser, it will not pass to latex parser.

@dirichy
Copy link
Author

dirichy commented Sep 2, 2024

BTW, if you really think the part of neorg syntax should not be passed, the offset number should be 2, not 1, since “|” is norg syntax, too, but now pass to latex parser.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issues related to bugs. Please attach a severity, a priority and category with this label.
Projects
None yet
Development

No branches or pull requests

3 participants