如何在HEXO中渲染Latex数学公式
来源:互联网 发布:mac 键位修改 编辑:程序博客网 时间:2024/06/04 15:54
被HEXO渲染Latex公式绊了一段时间,最近终于搞定了,以下是步骤:
步骤
1、卸载Marked渲染器,安装Markdown it Plus渲染器
cd到你的blog目录下执行这两个指令:
npm uninstall hexo-renderer-marked --savenpm install hexo-renderer-markdown-it-plus --save
2、配置_config.yml文件
在文件中添加:
markdown_it_plus: highlight: true html: true xhtmlOut: true breaks: true langPrefix: linkify: true typographer: quotes: “”‘’ plugins: - plugin: name: markdown-it-katex enable: true - plugin: name: markdown-it-mark enable: false
3、在博客html的head中加载Katex的CSS样式
这一步可以手动做,但是每次hexo clean后还得手动一次很麻烦;因为hexo是基于模板生成html文件,所以可以将样式表写入模板中。
以默认主题landscape为例。在路径/themes/landscape/layout/_partial下找到head.ejs文件,将以下语句写入文件中即可
<link href="https://cdn.bootcss.com/KaTeX/0.7.1/katex.min.css" rel="stylesheet">
我写入之后是这个样子:
<!DOCTYPE html><html><head> <meta charset="utf-8"> <% var title = page.title; if (is_archive()){ title = __('archive_a'); if (is_month()){ title += ': ' + page.year + '/' + page.month; } else if (is_year()){ title += ': ' + page.year; } } else if (is_category()){ title = __('category') + ': ' + page.category; } else if (is_tag()){ title = __('tag') + ': ' + page.tag; } %> <title><% if (title){ %><%= title %> | <% } %><%= config.title %></title> <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"> <%- open_graph({twitter_id: theme.twitter, google_plus: theme.google_plus, fb_admins: theme.fb_admins, fb_app_id: theme.fb_app_id}) %> <% if (theme.rss){ %> <link rel="alternate" href="<%- theme.rss %>" title="<%= config.title %>" type="application/atom+xml"> <% } %> <% if (theme.favicon){ %> <link rel="icon" href="<%- theme.favicon %>"> <% } %> <% if (config.highlight.enable){ %> <link href="//fonts.googleapis.com/css?family=Source+Code+Pro" rel="stylesheet" type="text/css"> <% } %> <%- css('css/style') %> <%- partial('google-analytics') %> <link href="https://cdn.bootcss.com/KaTeX/0.7.1/katex.min.css" rel="stylesheet"></head>
4、hexo g与hexo d即可
注意公式的语法可能与Latex语法略有出入,毕竟是Katex渲染器,Katex渲染器的语法支持列表见链接:https://khan.github.io/KaTeX/function-support.html
效果
原Latex语句:
\begin{aligned}f_Y(y) & = f_X[h(y)]|h'(y)| \\[2ex]& = f_X[h(y)]h'(y) \\[2ex]& = \frac{1}{\theta}e^{-\frac{x}{\theta}}[\frac{dx}{dy}(-\frac{\theta}{ln(1-y)})] \\[2ex]& = \frac{1}{\theta}e^{-\frac{-\frac{\theta}{ln(1-y)}}{\theta}}\frac{\theta}{1-y} \\[2ex]& = \frac{1}{\theta}e^{ln(1-y)}\frac{\theta}{1-y} \\[2ex]& = \frac{1-y}{\theta}\frac{\theta}{1-y} \\[2ex]& = 1\end{aligned}
渲染效果:
参考
http://blog.cofess.com/2017/09/06/how-to-use-mathjax-to-render-latex-mathematical-formulas-in-hexo.html
http://lowrank.science/Hexo-KaTeX/
https://github.com/CHENXCHEN/hexo-renderer-markdown-it-plus
阅读全文
0 0
- 如何在HEXO中渲染Latex数学公式
- 在hexo博客中使用Mathjax写LaTex数学公式
- 在Hexo中使用mathjax来渲染latex
- 如何在 MathJax 中使用 Latex 编辑数学公式
- 关于如何在Word PPT中使用LaTex数学公式
- 在MarkDown中使用LaTeX编辑数学公式
- 在博客中使用LaTeX插入数学公式
- 在 markdown 中编写 LaTex 数学公式
- LaTeX技巧8:在博客中插入LaTex数学公式
- LaTeX中插入数学公式
- LaTeX中插入数学公式
- LaTeX中插入数学公式
- mathjax 渲染LaTeX 数学公式 使用教程
- Markdown中编写LaTeX数学公式
- LaTeX-数学公式中加粗字体
- Markdown中编写LaTeX数学公式
- 【Latex】如何在eclipse中配置Latex
- 如何在 visio 2013 中插入数学公式
- Oracle更新数据的方法
- RTP协议
- struts2_day02_06-获取表单数据(使用ServletActionContext获取和接口注入)
- Java树形菜单____Ztree树形菜单使用教程
- solr6.3.0的安装
- 如何在HEXO中渲染Latex数学公式
- python3.0 变动
- Android动画之属性动画
- 红米4手机(其它小米应该一样)adb 调试(usb ,tcp)
- php织梦读取新闻相关
- Spring RMI错误:java.rmi.ConnectException: Connection refused to host: 127.0.0.1
- JAVA IO流
- MySql服务无法启动系统出错发生系统错误1067进程意外终止
- linux内核panic/oops/crash分析(addr2line,objdump,gdb)