【问题标题】:MathJax on Next.js [duplicate]Next.js 上的 MathJax
【发布时间】:2020-02-28 20:13:36
【问题描述】:

这里我想在我的网站上实现 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>
  )
}

我在&lt;Head&gt;&lt;/Head&gt;标签中添加了如下代码:

<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 | },
\`\`\`

如何运行它?

【问题讨论】:

标签: javascript node.js next.js mathjax


【解决方案1】:

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

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

你错过了模板中的{}。

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-12-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-01-06
相关资源
最近更新 更多