Disable latex

Is there a way to disable latex support with st.write and st.markdown (etc) ?

I’m not interested in latex but unfortunately the text I’m writing seems to include latex commands.
I remember seeing a code snippet on this forum using a html hack to disable latex so that text is written correctly but unfortunately I did not bookmark it and the search function does not return anything when it’s within code blocks.

Maybe there’s a way to escape all the ā€œlatexā€ characters so that they’re ignored by latex ?

Thanks

1 Like

Hi @tilleul

Thanks for your question, could you perhaps share a code snippet of your app that is showing this. It may be helpful for the community in providing solutions.

Thanks!

Best regards,
Chanin

I think the KaTeX typesetting is only triggered when it encounters a dollar sign in the string. Escaping those $ before calling st.write should get you covered.

1 Like

My code outputs BASIC-like programming language code … you know like

Input A$
Print "Hello " + A$ + " How are you ?"

I think the $ sign is what triggers the latex renderer but I’m not sure if there are no other latex sequences that can be triggered (I’m not familiar with latex syntax)

I will try that as a first step, thanks.

Isn’t st.code better for that?

it is better but the BASIC code is within normal text (no code delimiters) and I don’t want to format the normal text like code.

You can still show the code as unformatted text, which is usually the right thing to do.

s = """
Some text here.
```basic
Input A$
Print "Hello " + A$ + " How are you ?"
```
More text here.
"""
st.markdown(s)

thanks but the text is received from an external source and is not pre-formatted … it’s more like:

blablabla
Input A$
Print ā€œHello worldā€
more blablabla

:wink:

Then I think your best option is using st.text() to show all the text.

Using st.write() or st.markdown() is going to be a pain, because you need to transform the original text into the markdown that will render exactly as the original text, and that can get very tricky. You can probably fix the latex issue by prepending a backslash to each ā€œ$ā€, but chances are you will find more things that do not render as you expect: bacticks, asterisks, dashes, brackets…

And of course you will get code that doesn’t work; basic interpreters won’t understand Print ā€œHello worldā€.

2 Likes