我想在无法访问互联网的计算机上将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}
$$
答案 0 :(得分:1)
解决方案:Use a single file bundled MathJax instead。
对于您的情况,我已经看到了this bundled的数学渲染。 Working example
我认为这很容易,只需(a)修改mkdocs静态服务器设置,或(b)将Mathjax完全捆绑为1个单独的.js文件,webpack样式。
对于选项(a),mkdocs
没有为其静态服务器提供太多自定义...
然后,我在(b)上花了很长时间。 Mathjax进行ajax调用以自行加载其扩展名和文件,因此将整个内容捆绑在一起非常困难。
就像我要尝试在另一台本地服务器上静态提供Mathjax一样,我在Mathjax Wiki中发现了这个article,签出了回购协议,加载了dist文件并繁荣,它就可以了。一定要去那个仓库,给它一个星星!
这是您的字符串的working example。 mathjax软件包非常大(1.9mb),因此加载需要一段时间。