技术背景
在前面的几篇文章中,我们介绍过在RMarkdown中编写Latex Beamer风格的演讲文档,还有使用pandoc直接编译Markdown文档为Beamer的方法。pandoc是这些不同方案背后的核心编译工具,核心用法还是把markdown转译成Beamer风格的tex文件,然后再用latex编译器将其编译为pdf格式的文档。目前除了RMarkdown之外,还有一些VSCode插件的方法可以用。但是本文我要推荐的是另外一个Markdown撰写工具:Zettlr。非常简洁的一个开源软件,有所见即所得模式和源码模式,而且配置好之后,还可以直接输出Latex Beamer风格的文档。
Zettlr下载
重要的事情说三遍:不要从官网下载!不要从官网下载!不要从官网下载!这个软件近期都还在开源仓库上有更新,可以直接从Github的release中下载一个最新版本的tag,例如当前的最新版本是4.6.0:

我这里使用的是Windows的平台,下载完exe文件之后,直接双击就可以开始安装和使用了。

TinyTex下载安装
前面有提到,要生成Latex Beamer风格的演示文档,需要用到pandoc来进行转译,而pandoc转为tex之后,又需要通过xelatex来进行编译构建,所以我们还是需要一个latex的编译器。而TinyTex是一个不错的选择,它的大包中就包含了xelatex,所以我们可以直接从tinytex-releases这个开源的release项目中下载最新版本的TinyTex安装包。需要注意的是,这里每一个平台都提供了三个安装包选项,我们选择体积最大的那个即可。

下载解压缩运行之后,要把这个bin/windows的路径添加到系统路径中。如果配置正确,在Power Shell中应该可以运行得到:
bash
> xelatex --version
XeTeX 3.141592653-2.6-0.999998 (TeX Live 2026)
kpathsea version 6.4.2
Copyright 2026 SIL International, Jonathan Kew and Khaled Hosny.
There is NO warranty. Redistribution of this software is
covered by the terms of both the XeTeX copyright and
the Lesser GNU General Public License.
For more information about these matters, see the file
named COPYING and the XeTeX source.
Primary author of XeTeX: Jonathan Kew.
Compiled with ICU version 78.2; using 78.2
Compiled with zlib version 1.3.2; using 1.3.2
Compiled with FreeType2 version 2.14.1; using 2.14.1
Compiled with Graphite2 version 1.3.14; using 1.3.14
Compiled with HarfBuzz version 12.3.2; using 12.3.2
Compiled with libpng version 1.6.55; using 1.6.55
Compiled with pplib version v2.2
Compiled with fontconfig version 2.15.0; using 2.15.0
Ctex中文支持
像latex这样的产品,对于中文的直接支持还是差一点,有可能编译出来会是一个方框。如果需要中文支持的话,可以按照如下方式装一个ctex:
bash
> tlmgr update --self
tlmgr.pl: package repository https://tlnet.yihui.org (not verified: gpg unavailable)
tlmgr.pl: Preparing TeX Live infrastructure update...
DO NOT CLOSE THIS WINDOW!
TeX Live infrastructure update in progress ...
Detailed command logging to "S:\TinyTex\TinyTeX\temp\update-self.log"
self update: texlive.infra (79365 -> 79511)
Infrastructure update finished successfully.
You may now close this window.
> tlmgr install ctex
tlmgr.pl: package repository https://tlnet.yihui.org (not verified: gpg unavailable)
[1/44, ??:??/??:??] install: adobemapping [2128k]
[2/44, 00:04/02:37] install: arphic [26742k]
[3/44, 00:23/01:06] install: chinese-jfm [3k]
[4/44, 00:24/01:09] install: cjk [58k]
[5/44, 00:25/01:12] install: cjkpunct [4k]
[6/44, 00:26/01:15] install: cns [2916k]
[7/44, 00:32/01:24] install: ctablestack [2k]
[8/44, 00:33/01:26] install: ctex [131k]
[9/44, 00:34/01:29] install: everyhook [3k]
[10/44, 00:34/01:29] install: fandol [21077k]
[11/44, 00:44/01:09] install: fonts-tlwg [4932k]
[12/44, 00:47/01:07] install: garuda-c90 [4k]
[13/44, 00:49/01:10] install: l3backend-dev [17k]
[14/44, 00:49/01:10] install: l3kernel-dev [187k]
[15/44, 00:51/01:13] install: latex-base-dev [258k]
[16/44, 00:52/01:14] install: latex-firstaid-dev [5k]
[17/44, 00:53/01:15] install: luatexbase [4k]
[18/44, 00:54/01:17] install: luatexja [196k]
[19/44, 00:55/01:18] install: mptopdf.windows [3k]
[20/44, 00:55/01:18] install: mptopdf [37k]
[21/44, 00:56/01:19] install: norasi-c90 [9k]
[22/44, 00:57/01:21] install: platex.windows [3k]
[23/44, 00:58/01:22] install: platex [42k]
[24/44, 00:58/01:22] install: platex-tools [9k]
[25/44, 00:59/01:24] install: ptex.windows [1156k]
[26/44, 01:01/01:25] install: ptex [1k]
[27/44, 01:01/01:25] install: ptex-base [10k]
[28/44, 01:02/01:26] install: ptex-fonts [14k]
[29/44, 01:03/01:28] install: ttfutils.windows [519k]
[30/44, 01:04/01:28] install: ttfutils [107k]
[31/44, 01:05/01:29] install: uhc [3516k]
[32/44, 01:16/01:39] install: uplatex.windows [3k]
[33/44, 01:17/01:40] install: uplatex [15k]
[34/44, 01:18/01:41] install: uptex.windows [1398k]
[35/44, 01:19/01:41] install: uptex [1k]
[36/44, 01:20/01:42] install: uptex-base [10k]
[37/44, 01:22/01:44] install: uptex-fonts [165k]
[38/44, 01:23/01:45] install: wadalab [17357k]
[39/44, 01:39/01:39] install: xcjk2uni [196k]
[40/44, 01:41/01:41] install: xecjk [231k]
[41/44, 01:42/01:42] install: xpinyin [197k]
[42/44, 01:43/01:43] install: zhmetrics [59k]
[43/44, 01:47/01:47] install: zhmetrics-uptex [31k]
[44/44, 01:47/01:47] install: zhnumber [9k]
running mktexlsr ...
done running mktexlsr.
running updmap-sys ...
done running updmap-sys.
regenerating fmtutil.cnf in S:/TinyTex/TinyTeX/texmf-dist
running fmtutil-sys --byengine euptex --no-error-if-no-format --no-error-if-no-engine=luametatex,luajithbtex,luajittex,mfluajit,xetex --status-file=C:\Users\dechi\AppData\Local\Temp\YhLR1fpn3j\ENydfFIEH2 ...
OK: euptex.fmt/euptex uptex.fmt/euptex uplatex.fmt/euptex platex-dev.fmt/euptex ptex.fmt/euptex eptex.fmt/euptex platex.fmt/euptex uplatex-dev.fmt/euptex
running fmtutil-sys --byfmt mptopdf --no-error-if-no-engine=luametatex,luajithbtex,luajittex,mfluajit,xetex --status-file=C:\Users\dechi\AppData\Local\Temp\YhLR1fpn3j\ENydfFIEH2 ...
OK: euptex.fmt/euptex uptex.fmt/euptex uplatex.fmt/euptex platex-dev.fmt/euptex ptex.fmt/euptex eptex.fmt/euptex platex.fmt/euptex uplatex-dev.fmt/euptex mptopdf.fmt/pdftex
tlmgr.pl: package log updated: S:/TinyTex/TinyTeX/texmf-var/web2c/tlmgr.log
tlmgr.pl: command log updated: S:/TinyTex/TinyTeX/texmf-var/web2c/tlmgr-commands.log
Zettlr Beamer格式配置
重启Zettlr,配置一个Beamer输出格式:

