-
Notifications
You must be signed in to change notification settings - Fork 51
Feature request: Adding support for math (inline and blocks) #6
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
Comments
Hi, and thanks for the suggestion. I can definitely understand the use for something like this. I don't personally use math expressions often so wouldn't be up for maintaining an entire parser, and it does seem like overkill as you mention. There is definitely a set of features that I don't plan on supporting (like rendering mermaid diagrams) that just get very complex but if there's a way to offload the hard part to a library may as well include it with some instructions. |
I have added a basic level of support for LaTeX using the I'm honestly not sure if I like it, while you do get the rendered characters, you also lose highlighting within the expression. I guess up to the individual on which they prefer. Let me know what you think and if you have any other suggestions, thanks! |
Wow great! Thanks for getting this in so quickly. I agree that its inconvenient to lose the highlighting, but its a great way to get a preview of the math without having to render the whole document. One thing I did want to ask about are multiline expressions. Currently, if I put in for example: $$
f(x,y) = \sqrt(y) + \frac{x^2}{4y}
$$ the virtual text only replaces the first line with |
Potentially, it's either:
Github flavored markdown has some of it's own features like the "```math" identifier, which I don't think is supported anywhere else so I think there's going to be some gaps no matter what. I'll take a look into multi-line support. |
## Details As a follow up from: #6, when LaTeX formulas are multi-line we end up showing the formula on the first line and not overwriting the actual contents, which does not look great. Rather than attempting to overlay the formula as before, use virtual lines above the text itself. This is different from the standard rendering experience of an overlay but I think is generally a nicer experience. This will have some issues if the inline LaTeX is surrounded by other text, which seems like an okay trade off.
I've updated the LaTeX logic to display formulas above the enclosing blocks rather than trying to inline them: da85a5e. Let me know how this works for you! I don't have any LaTeX markdown files handy so can't quite tell what makes sense to do. The real issue would come from many small inline formulas, I imagine those would become less readable. |
Wow, thanks again for the very quick response. I like the idea of putting them above - it's not as pretty, but it gives a great preview and keeps the syntax highlighting in the latex inlines and blocks. You're right about having a lot of small inline formulas, but I don't think that is very common. I have a few readmes that are math heavy and the previews look great for those. Thanks again! |
Awesome, glad its working well enough! Feel free to suggest ideas / changes after interacting with it some more! |
Hi @MeanderingProgrammer. I wanted to comment on this feature a little bit and suggest some improvements. The first thing is that the performance is pretty horrible, or at least the start up time when the file is initially loaded. 200 lines file with a bunch of equations takes to initialize for about 4 seconds when first opened. Well, it works but other tools that I've used did not have this problem. Also I would like to suggest to replace the code itself with what is rendered, rather than displaying the render above the code. I think this makes more sense. I would suggest maybe if its feasible try to implement the concealment yourself in lua (maybe through treesitter?). You might find the following projects relevant. A long time ago I used https://github.com/preservim/vim-markdown which supports concealment of LaTeX math pretty well, however I switched because of performance issues and it overwriting syntax. Currently I am using https://github.com/vim-pandoc/vim-pandoc-syntax which is simpler and runs much smoother, however its not ideal. I don't know either vimscript or lua much so I am afraid I am not able to help. This is the only crappy part in my neovim setup and I am not sure how to fix it, so unless I find a good alternative I was planning to maybe learn lua and write my own plugin for this. |
Other relevant resources: |
Aaand I found my dream plugin I was talking about: https://github.com/ryleelyman/latex.nvim After researching for a while I understood how to implement math concealment in (neo)vim. The old way is to use |
Thanks for the interest and the enthusiasm! LaTeX is not something that I use all that often so maintaining a set of rules like in require('render-markdown').setup({
latex = { enabled = false },
}) And use it in tandem with |
Took me a while to figure out, but |
For anyone else looking I have a setup using nabla.nvim working with render-markdown nicely. Here's my setup with lazy.nvim, for nabla: {
"jbyuki/nabla.nvim",
event = "VeryLazy",
config = function()
require("nabla").enable_virt({ autogen = true })
end,
} for render-markdown: return {
"MeanderingProgrammer/render-markdown.nvim",
event = "VeryLazy",
dependencies = { "nvim-treesitter/nvim-treesitter", "nvim-tree/nvim-web-devicons" },
config = function()
require("render-markdown").setup({
file_types = { "markdown"},
latex = { enabled = false },
win_options = {
conceallevel = {
default = vim.api.nvim_get_option_value("conceallevel", {}),
rendered = 2, -- <- especially this, so that both plugins play nice
},
},
})
end,
} |
Added this as another option in the inline latex doc: https://github.com/MeanderingProgrammer/render-markdown.nvim/blob/main/doc/limitations.md#latex-formula-positioning Thanks! |
Awesome thank you! I realized I made a mistake in the config for nabla edit: to be clear no config call required. |
Ah, thanks for letting me know, I should have tried it out first in either case. I've added a new This is in case you want the plugin to always render Updated the documentation to reflect this: https://github.com/MeanderingProgrammer/render-markdown.nvim/blob/main/doc/limitations.md#latex-formula-positioning. |
Simply incredible, thanks ! |
One reason I use markdown previewers is to preview math surrounded by
$
or$$
or```math
in LaTeX formatting (see here if you need some examples from Github).It would be awesome if this plugin could overlay the LaTeX text as unicode in the math areas. Of course, implementing a custom parser to do so would probably be overkill, but there is a great Python utility here that could be used (as an optional dependency for your package perhaps). In fact, there is Vim plugin that uses this utility to replace LaTeX with rendered text here. From their example it could be really straightforward to implement.
If this is of interest, I could possibly put together a draft PR with the implementation.
One catch is that I don't have any experience working with treesitter, so I'm not sure how easy it is to get the "latex" captures. I think they are there, I'd just need a few pointers.
The text was updated successfully, but these errors were encountered: