像写论文一样写 Hexo:支持自动编号的定理环境,以及 bibtex 参考文献 - V2EX
V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
爱意满满的作品展示区。
mathzhaoliang
V2EX    分享创造

像写论文一样写 Hexo:支持自动编号的定理环境,以及 bibtex 参考文献

  •  
  •   mathzhaoliang
    neozhaoliang 2024-04-27 11:08:32 +08:00 2081 次点击
    这是一个创建于 598 天前的主题,其中的信息可能已经有所发展或是发生改变。

    我有一个数学相关的博客,里面的文章经常要用到定理环境。以前我的做法是使用 Hexo 自带的

    <div id="thm-name"> {% blockquote %} ... {% endblockquote %} </div> 

    手动加上编号。需要在其它地方引用的时候就用 定理 1 这样的写法。但是显然这个方案很丑,因为一旦定理顺序作了修改,所有的编号都要重新调整,非常麻烦。

    现在我找到了一个解决方案分享给大家。

    效果地址: https://pywonderland.com/weyl-character-formula/

    你需要做这么几件事情:

    1. 使用 hexo-renderer-pandoc 插件作为 md 的解释器. npm install hexo-renderer-pandoc --save 然后删掉 hexo 自带的 hexo-renderer-marked 。
    2. 这个 repo clone 到你的本地,放在 blog 目录,和 _config.yml 都处于顶层即可。
    3. 同样在你的 blog 目录下,和 _confi.yml 处于同一级,新建一个 metadata.yml,里面写上
    --- link-citations: true reference-section-title: "References" bibliography: "./ref.bib" statement: supply-header: no count-within: section crossref-prefixes: true statement-kinds: theorem: label: 定理 lemma: label: 引理 counter: theorem proposition: label: 命题 counter: theorem corollary: label: 推论 counter: theorem definition: label: 定义 counter: theorem proof: label: 证明 counter: none style: definition note: label: 注记 counter: none style: definition example: label: 例 counter: none style: definition question: label: 问题 counter: theorem style: definition statement-styles: definition: punctuation: ':' note: punctuation: ':' --- 

    上面这个是控制各种定理、引理等环境的显示方式,比如定理环境会统一显示为 **定理 1.**,而例子会统一显示为 例: 这样。此外里面还指定了定理编号是跟着 section 走,以及参考文献的路径。

    然后, 在你的 _config.yml 里面加上

    pandoc: args: - '--to' - 'html5' - '-L' - './statement/statement.lua' - '--citeproc' - '--metadata-file' - './metadata.yml' - '--mathjax' 

    这一步是为了把编译参数传给 pandoc 。最后,还要在你的博客的 css/styl 文件里面加上:

     .statement.plain background-color: rgba(0, 0, 0, 0.03); padding: 0.6rem 0.6rem 0.6rem 1.2rem; border-left: 5px solid #ee6e73; margin: 1.5em 0em; color: black; .statement.example.definition background-color: rgba(0, 0, 0, 0.03); padding: 0.6rem 0.6rem 0.6rem 1.2rem; border-left: 5px solid #0565f6; margin: 1.5em 0em; color: black; .statement.definition background-color: rgba(0, 0, 0, 0.03); padding: 0.6rem 0.6rem 0.6rem 1.2rem; border-left: 5px solid #0565f6; margin: 1.5em 0em; color: black; .statement.plain .statement-label font-weight: bold; .statement.note.unnumbered margin: 2em auto; padding: 0.5em; font-size: 85%; width: 90%; box-shadow: 0 0 10px rgba(0,0,0,0.5); border-radius: 5px; padding: 10px; .statement.definition .statement-label font-weight: bold; .statement.proof .statement-label font-weight: bold; .statement.plain p:first-child text-indent: 0pt; .statement.plain .statement-info font-style: normal; font-weight: normal; font-variant: normal; .csl-entry border-left: 1px solid #777; padding-left: 1em; margin-left: 2em; margin-top: 1.5em; margin-bottom: 1.5em; margin-right: 0em; font-size: 100%; line-height: 150%; 

    以控制定理环境和参考文献的样式。

    然后 hexo clean && hexo g 你的博客现在就可以支持自动编号的定理环境了。

    在正文中,你可以这样写:

    ::: {.theorem #thm-name} xxxxx ::: 

    引用的时候使用 @Pre:thm-name ,所有的编号就都自动可以完成了。如果你不想给某个定理编号,那么可以加上 .unnumbered 标签:

    ::: {.theorem .unnumbered #thm-name} xxxxx ::: 

    如果你想用 bibtex 管理参考文献的话,可以把参考文献放在 blog 目录下的比如 ref.bib 文件中 (见上面 metadata.yml 中 reference 路径的设置)。然后在正文中引用方式为 [@Einstein section 1.1] 这样。

    希望上面的方法对大家有用。

    目前尚无回复
    关于     帮助文档     自助推广系统     博客     API     FAQ     Solana     5153 人在线   最高记录 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 35ms UTC 07:25 PVG 15:25 LAX 23:25 JFK 02:25
    Do have faith in what you're doing.
    ubao msn snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86