Windows Emacs 导出PDF

Windows Emacs 导出PDF

1. 概述

在 Termux 中,Org-mode 导出 PDF 的核心链路如下:

1
Org-mode → ox-latex → LaTeX → xelatex/pdflatex → PDF

在 Windows 中该流程完全一致,只是安装方式与路径不同。

本文目标:复现 Termux 的 Emacs + TeX Live + batch 导出 PDF 工作流。

2. TeX Live 安装(Windows)

推荐使用 TeX Live:

TeX Live 是跨平台 LaTeX 发行版,提供完整编译链。

2.1 下载与安装

下载地址: https://tug.org/texlive/

国内链接推荐:https://mirrors.tuna.tsinghua.edu.cn/CTAN/systems/texlive/Images/

  • 注:如果下载太慢,可以用迅雷下载

安装建议:

  • 选择 scheme-full(完整安装,避免缺包)
  • 安装路径示例: C:\texlive\2026\

2.2 环境变量配置

将 TeX Live 加入 PATH:

1
C:\texlive\2026\bin\windows

2.3 验证安装

1
2
xelatex --version
pdflatex --version

若输出版本信息则安装成功。

3. Emacs 安装

使用 GNU Emacs:

https://www.gnu.org/software/emacs/

建议版本:

  • Emacs 29 / 30

安装后路径示例:

1
C:\Program Files\Emacs\emacs-30.x\

验证:

1
emacs --version

4. Org → PDF 依赖链

Org 导出 PDF依赖如下模块:

1
2
3
4
5
6
7
org-mode
ox-latex
LaTeX Engine (xelatex)
PDF

确保 Emacs 内启用:

1
(require 'ox-latex)

5. Windows batch 导出 PDF

5.1 创建测试文件

1
echo "1" > test.org

5.2 Emacs batch 导出命令

1
2
3
4
5
6
7
emacs --batch ^
  --load "C:\Users\YOURNAME\.emacs.d\early-init.el" ^
  --load "C:\Users\YOURNAME\.emacs.d\init.el" ^
  --visit test.org ^
  --eval "(progn
            (require 'ox-latex)
            (org-latex-export-to-pdf))"

6. WSL 方案(推荐)

更稳定的方案是使用 WSL:

Windows Subsystem for Linux(WSL)

特点:

  • 与 Linux 环境一致
  • 可直接复用 Termux / Linux 命令
  • TeX Live + Emacs 行为完全一致

安装方式:

1
sudo apt install emacs texlive-full

导出命令:

1
2
3
4
5
emacs --batch \
  --load ~/.emacs.d/early-init.el \
  --load ~/.emacs.d/init.el \
  --visit test.org \
  --eval "(org-latex-export-to-pdf)"

7. 常见问题

7.1 找不到 xelatex

解决方法:

1
set PATH=%PATH%;C:\texlive\2026\bin\windows

7.2 org-latex-export-to-pdf 不生效

检查:

1
(require 'ox-latex)

7.3 中文 PDF 问题

建议使用 XeLaTeX:

1
2
3
(setq org-latex-pdf-process
      '("xelatex -interaction nonstopmode %f"
        "xelatex -interaction nonstopmode %f"))

8. Termux vs Windows 对照表

功能TermuxWindows
LaTeX 安装pkg install texlive-binTeX Live Installer
初始化termux-install-tlGUI 安装
路径$PREFIX/share/texliveC:\texlive\
清理rm -rf重装
batch Emacsemacs –batch同左
xelatextermux 包Windows PATH

9. 推荐架构

稳定性排序:

  1. WSL + Emacs + TeX Live(推荐)
  2. Windows + TeX Live + Emacs
  3. Termux(移动端)

10. 总结

Windows 下 Org → PDF 本质与 Termux 完全一致:

1
2
核心不变:Org → LaTeX → PDF
差异仅在:安装方式 + PATH 管理