安装
安装MathJax-LaTeX插件。
在插件设置中,打开Force Load(在每篇文章中自动使用\(LaTeX{}\)),打开Use wp-latex syntax(可以使用$latex $插入\(LaTeX{}\))。
使用
通过$$E=mc^2$$或\\[E=mc^2\\]得到$$E=mc^2$$,
通过$latex E=mc^2$或\\(E=mc^2\\)得到\(E=mc^2\)。
在文章的任意位置加入[nomathjax]以禁用\(LaTeX{}\)。
坑
所有的\应改为\\,所有的_应改为\_。
无法使用常规的$ $来插入行内公式。
公式中不能有空行。
使用$以插入$,使用[和]以插入[和](全部符号见htmlsymbols.xyz)。
解决方案:使用以下的python代码进行格式转换(只能解决前三个问题)
注意:这里暴力去除了所有空行,可能会导致格式问题。(如果你真的想要一个空行,空两行。)
'''
将markdown转为wordpress友好的形式
ver 1.2
by peop1e 2024
'''
nowB='xxds'
import re
def convert(input_name, output_name):
try:
with open(input_name, 'r', encoding='utf8') as fr, open(output_name, 'w', encoding='utf8') as fw:
data = fr.read()
pattern1 = '\$[\s\S]+?\$'
pattern2 = '\$\$[\s\S]+?\$\$'
data = re.sub(pattern2, lambda x:'\\[' + re.split('\$\$',x.group(0))[1] + '\\]', data)
data = re.sub(pattern1, lambda x:'\\(' + re.split('\$',x.group(0))[1] + '\\)', data)
data=data.replace('\\','\\\\')
data=data.replace('_','\\_')
qu=data.split('\n')
flg=False
for qz in qu:
if(qz!=""):
fw.write(qz+"\n")
flg=False
else:
if flg:
fw.write("\n")
else:
flg=True
print('Sucess!')
except FileNotFoundError as e:
print(e)
if __name__ == '__main__':
convert('md/'+nowB+'.md','wp/'+nowB+'.md')
其实还有一个更简单的办法,在typora里写好之后导出为html,解决所有问题……

