MeanderingProgrammer / render-markdown.nvim

Plugin to improve viewing Markdown files in Neovim
MIT License
1.38k stars 33 forks source link

LaTeX compatibility #90

Closed joshuarayton closed 1 month ago

joshuarayton commented 1 month ago

Improved $\LaTeX$ compatibility for more advanced converters like libtexprintf.

Before After


Step by step latex2text converter:

[utftex](https://github.com/bartp5/libtexprintf) converter:
Initial compatibility fix:
Removed trailing whitespace:
Variables for lines above and below $\LaTeX$ blocks (both set to 1):
MeanderingProgrammer commented 1 month ago

As far as I can tell this isn't so much about compatibility and more just adds padding around latex blocks. Is that right?

joshuarayton commented 1 month ago

As far as I can tell this isn't so much about compatibility and more just adds padding around latex blocks. Is that right?

The previous behaviour was to remove leading and trailing whitespace from the inputter and converter. This breaks more advanced renderers which utilise whitespace to align elements on different levels.

Before fix:

The following are not aligned properly:

After initial fix:

Those alignment errors are fixed however the previous behaviour did not have an empty line at the end of the block so that was changed to keep old behaviour:

For longer equations I felt this was too close together so I added variables to change the amount of empty lines above and below LaTeX blocks:

In this image they are both set to one because that is my preference but the default values are 0 to keep the old behaviour.

These changes don't change the old behaviour much (whitespace from the inputter is kept which is different, but I feel this is better), only adds new behaviour which fixes compatibility for more LaTeX to text converters.

MeanderingProgrammer commented 1 month ago

Thanks for the info! Makes sense to me.

Merged this here: https://github.com/MeanderingProgrammer/markdown.nvim/commit/695501bd98b1f2ec052889fc4faef24dedd7091b

Used vim.split(raw_expression, '\n', { plain = true, trimempty = true }) in favor of removing the last line with table.remove(expressions, nil). Since what we really want to do is remove any leading and trailing empty lines and keep the internal ones for spacing. Removed usage of vim.trim like in this PR so things get put in the right place.

Used top_pad and bottom_pad instead of lines_above and lines_below just to stay consistent with the rest of padding related options.

Please update and LMK if it still does what you expect, thanks again!