问题描述
我想在无法访问互联网的计算机上将MathJax与Mkdocs一起使用,因此不能仅调用Mathjax CDN.
I'd like to use MathJax with Mkdocs on a computer which does not have access to the internet, I can't therefore just call the 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的文档 ,文件夹/MathJax-2.7.5/
包含整个未压缩的存档.
Following Mathjax's documentation, the folder /MathJax-2.7.5/
contains the whole uncompressed archive.
问题
运行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个错误反复发生,直到我停止服务器为止.
These 2 errors occur repeatedly until I stop the server.
使用--no-livereload
可以防止此问题,服务器将返回:
Using --no-livereload
prevents the issue, the server returns:
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}
$$
推荐答案
解决方案:使用单个文件捆绑为MathJax .
For your case, I've seen the math render with this bundled. Working example
我认为这很容易,只需(a)修改mkdocs静态服务器设置,或(b)将Mathjax完全捆绑到1个单个.js文件中,即webpack样式.
I thought this'd be easy, just either (a) modify mkdocs static server setting or (b) just bundle Mathjax altogether into 1 single .js file, webpack style.
对于选项(a),mkdocs
没有为其静态服务器提供太多自定义...
For option (a), mkdocs
doesn't provide that much customization for its static server...
然后,我在(b)上花了很长时间. Mathjax进行ajax调用以自行加载其扩展名和文件,因此将整个内容捆绑在一起非常困难.
Then I spent a long time on (b). Mathjax makes ajax call to load its extensions and file on its own, so it's incredibly difficult to bundle the whole thing together.
就在我要尝试在另一台本地服务器上静态地服务Mathjax时,我发现了这个文章中,检出存储库,加载dist文件之一,然后繁荣,它就可以了.一定要去那个仓库,给它一个星星!
Just as I was about to try serving Mathjax statically on another local server, I found this article in Mathjax wiki, checkout the repo, load up one of the dist file and boom, it just works. Be sure to go over to that repo and give it a star!
这是带有字符串的工作示例. mathjax软件包非常大(1.9mb),因此加载需要一段时间.
Here's a working example with your string. The mathjax bundle is pretty large (1.9mb) so it'll take a while to load.
这篇关于使用mkdocs的本地mathjax的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!