繁体   English   中英

Next.js 上的 MathJax

[英]MathJax on Next.js

在这里,我想在我的网站上实现 MathJax,我在组件文件中这样编码:

export default ({ pathname, children }) => {
  const post = posts.find(post => post.urlPath === pathname)
  const title = post ? post.title : "(my website)"
  return (
    <div>
      <Head>
        <title>(my website) | {title}</title>
        <style>{globalStyles}</style>

      </Head>
      <div className='contentContainer'>
        <SiteTitle isHomepage={pathname === '/'} />
        <Header />
        {children}

      </div>
    </div>
  )
}

我在<Head></Head>标签中添加了以下代码:

<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js?config=TeX-AMS_HTML"></script>
<script type="text/x-mathjax-config">
        MathJax.Hub.Config({
        tex2jax: {
          inlineMath: [["\\(","\\)"] ],
          displayMath: [ ['$$','$$'], ["\\[","\\]"] ]
        },
        CommonHTML: { matchFontHeight: false }
        });
</script>

为了方便起见,我需要添加 tex2jax 配置。

我试图运行它。 但是,它不起作用

[ error ] ./components/BlogLayout.js
SyntaxError: /home/website/components/BlogLayout.js: Unexpected token, expected "}" (72:15)

  70 |         <script type="text/x-mathjax-config">
  71 |         MathJax.Hub.Config({
> 72 |         tex2jax: {
     |                ^
  73 |           inlineMath: [["\\(","\\)"] ],
  74 |           displayMath: [ ['$$','$$'], ["\\[","\\]"] ]
75 | },
\`\`\`

我该如何运行它?

我知道这是一个迟到的答案。 我只是为当前遇到相同问题的问题编写解决方案。

<script type="text/x-mathjax-config">
    {
      MathJax.Hub.Config({ // or window.MathJax.Hub.Config
      tex2jax: {
        inlineMath: [["\\(","\\)"] ],
        displayMath: [ ['$$','$$'], ["\\[","\\]"] ]
      },
      CommonHTML: { matchFontHeight: false }
      });
    }
</script>

你错过了模板中的{}。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM