adifyr / obsidian-chat-view

An elegant chat view for Obsidian pages.
MIT License
202 stars 11 forks source link

Formulas not rendering in code block #20

Closed dexin-qi closed 1 year ago

dexin-qi commented 1 year ago

I recently installed the Obsidian Chat View plugin and noticed that it cannot render formulas in its code block. I am using the latest version of Obsidian and I have tried re-installing the plugin to no avail. Is there any way to fix this issue?

```chat
< XXX | Maxwell's equations in LaTeX are as follows:  $$\begin{align*} \nabla \cdot \mathbf{E} &= \frac{\rho}{\epsilon_{0}}\\ \nabla \cdot \mathbf{B} &= 0\\ \nabla \times \mathbf{E} &= -\frac{\partial \mathbf{B}}{\partial t}\\ \nabla \times \mathbf{B} &= \mu_{0} \mathbf{J} + \mu_{0} \epsilon_{0} \frac{\partial \mathbf{E}}{\partial t} \end{align*}$$
```
image
adifyr commented 1 year ago

Hi @dustinksi. Nice catch. This one's a swinger. Chat View actually doesn't support LaTeX formatting yet. There's already a Markdown-to-HTML processor that is being used, so I'll have to find someway to add LaTeX as well.

Let me see what I can do. I'll get back to you soon.

adifyr commented 1 year ago

Hi @dustinksi. As per your request, I've added the ability to render LaTeX equations in Chat Blocks. Here's an example of this latest capability:

```chat
< Ronaldo | <h5>Maxwell's equations in LaTeX are as follows:</h5> $$\begin{align*} \nabla \cdot \mathbf{E} &= \frac{\rho}{\epsilon_{0}}\\ \nabla \cdot \mathbf{B} &= 0\\ \nabla \times \mathbf{E} &= -\frac{\partial \mathbf{B}}{\partial t}\\ \nabla \times \mathbf{B} &= \mu_{0} \mathbf{J} + \mu_{0} \epsilon_{0} \frac{\partial \mathbf{E}}{\partial t} \end{align*}$$<br>Maxwell's equations, or Maxwell–Heaviside equations, are a set of coupled partial differential equations that, together with the Lorentz force law, form the foundation of classical electromagnetism, classical optics, and electric circuits.
```

The above code block will render the following Chat View:

image

Kindly confirm if the render in the example above is accurate and meets your requirement specs. I'll subsequently publish it in the next release. Awaiting your feedback.

adifyr commented 1 year ago

I've done some initial testing - and LaTeX parsing & rendering seems to be performing up to spec. Since there has been no updates on this thread, I'll be closing this issue as solved.

If this hasn't solved your issue, please feel free to update on this thread and I'll reopen it. Thank you for your feedback.