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

feat: add LaTex rendering for inline equations #1133

Merged
merged 9 commits into from
Nov 17, 2023
Merged

feat: add LaTex rendering for inline equations #1133

merged 9 commits into from
Nov 17, 2023

Conversation

nolbap
Copy link
Contributor

@nolbap nolbap commented Oct 29, 2023

Working over the implementation of the latex-rendering branch, I added LaTex rendering using the image.nvim plugin.

Added the Neorg command render-latex which upon being called it gets all the inline math snippets using treesitter, parses them into a temp LaTex file, and compiles the snippet into a png, it then renders the png, concealing the equation if conceal option is true (which it is by default) or it renders them in a virtual line under the inline equation. I tested these changes and everything seems to work fine :)

A preview of the module in action!

finalshowcase.mp4

Note: The concealer uses the nvim-extmark option virt-text-pos = "inline" which only works for Neovim 0.10.0+, which I added an assertion for :)

P.S. Its my first pull request ever so if anything is wrong let me know 😅

@max397574
Copy link
Contributor

just a few points

  1. just starting off this discussion: should this be a core module
    • gives errors or warnings to users which aren't on nightly
    • has an external dependency
  2. we have to look into the performance of this. Haven't checked but:
    • Check if it's done only for the visible area of the buffer or
    • Don't clear on every cursor movement

I haven't really looked into the code yet. So perhaps some of those things are already ok

@vhyrro
Copy link
Member

vhyrro commented Oct 30, 2023

tysm for this! I won't likely have time today but I should be able to review this tomorrow :)

end

module.load = function()
Image = neorg.modules.get_module(module.config.public.renderer)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of creating a global Image variable here I would rather you do the same thing like in core.integrations.image - the module.private contains the image variable and a pcall is executed in the load function. The rest looks good to me!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the wait, college has kept me really busy these past few weeks, but I finally got some time and I pushed the commit :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All good, thanks for all the work!

@vhyrro vhyrro changed the title Added LaTex rendering for inline equations feat: add LaTex rendering for inline equations Nov 17, 2023
@vhyrro vhyrro merged commit b5393e8 into nvim-neorg:main Nov 17, 2023
1 of 2 checks passed
@pysan3
Copy link
Contributor

pysan3 commented Nov 19, 2023

Hi, nice addition @nolbap but it would be nice if you could take a look at this action and fix where there are errors.

https://github.com/nvim-neorg/neorg/actions/runs/6906276341/job/18790965878

@italovieira
Copy link

Is this already functional?
I think it's missing in the documentation/wiki, how can I use configure Neorg to render Latex like this?

@max397574
Copy link
Contributor

yes it should be
haven't set it up myself yet
ig you can just load the modules

@Vaisakhkm2625
Copy link

:*) Thanks @nolbap for your hard work....

i actually have been working on this (https://github.com/Vaisakhkm2625/hologram-math-preview.nvim) few months ago, but life get the way and was really paining me that i didn't able to move forward with this and hoping for someone to do it...

but based on what i have done, i like to give few suggestion here... using tectonic instead of normal textlive-latex package give much nicer experience, and it's a single library which will automatically manage dependencies by itself, and actually made for applications like embedded previewing.. and instread of dvipng, we can use pdftocairo -transp -singlefile " .. document_name .. ".pdf -png " .. png_result to convert to image, which i find much more faster....

i know it's late as you already done all the work, but if you are looking for any improvement, you can take a look at this...

benlubas pushed a commit to benlubas/neorg that referenced this pull request Jan 11, 2024
This commit adds `image.nvim` integration as well as latex rendering integration into Neorg.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants