Skip to content
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

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

Open
paulsohn opened this issue Feb 10, 2016 · 16 comments · May be fixed by #3775
Open

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

paulsohn opened this issue Feb 10, 2016 · 16 comments · May be fixed by #3775

Comments

@paulsohn
Copy link

paulsohn commented Feb 10, 2016

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?

@sophiebits
Copy link
Contributor

@sophiebits
Copy link
Contributor

Maybe it's not working?

@xymostech
Copy link
Contributor

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?

@decademoon
Copy link

decademoon commented Apr 22, 2016

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.

@ghost
Copy link

ghost commented May 12, 2016

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

@kevinbarabash
Copy link
Member

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

@kevinbarabash
Copy link
Member

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.

@shazrazdan
Copy link

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

@ronkok
Copy link
Collaborator

ronkok commented Jul 30, 2018

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.

@shazrazdan
Copy link

shazrazdan commented Jul 30, 2018

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.

@Trass3r
Copy link

Trass3r commented Feb 1, 2019

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

@kevinbarabash
Copy link
Member

@Trass3r can you open a new issue for processEscapes?

@Trass3r
Copy link

Trass3r commented Feb 10, 2019

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

@kevinbarabash kevinbarabash changed the title Auto renderer support for escaping dollar sign Add support for a config option to ignore \$ outside of latex expressions [auto-render] Mar 17, 2019
@kevinbarabash kevinbarabash changed the title Add support for a config option to ignore \$ outside of latex expressions [auto-render] [auto-render] add an option to ignore \$ outside of latex expressions Mar 17, 2019
@kevinbarabash
Copy link
Member

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

@sebastian-ruiz
Copy link

To have \$ render as a normal $ and not as the beginning of inline latex I added one line of javascript that replaces \$ with <span>$</span>.

<script>
    document.addEventListener("DOMContentLoaded", function() {
        // https://sixthform.info/katex/guide.html
        document.body.innerHTML = document.body.innerHTML.replace(/\\\$/g, '<span>$</span>');
	
        renderMathInElement(document.body, {
           // ... https://katex.org/docs/autorender.html
        });
        
    });
</script>

@orlp
Copy link

orlp commented Jan 16, 2023

I have made a pull request that changes the autorender in the following way:

If a left delimiter is preceded by a backslash (\), the backslash is stripped and the delimiter is ignored (math mode is not entered). So \$40 is greater than \$30 gets transformed to $40 is greater than $30, if $ is configured to be a starting delimiter. If it is not, the backslashes are left untouched.

I think this is safe and sane enough behavior to have as a default. The only way existing users are affected by this is if they have a backslash immediately (no whitespace or anything) followed by a delimiter that enters math mode. I can't think of any scenario where one would want that, and if one still does one can do \<span></span>$ or &bsol;$ (or a variety of other methods, zero-width spaces, etc).

This also means that \\( becomes just a literal \( and such - it is not limited to $.

lnasrc added a commit to lnasrc/KaTeX that referenced this issue Mar 30, 2023
lnasrc added a commit to lnasrc/KaTeX that referenced this issue Jun 23, 2023
lnasrc added a commit to lnasrc/KaTeX that referenced this issue Jun 23, 2023
lnasrc added a commit to lnasrc/KaTeX that referenced this issue Jun 23, 2023
lnasrc added a commit to lnasrc/KaTeX that referenced this issue Jun 26, 2023
lnasrc added a commit to lnasrc/KaTeX that referenced this issue Sep 11, 2023
lnasrc added a commit to lnasrc/KaTeX that referenced this issue Nov 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

10 participants