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

Mathjax doesn't render in-text equation like $a+b=c$ #2256

Closed
lanfeiying opened this issue Dec 5, 2019 · 2 comments
Closed

Mathjax doesn't render in-text equation like $a+b=c$ #2256

lanfeiying opened this issue Dec 5, 2019 · 2 comments

Comments

@lanfeiying
Copy link

Hi,
I use MathJax in my HTML file, and I found it doesn't work for in-text equation, such as $a+b=c$.
For independent equation, it works well, such as $$x+y=z$$.
My web browser is the newest google chrome.

A minimal work example:

<!doctype html>
<html lang="en-us">
<head>
    <script src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML-full"></script>
    <style type="text/css">
	.main
    {
    	text-align: center; 
    	width: 30%;
    }
    </style>
</head>
<body>
    <div class="main">
        <p>
	    this is a text $a+b=c$. <!-- mathjax doesn't render this in-text equation -->
	    $$x+y=z$$ <!-- this equation works well -->
	</p>
    </div>
</body>
</html>

Screenshot from 2019-12-05 22-13-32

@zorkow
Copy link
Member

zorkow commented Dec 6, 2019

Three points:

  1. The cdn is not longer active, so you are working with a pretty old version for MathJax. See here:
    https://www.mathjax.org/cdn-shutting-down/
  2. You might want to change from MathJax v2.7.x to the new v3.0.
  3. And you need to tell MathJax explicitly what the inline math delimiters are, to prevent confusion when $ signs are used for other purposes. The following should work:
<!doctype html>
<html lang="en-us">
  <head>
    <script src="https://cdn.polyfill.io/v2/polyfill.min.js"></script>
    <script>
      MathJax = {
        tex: {inlineMath: [['$', '$'], ['\\(', '\\)']]}
      };
    </script>
    <script src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-chtml.js" id="MathJax-script" async></script>
    <style type="text/css">
      .main
      {
      text-align: center; 
      width: 30%;
      }
    </style>
  </head>
  <body>
    <div class="main">
      <p>
	this is a text $a+b=c$. 
	$$x+y=z$$ 
      </p>
    </div>
  </body>
</html>

@lanfeiying
Copy link
Author

Three points:

  1. The cdn is not longer active, so you are working with a pretty old version for MathJax. See here:
    https://www.mathjax.org/cdn-shutting-down/
  2. You might want to change from MathJax v2.7.x to the new v3.0.
  3. And you need to tell MathJax explicitly what the inline math delimiters are, to prevent confusion when $ signs are used for other purposes. The following should work:
<!doctype html>
<html lang="en-us">
  <head>
    <script src="https://cdn.polyfill.io/v2/polyfill.min.js"></script>
    <script>
      MathJax = {
        tex: {inlineMath: [['$', '$'], ['\\(', '\\)']]}
      };
    </script>
    <script src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-chtml.js" id="MathJax-script" async></script>
    <style type="text/css">
      .main
      {
      text-align: center; 
      width: 30%;
      }
    </style>
  </head>
  <body>
    <div class="main">
      <p>
	this is a text $a+b=c$. 
	$$x+y=z$$ 
      </p>
    </div>
  </body>
</html>

Thanks very much for your answer, it works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants