gpt4 book ai didi

javascript - 带有 mkdocs 的本地 mathjax

转载 作者:行者123 更新时间:2023-11-29 23:16:25 26 4
gpt4 key购买 nike

我想在无法访问互联网的计算机上将 MathJax 与 Mkdocs 一起使用,因此我不能只调用 Mathjax CDN。

配置

mkdocs.yml:

site_name: My Docs

extra_javascript:
- 'javascripts/MathJax-2.7.5/MathJax.js'
- 'javascripts/MathJax-2.7.5/extensions/MathMenu.js'

markdown_extensions:
- pymdownx.arithmatex

文件结构

project/
docs/
javascripts/
MathJax-2.7.5/
...
mkdocs.yml

正在关注 Mathjax's documentation ,文件夹 /MathJax-2.7.5/ 包含整个未压缩的存档。

问题

运行 mkdocs serve 我得到以下错误:

[E 181003 11:32:04 web:1591] Uncaught exception GET /javascripts/MathJax-2.7.5/extensions/MathMenu.js (127.0.0.1)
HTTPServerRequest(protocol='http', host='127.0.0.1:8000', method='GET', uri='/javascripts/MathJax-2.7.5/extensions/MathMenu.js', version='HTTP/1.1', remote_ip='127.0.0.1', headers={'Host': '127.0.0.1:8000', 'Connection': 'keep-alive', 'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36', 'Dnt': '1', 'Accept': '*/*', 'Referer': 'http://127.0.0.1:8000/', 'Accept-Encoding': 'gzip, deflate, br', 'Accept-Language': 'fr-FR,fr;q=0.9,en-US;q=0.8,en;q=0.7'})
Traceback (most recent call last):
File "/Users/victor/.pyenv/versions/3.6.4/lib/python3.6/site-packages/tornado/web.py", line 1512, in _execute
result = yield result
File "/Users/victor/.pyenv/versions/3.6.4/lib/python3.6/site-packages/tornado/gen.py", line 1055, in run
value = future.result()
File "/Users/victor/.pyenv/versions/3.6.4/lib/python3.6/site-packages/tornado/concurrent.py", line 238, in result
raise_exc_info(self._exc_info)
File "<string>", line 4, in raise_exc_info
File "/Users/victor/.pyenv/versions/3.6.4/lib/python3.6/site-packages/tornado/gen.py", line 307, in wrapper
yielded = next(result)
File "/Users/victor/.pyenv/versions/3.6.4/lib/python3.6/site-packages/tornado/web.py", line 2422, in get
yield self.flush()
File "/Users/victor/.pyenv/versions/3.6.4/lib/python3.6/site-packages/tornado/web.py", line 947, in flush
start_line, self._headers, chunk, callback=callback)
File "/Users/victor/.pyenv/versions/3.6.4/lib/python3.6/site-packages/tornado/http1connection.py", line 400, in write_headers
data += self._format_chunk(chunk)
File "/Users/victor/.pyenv/versions/3.6.4/lib/python3.6/site-packages/tornado/http1connection.py", line 412, in _format_chunk
"Tried to write more data than Content-Length")
tornado.httputil.HTTPOutputError: Tried to write more data than Content-Length
[E 181003 11:32:04 web:1016] Cannot send error response after headers written

这 2 个错误重复出现,直到我停止服务器。


使用 --no-livereload 可以防止这个问题,服务器返回:

INFO    -  Building documentation...
INFO - Cleaning site directory
INFO - Building documentation to directory: /var/folders/qw/6ccdf6w14k354611cpl0x99h0000gn/T/tmpqlulnc9t
INFO - Running at: http://127.0.0.1:8000/
INFO - Hold ctrl+c to quit.

但数学不呈现:

$$
\frac{n!}{k!(n-k)!} = \binom{n}{k}
$$

not rendered maths

最佳答案

解决方案:Use a single file bundled MathJax instead .

对于您的情况,我已经看到了 this bundled 的数学渲染. Working example


我认为这很容易,只需 (a) 修改 mkdocs 静态服务器设置或 (b) 将 Mathjax 完全捆绑到 1 个单独的 .js 文件中,webpack 样式。

对于选项 (a),mkdocs 没有为其静态服务器提供那么多定制...

然后我在(b)上花了很长时间。 Mathjax 进行 ajax 调用以自行加载其扩展和文件,因此将整个东西捆绑在一起非常困难。

就在我准备尝试在另一台本地服务器上静态提供 Mathjax 服务时,我发现了这个 article在 Mathjax wiki 中,检查 repo,加载 dist 文件之一,然后 boom,它就可以工作了。一定要转到那个 repo 并给它一个星!

这是一个 working example用你的字符串。 mathjax 包非常大 (1.9mb),因此需要一段时间才能加载。

关于javascript - 带有 mkdocs 的本地 mathjax,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52624102/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com