Hexo-Latex
前言
使用Hexo
创建博客后,难免会遇到公式的书写问题。但是本地Typora
的公式渲染无法直接在博客中显示出来,主要原因是Hexo
默认使用的渲染器不支持latex公式,因此需要更换渲染器(hexo-renderer-pandoc
),并且进行后续的一系列操作。
操作流程
卸载默认公式渲染器
npm un hexo-math
npm un hexo-renderer-markednpm
加速下载(可选)使用
npm
镜像npm config set registry https://registry.npmmirror.com
查看当前镜像源
npm config get registry
返回官方原始镜像源
npm config set registry https://registry.npmjs.org/
安装新的公式渲染器即插件
npm i hexo-renderer-pandoc
这步可以视具体情况而定,但是如果遗漏可能会没办法正确显示公式
npm i hexo-filter-mathjax
配置文件更改 (
eg:\themes\butterfly\ _config.yml
)# Math (數學)
# --------------------------------------
# About the per_page
# if you set it to true, it will load mathjax/katex script in each page (true 表示每一頁都加載js)
# if you set it to false, it will load mathjax/katex script according to your setting (add the 'mathjax: true' in page's front-matter)
# (false 需要時加載,須在使用的 Markdown Front-matter 加上 mathjax: true)
# MathJax
mathjax:
enable: true # 将此处更改为true,并且在每个md文件前面加上mathjax:true
per_page: false
# KaTeX
katex:
enable: false
per_page: false
hide_scrollbar: trueMarkdown
文件开头如下:---
title: Hexo-Latex
author: Kegard
date: 2023-12-12 23:12:35
tags: Hexo
categories: Hexo
mathjax: true
---本地安装
pandoc
执行完上述步骤,直接进行
hexo g
时,出现错误pandoc exited with code null
,需要在本地安装pandoc
[官方下载地址]下载安装包:
pandoc-3.1.9-windows-x86_64.msi
测试安装是否成功:
win
+r
cmd
pandoc -v
, 出现以下命令表示安装成功pandoc 3.1.9
Features: +server +lua
Scripting engine: Lua 5.4
User data directory: C:\Users\31793\AppData\Roaming\pandoc
Copyright (C) 2006-2023 John MacFarlane. Web: https://pandoc.org
This is free software; see the source for copying conditions. There is no
warranty, not even for merchantability or fitness for a particular purpose.重启
git bash
结语
是否支持Latex
语法与Hexo
应用主题无关,根本原因还是在于Hexo
默认的公式渲染器。
上述操作解决本人在使用行内公式的渲染问题,但是具体其他的公式无法显示的问题能否解决,有待考察。
本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 Zone!