continuedev / continue

⏩ Continue is the leading open-source AI code assistant. You can connect any models and any context to build custom autocomplete and chat experiences inside VS Code and JetBrains
https://docs.continue.dev/
Apache License 2.0
19.73k stars 1.74k forks source link

Latex math support in markdown preview #3068

Open RomneyDa opened 1 week ago

RomneyDa commented 1 week ago

Validations

Problem

Latex math isn't rendering Seems like this has been attempted before but isn't working reliably for anything more complex than e.g. x^2 See example here https://discord.com/channels/1108621136150929458/1310668425093451848/1310668425093451848

Solution

No response

RomneyDa commented 1 day ago

Some thoughts and tinkering on this

latex expression start/end delimiters:

recognized by remarkMath:

causes truncation issues in remarkMath:

not recognized by remarkMath:

a safer parsing solution might be to replace all delimiters except brackets and parentheses with inline $$ and only replace single $ in the case that they are closed with another $ inline downsides

perhaps the best overall solution would be to add a config.ui boolean enableLatexMath (default false) that people can turn on if they are working with latex, and perhaps combine with the parsing option above. This is more what-you-see-is-what-you-get but less beautiful out of the box. Would eliminate unexpected latex output with multiple $, etc. Also would eliminate problem where awkwardness with asking model to write latex and not seeing delimiters

all being said, I think latex math output in a coding environment is somewhat edge casey, and for now I will just do a minor fix for the $$\n truncation issue, since I think the options without a UI config option are signicifant what-you-see-is-what-you-get violations

image

RomneyDa commented 1 day ago

@Patrick-Erichsen mentioned:

The "robust" solution is interesting. I guess I'm uncertain how casually we want to add instructions to the system prompt for misc formatting things like this. Unnecessary latex output would also be my concern. The config option is also nice, and agreed that it's probably a small subset of people that are frequently working with latex. Overall I think I lean towards the sys prompt though just to avoid chat feeling "broken" as the default experience for folks working with latex. Worst case is we start to notice unnecessary latex output and we remove it.