PPT 转 LaTeX Beamer 工具
中英文 README 文档
中文 README
PPT 转 LaTeX Beamer 转换器 VBA 脚本
工具简介
这是一个 VBA 宏脚本,可从Microsoft PowerPoint (.ppt) 演示文稿中提取文本和基础内容,自动转换为标准 LaTeX Beamer 帧结构,并将结果保存为文本文件,可直接用于制作 Beamer 幻灯片。
重要说明与警告
- 文件格式要求:运行脚本前,必须将演示文稿保存为 .ppt 格式(不支持 .pptx)。
- 文件覆盖风险:如果与PPT文件同文件夹下存在同名文件,脚本会直接覆盖,请提前备份。
- 无担保声明:本脚本免费提供,不提供任何形式的担保或承诺,请自行承担使用风险。
- 图片处理:脚本会自动重命名图片,移除空格和特殊字符,兼容 LaTeX 编译。
功能特性
- 提取幻灯片标题,自动转换为
\frametitle{} 格式
版权与致谢
- 原始作者:Louis(TeX StackExchange)
- 优化修改:Jason Kerwin(2018年2月20日)
- 改进内容:修复标题格式、移除多余分段、优化图片命名规则
使用方法
第一步:准备 PowerPoint 文件
- 用 Microsoft PowerPoint 打开你的演示文稿
- 另存为 → 选择 .ppt 格式(务必不要选 .pptx)
第二步:开启 PowerPoint 开发工具选项卡
第三步:导入并运行 VBA 脚本
- 在左侧「工程」面板中右键你的演示文稿 → 插入 → 模块
- 选择
ConvertToBeamer → 点击执行
第四步:获取输出文件
- 生成的
.txt 文件会保存在 .ppt 文件所在的同一文件夹 中 - 可直接将文件内容复制到你的 LaTeX Beamer 文档正文中使用
输出代码示例
\section{PresentationName}\begin{frame}\frametitle{幻灯片标题}幻灯片正文内容\end{frame}
限制说明
- 复杂排版的幻灯片可能需要在 LaTeX 中手动调整
' this code extracts text from PPT(X) and saves to latex beamer body' Provided for free with no guarantees or promises'WARNING: this will overwrite files in the powerpoint file's folder if there are name collisiona' Original version by Louis from StackExchange (https://tex.stackexchange.com/users/6321/louis) available here: (https://tex.stackexchange.com/questions/66007/any-way-of-converting-ppt-or-odf-to-beamer-or-org)' Modified by Jason Kerwin (www.jasonkerwin.com) on 20 February 2018:' Takes out extra text that printed in the title line ' Switches titles to \frametitle{} instead of including them on the \begin{frame} line (sometimes helps with compiling)' Changes the image names to remove original filename, which might have spaces ' Removes "\subsection{}"which was printing before each slide'NB you must convert your slides to .ppt format before running this codePublic Sub ConvertToBeamer() Dim objPresentation As Presentation Set objPresentation = Application.ActivePresentation Dim objSlide As Slide Dim objshape As Shape Dim objShape4Note As Shape Dim hght As Long, wdth As Long Dim objFileSystem Dim objTextFile Dim objGrpItem As Shape Dim Name As String, Pth As String, Dest As String, IName As String, ln As String, ttl As String, BaseName As String Dim txt As String Dim p As Integer, l As Integer, ctr As Integer, i As Integer, j As Integer Dim il As Long, cl As Long Dim Pgh As TextRange Name = Application.ActivePresentation.Name p = InStr(Name, ".ppt") l = Len(Name) If p + 3 = l Then Mid(Name, p) = ".txt" Else Name = Name & ".txt" End If BaseName = Left(Name, l - 4) Pth = Application.ActivePresentation.Path Dest = Pth & "\" & Name ctr = 0 Set objFileSystem = CreateObject("Scripting.FileSystemObject") Set objTextFile = objFileSystem.CreateTextFile(Dest, True, True) objTextFile.WriteLine "\section{" & Name & "}" With Application.ActivePresentation.PageSetup
English README
PPT to LaTeX Beamer Converter VBA Script
Overview
This VBA macro extracts text and basic content from Microsoft PowerPoint (.ppt) presentations and converts them into a LaTeX Beamer frame structure, saving the output as a text file for direct use in Beamer presentations.
Important Notes & Warnings
- File Format Requirement: Your presentation MUST be saved as .ppt format (not .pptx) before running this script.
- File Overwrite Risk: This script will overwrite existing files in the same folder as your PowerPoint file if there are filename conflicts.
- No Warranty: This script is provided for free, with NO warranties or guarantees of any kind. Use at your own risk.
- Image Handling: The script renames images to remove spaces and special characters for LaTeX compatibility.
Features
- Extracts slide titles and converts to
\frametitle{} - Extracts body text from all slides
- Generates standard LaTeX Beamer frame syntax
- Removes invalid LaTeX formatting and extra characters
- Cleans image filenames for compatibility
- Outputs a ready-to-use
.txt Beamer body file
Credits
- Original Author: Louis (TeX StackExchange)
- Modified By: Jason Kerwin (20 Feb 2018)
- Improvements: Fixed title formatting, removed extra sections, optimized image naming
How to Use
Step 1: Prepare Your PowerPoint File
- Open your presentation in Microsoft PowerPoint
- Save As → Select .ppt format (not .pptx)
- Close and re-open the .ppt file
Step 2: Enable Developer Tab in PowerPoint
- Go to File → Options → Customize Ribbon
- Check the box for Developer in the right panel
Step 3: Import & Run the VBA Script
- Click Visual Basic to open the VBA editor
- Right-click your presentation in the Project Explorer → Insert → Module
- Paste the full VBA code into the module window
- Back in PowerPoint: Developer → Macros
- Select
ConvertToBeamer → Click Run
Step 4: Get the Output File
- The generated
.txt file will appear in the same folder as your .ppt file - Copy the content directly into your LaTeX Beamer document body
Output Structure Example
\section{PresentationName}\begin{frame}\frametitle{Slide Title}Slide body text content\end{frame}
Limitations
- Only extracts text and basic shapes; complex formatting is not preserved
- Tables, charts, animations, and transitions are not converted
- Advanced PowerPoint layouts may require manual adjustment in LaTeX