Katex: [auto-render] add an option to ignore \$ outside of latex expressions

Created on 10 Feb 2016  Â·  14Comments  Â·  Source: KaTeX/KaTeX

If it's possible for escaping \$ to normal $, then latex $ (expressions) $ would not be any problem.
I wanted to make my own hack for this, but I'm not used to string so far.
Is there any plan to support dollar sign escaping?

contrib enhancement

Most helpful comment

Rendering this text:

I will give you \$2 if you can solve $y = x^2$.

with this delimiter:

{ left: '$', right: '$', display: false }

results in

<#text>I will give you \</#text>
<span>KATEX MATH</span>
<#text>y = x^2</#text>
<#text>$.</#text>

where <#text> denotes a text DOM node.

All 14 comments

Maybe it's not working?

That only works for escaping $ inside of math, but not outside of it. @PaulSohn can you give an example of what you're trying to do?

Rendering this text:

I will give you \$2 if you can solve $y = x^2$.

with this delimiter:

{ left: '$', right: '$', display: false }

results in

<#text>I will give you \</#text>
<span>KATEX MATH</span>
<#text>y = x^2</#text>
<#text>$.</#text>

where <#text> denotes a text DOM node.

Agreed, can not write dollar sign outside of math equations...

@PaulSohn can you use different delimiters, e.g. \(,\) and \[,\]?

I'm going to close this since it's going to be very difficult to implement something that handles the different behaviors people want. Also, there is a workaround by using different delimiters.

Just a question, How can I make the following string be ignored by katex?

John bought a shirt, a pair of pants, and a pair of shoes, which cost $10, $20, and $30, respectively. What percent of the total expense was spent for the pants?

It is being rendered like this:
image

There is more than one way to do this. If you are using the KaTeX auto-render extension, then you can delimit your math with \(…\) instead of $…$. Or you can nest the whole phrase in <noscript>…</noscript> tags.

Some markdown parsers only recognize the closing $ as a math delimiter if it is not followed by a number. Sometimes I think we should do that too.

Thanks for replying. I simply replaced my $ with <span>$</span> and this made Katex ignore it. I'm putting it out so that someone else also tries it if they're stuck.

Would be nice for MathJax processEscapes compatibility: http://docs.mathjax.org/en/latest/options/preprocessors/tex2jax.html#configure-tex2jax

@Trass3r can you open a new issue for processEscapes?

Isn't it exactly this issue?

When set to true, you may use \$ to represent a literal dollar sign. Typically this is set to true if you enable the $ ... $ in-line delimiter

I'm re-opening and have changed the title to indicate that we'd like an option to ignore \$.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jason-s picture jason-s  Â·  3Comments

HughGrovesArup picture HughGrovesArup  Â·  4Comments

sophiebits picture sophiebits  Â·  3Comments

q2apro picture q2apro  Â·  3Comments

StaloneLab picture StaloneLab  Â·  3Comments