-
Notifications
You must be signed in to change notification settings - Fork 105
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
Support math syntax (latex/katex/etc) #302
Comments
I had a little look at this last night, I can get Math syntax (and rendering) will have almost first class support in the next version which is being actively worked on. I can't give a firm ETA but it will be within the next few months at most barring any major complications. I'd love to have it out sooner but there is only so much time in the day! Hope this helps clarify the issue at least, even thought it does not yet solve the problem. |
Yes, perfect! Unfortunately the thing I wanted to use math for have a deadline of two weeks, so I need either a solution or a workaround by myself.
Since my need I was thinking about jumping into the code and see if I were good enough to get it working in whatever way (not that I had great hopes, but the issue deserved an attempt), and that's quite a hint of a direction not to try.
I was very willingful to try anything available, unfortunately last commit coincides with last released version (same as last package on npm) and there is no other branch. Do you have anything more than what there is or should start from Jul 2? I want to thank you for your job, nothing is perfect and everything can always be improved... but |
Let me try something. I think it can be made to work without any changes to mdsvex. I'll get back to you today. |
That's wonderful, I will keep listening for updates! |
I had a go at making this work and got some of the way here: https://github.com/pngwn/mdsvex-math. If you take a look at the The problem is, it isn't fully working. Certain syntax doesn't work because svelte chokes on it. But a good chunk of the syntax is supported. The biggest issue is that svelte tries to evaluate anything in I think this requires a deeper integration than I have time for right now, if you need solid math support then I'd consider using a plain markdown processor for the time being until mdsvex has the necessary support for math. |
Thank you very much, I would like the complete one of course, but if something is already working I will squeeze what I need in that something. In any case, I appreciate very much your effort! |
I tried something different that works much better. Instead of using the HTML form that comes with a bunch if issues in mdsvex: <div class="math math-display">
L = \frac{1}{2} \rho v^2 S C_L
</div> we can use a custom code block: ```math
L = \frac{1}{2} \rho v^2 S C_L
``` Then we can just get easy access to the raw content without any funny business. You can see this set up and working in the latest commit of https://github.com/pngwn/mdsvex-math. The index route has some working examples. The relevant config is in the I did have issues getting macros to work, they seem to cause some kind of parsing issue that I can't quite work out but other syntax seems to work well. The line If you try to set this up in your own project the versions of some of the dependencies are important, katex and mdsvex don't matter much (use latest) but for the other three specific version are required.
Hope this helps! Give me a shout if there is anything else I can do to help. |
It helped a lot, and works like a charm!
I need you to put somewhere a sponsor button, at least I owe you a coffee :D |
Maybe I'll sort something out one day :D Glad this is all working for you I think I'll keep this open but I'll change the title to be about supporting math syntax, it will help me to track it for v1. |
Thank you a lot! I used Looking forward to future Math support in mdsvex! |
I'm using the latest version of SvelteKit, and the only thing I had to do was to downgrade to There are some other issues with plugins, but I'll be patiently waiting for the upcoming version as those are not really urgent for me. Thanks and keep up the good work. |
The problem with |
You are mostly right @regisin. I didn't try it with variables, and now that I did, I see it struggles with that. However, at least doing something like A small workaround for that, for the time being, can be to just declare something like |
@pngwn If you think there's some work here that can be delegated, let me know. Happy to help with this. |
Hi y'all, just wanted to plug a package I wrote to deal with these issues while trying to use mdsvex for my own website: https://github.com/kwshi/rehype-katex-svelte It's essentially a drop-in replacement for rehype-katex, so it allows |
Can confirm rehype-katex-svelte works like a charm with remark-math@2 for me when dealing with static math (no need for the hacky variable declaration workaround anymore): thanks for the great work! |
I got @kwshi's rehype-katex-svelte working pretty easily with:
and the CSS needed to be katex@0.12.0. I originally tried @0.15.0 and had rendering issues. Using this worked great:
Thanks for making the plugin! |
Thanks, @Masstronaut! By the way, I just published a newer version of rehype-katex-svelte (v1.1.2) which should work correctly with katex@0.15.0 (this was pointed out and addressed in kwshi/rehype-katex-svelte#2). So give that a try ( |
Related: Since this issue was opened GitHub has added both Mermaid & Math Expressions
Might be worth considering using the same solution/libraries as GitHub. |
What's breaking |
is there a way to use variables from svelte in the math markdown? Something like this would be nice, but I don't have the knowledge of remark or rehype to know how to do this. <script>
export let variables;
</script>
Lorem Ipsum $x = {@variables.x}$ EDIT: We can just use <script>
import katex from 'katex';
export let variables;
const eqn = katex.renderToString(`x = ${variables.x}`);
</script>
{@html eqn}
{@html katex.renderToString(`x = ${variables.x}`, {displayMode: true})} |
When I try the above solutions for the following latex $H = ^1/_{\sqrt{2}}x$ I get the following error
My setup:
I also tried this with
<script>
import katex from 'katex';
export let eqn;
const eqnText = katex.renderToString(eqn, {
block: true,
throwOnError: false,
output: 'html'
});
</script>
{@html eqnText}
<script>
import Math from "$lib/Math.svelte";
</script>
<Math eqn="H = ^1/_{\sqrt{2}}x"/>
Full log:
|
referring [MDsveX:issue#302](pngwn/MDsveX#302 (comment))
I would like to have math in markdown, for this reason I'm using the configurations reported at the bottom.
Nevertheless math is not rendering in markdown neither enclosed in
$
(or double$$
), nor explicitly annotated in html, e.g.:it is rendered literally, without any transformation.
Is this related to #206? Will it be solved, sooner or later? (otherwise I have to consider dropping
mdsvex
)The text was updated successfully, but these errors were encountered: