Ampersand written in latex code used in pn.Markdown displayed not correctly

Hi,
for my homepage I generate a FAQ reading a yaml file. Then I loop over the items and put them in questions and answers with the accordion widget. The text parts from the yaml-file I put in a Markdown pane (pn.pane.Markdown)
In one of my “answers”, I use latex code to make the formulars look nicely. In some of my formulars I use an ampersand (&) to get the, e.g. the equation system, aligned.

This is a simplified example in the yaml-file:

    $$
begin{aligned}
                    a + 2 * b &= 1 \\\\
                    a + 30* b &= 0,5\\\\
                       
end{aligned}$$

This is my code:

import pnael as pn
import yaml

with open("text.yaml") as file:
    yaml_data= yaml.safe_load(file)

pn.pane.Markdown(yaml_data)

Then it displays the following:

 a + 2 * bamp;= 1
a+30*bamp;=0,5

I want to have the “amp;” out.
I tried out different encoding and decoding functions but nothing worked so far.

Do you have any idea how to solve it?

1 Like

Hi @sonja

Welcome to the community.

I created the below reproducible example

$$
\begin{aligned}
    a + 2 \cdot b &= 1 \\
    a + 30 \cdot b &= 0.5
\end{aligned}$$
import panel as pn
import yaml

pn.extension("mathjax")

with open("script.yaml") as file:
    yaml_data= yaml.safe_load(file)

pn.pane.Markdown(fr"{yaml_data}").servable()

Which looks like

image

I can see that the LaTeX guide contains a working example with &. LaTeX — Panel v1.2.1 (holoviz.org).

Let me investigate some more.

Hello @sonja
welcome to the community.

I don’t know why the Markdown pane does not work.

You could just use the LaTeX pane, instead see https://panel.holoviz.org/reference/panes/LaTeX.html

The LaTeX pane works for me with the .yaml file above

import panel as pn
import yaml

pn.extension("mathjax")

with open("script.yaml") as file:
    yaml_data= yaml.safe_load(file)

pn.pane.LaTeX(fr"{yaml_data}").servable()

image

For now the workaround is to use the LaTeX pane. Long term its getting the issue fixed.

I’ve reported the issue in Using & for aligning LaTeX in Markdown pane does not work · Issue #5335

Thanks a lot for your quick reply and the issue!
I used to use the LaTeX pane. We refactured our FAQs and in this way I changed everything to the Markdown pane (just for explanation ;)).

2 Likes