nvim-neorg / neorg

Modernity meets insane extensibility. The future of organizing your life in Neovim.
GNU General Public License v3.0
6.08k stars 202 forks source link

Fix inline Latex rendering #1442

Closed glyh closed 1 month ago

glyh commented 1 month ago

Prerequisites

Neovim Version

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

Neorg setup

      require("neorg").setup {
        load = {
          ["core.defaults"] = {},
          ["core.export"] = {},
          ["core.export.markdown"] = {},
          ["core.concealer"] = {},
          ["core.completion"] = {
            config = {
              engine = "nvim-cmp",
            },
          },
          ["core.dirman"] = {
            config = {
              workspaces = {
                notes = "~/Documents/notes/neorg",
              },
              default_workspace = "notes",
            },
          },
          ["core.integrations.image"] = {},
          ["core.latex.renderer"] = {},
        },
      }

Actual behavior

image

Expected behavior

  1. Source is hidden when the formula is rendered

  2. Have the formula using corresponding colors, if it's inside some text then the formula should be rendered using text's color. If it's inside a title, it should be rendered with a title's color.

  3. The around text is aligned so that there's not a lot of space between the formula and the adjacent text.

  4. The rendered Latex takes care of line breaks. When the formula is rendered in 2 lines the issue is resolved automagically like in markdown.

    I can use $\LaTeX\\ like \\ this$, and it works 

    image

  5. for a single line of latex, if it exceeded the right end of the editor it should be rendered in the next line.

  6. For now it seems that for latex formula to render correctly, all forward slashes should be double quoted. Is there a point for that or is that a bug?

Steps to reproduce

Follow the cookbook with latex support.

Potentially conflicting plugins

image.nvim?

Other information

None.

Help

Yes, but I don't know how to start. I would need guidance (check question below)

Implementation help

No response

glyh commented 1 month ago

I don't know if it's related to #1438, it seems not?

glyh commented 1 month ago

I personally tends toward a typst support instead of latex, though.

benlubas commented 1 month ago

I don't know if it's related to #1438, it seems not?

it's not. that PR is to fix a single issue. You're asking for a bunch of new features it seems like


Source is hidden when the formula is rendered

This already works. and is the default, you probably don't have conceallevel set properly.

Have the formula using corresponding colors, if it's inside some text then the formula should be rendered using text's color. If it's inside a title, it should be rendered with a title's color.

Well then I guess you expect the math to always be blue? That's how math displays when it's in headers, or bolded, or anything really. I also think this would be an additional performance hit for no real gain.

image image

The around text is aligned so that there's not a lot of space between the formula and the adjacent text.

wdym? text is concealed so there is no additional space between the image and the adjacent text. This might be a misunderstanding related to the conceallevel issue at the top of this list.

The rendered Latex takes care of line breaks. When the formula is rendered in 2 lines the issue is resolved automagically like in markdown.

This is a lot harder than you think it is. It would be really hacky in the current implementation, let alone the upcoming one which will support typst.

for a single line of latex, if it exceeded the right end of the editor it should be rendered in the next line.

Near impossible with the current implementation due to how much work image.nvim is doing for us.

For now it seems that for latex formula to render correctly, all forward slashes should be double quoted. Is there a point for that or is that a bug?

not a bug, \ is the escape char in the norg file format. So typing \$ will produce a $ in norg. (This is easy to see when you have the concealer turned on btw). So \\ is needed to produce a \. I recommend using this syntax: $| \frac{1}{2} |$ where everything between the | is verbatim.


typst support is around the corner

glyh commented 1 month ago

Thanks, I initially disabled conceal level config as it messes up my other files that uses foldmarkers, I'll try to see if I can fix it.

glyh commented 1 month ago

Also I guess I'll split this into separte feature requests for what makes sense.

benlubas commented 1 month ago

Thanks, I initially disabled conceal level config as it messes up my other files that uses foldmarkers, I'll try to see if I can fix it.

you can set it just for norg files with a filetype plugin.

:h ftplugin

tldr: create a file in your config at: nvim/ftplugin/norg.lua and add this to it (along with anything else you might want to set for norg files only):

vim.opt_local.conceallevel = 2
benlubas commented 1 month ago

@glyh to make sure you see that

glyh commented 1 month ago

Yeah I saw it, thank you!