内容为:
yaml
reader: markdown
writer: beamer
pdf-engine: xelatex
variables:
documentclass: beamer
classoption: aspectratio=169
就可以编译出Beamer格式的pdf了

这个演示文档所对应的Markdown原文内容为:
markdown
---
title: "My Beamer"
author: "Dechin"
institute: "My Institute"
date: "2025-01-20"
documentclass: beamer
header-includes:
- \usetheme{Dresden}
- \usepackage{ctex}
---
# Markdown
This is an Markdown presentation. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see <http://rmarkdown.rstudio.com>.
When you click the **Knit** button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document.
# Slide with Bullets
- Bullet 1
- Bullet 2
- Bullet 3
# Slide with Python Output
\`\`\`python
import numpy as np
print ('This is a python code block')
\`\`\`
# Slide with Equation
Test Equation input
$$ -i\hbar\frac{\partial}{\partial t}\left|\psi\right>=E\left|\psi\right> $$
总结概要
Latex Beamer是我个人非常喜欢的一个演示文稿风格,该文稿类型,不仅对于公式、代码块有很好的展示效果,同时在演示文稿的架构上有非常清晰的层次感,甚至可以直接支持mermaid这样的流程图,内容专业而丰富。所以我也一直有在探索有什么工具可以更好的结合Markdown的简明语法和Latex Beamer的专业演示,从这点上来说,我觉得Zettlr是一个不错的开始。
版权声明
本文首发链接为:https://www.cnblogs.com/dechinphy/p/zettlr.html
作者ID:DechinPhy
更多原著文章:https://www.cnblogs.com/dechinphy/
请博主喝咖啡:https://www.cnblogs.com/dechinphy/gallery/image/379634.html