# LaTeXSnipper Office 插件

在 Word 和 PowerPoint 中插入、编辑、转换和维护 LaTeXSnipper 公式。

## 系统要求

组件 | 要求
--- | ---
Windows 版本 | Windows 10 22H2 或更高版本 / Windows 11
Office 版本 | Microsoft 365 应用（当前通道或月度企业通道） Office 2024 / 2021 / 2019 零售版或批量许可版 Office LTSC 2024 / 2021
运行时 | .NET Framework 4.8；Microsoft Edge WebView2 Runtime（Windows 11 已内置；M365 会自动安装）
Office 体系 | 仅支持 32 位和 64 位桌面版 Office；不支持网页版、移动版和 macOS 版 Office
LaTeXSnipper 桌面端 | 需在本机运行并开启 Office 插件功能，插件通过 `127.0.0.1:28765` 与本机 Bridge 通信

## 快速开始

### 1. 启动桌面端

打开 LaTeXSnipper 桌面端，在设置中启用 Office 插件功能。

### 2. 打开编辑器

使用 Ribbon 插入按钮打开 MathLive 编辑器，输入或选择需要插入的公式。

### 3. 插入到文档

默认使用 OLE 公式对象插入。侧边栏只负责独立草稿和新插入；更新公式只从编辑器窗口提交。

公式编辑与渲染在插件内本地完成；截图识别需要本机 LaTeXSnipper 桌面端。

## 编辑器快捷键

MathLive 输入区按 Enter 新建数学行，首次换行会自动进入多行数学环境；按 Shift+Enter 插入或更新公式。Ctrl+F、Ctrl+R、Ctrl+H、Ctrl+L、Ctrl+J 分别插入分式、根号、上标、下标和上下标。空格键插入数学薄空格。Esc 不关闭编辑器，只收回 MathLive 虚拟键盘。提交期间按钮会禁用；如果 Office 正在执行加载、删除、重编号或 OCR 等命令，编辑器会提示稍后再试，不排队等待。

## 字体与宏包命令

设置页提供常用论文写作字体。下列字体既可作为新公式默认字体，也可在源码编辑框显式输入。

用途 | 源码示例 | MathJax 扩展 | 插件支持
--- | --- | --- | ---
TeX 原生数学字体 | `e^{i\pi}+1=0` | 内置 | 默认字体选项
罗马正体 | `\mathrm{rank}\,A` | 内置 | 默认字体选项；源码可用
数学斜体 | `\mathit{ABCxyz}` | 内置 | 默认字体选项；源码可用
粗体字母 | `\mathbf{x},\mathbf{A}` | 内置 | 默认字体选项；源码可用
粗体符号 | `\boldsymbol{\alpha+\nabla f}` | `boldsymbol` | 默认字体选项；源码可用
粗斜体 | `\mathbfit{x},\mathbfit{T}` | 内置 | 默认字体选项；源码可用
无衬线 | `\mathsf{ABCxyz}` | 内置 | 默认字体选项；源码可用
无衬线粗体 | `\mathbfsf{ABC}` | 内置 | 默认字体选项；源码可用
无衬线斜体 | `\mathsfit{ABCxyz}` | 内置 | 默认字体选项；源码可用
无衬线粗斜体 | `\mathbfsfit{ABCxyz}` | 内置 | 默认字体选项；源码可用
等宽 | `\mathtt{code123}` | 内置 | 默认字体选项；源码可用
花体 | `\mathcal{L},\mathcal{F}` | 内置 | 默认字体选项；源码可用
手写体 | `\mathscr{F},\mathscr{O}` | 内置/AMS 自动加载 | 默认字体选项；源码可用
哥特体 | `\mathfrak{g},\mathfrak{sl}_2` | 内置/AMS 自动加载 | 默认字体选项；源码可用
黑板粗体 | `\mathbb{R},\mathbb{N}` | 内置/AMS 自动加载 | 默认字体选项；源码可用
数学文本 | `\text{if }x>0`、`\textrm{Re}` | `textmacros` | 源码可用
直立希腊 | `\upalpha,\uppi,\Updelta` | `upgreek` | 源码可用
化学式文本 | `\ce{H2O}`、`\pu{9.8 m/s2}` | `mhchem` | 源码可用
物理微分和向量 | `\qty(\frac{a}{b})`、`\dv{f}{x}`、`\vb{E}` | `physics` | 源码可用
量子力学括号 | `\braket{\psi|\phi}`、`\ketbra{0}{1}` | `braket` | 源码可用
分段函数 | `\begin{cases}x^2,&x>0\\0,&x\le0\end{cases}` | `cases` | 源码可用
删除线与标记 | `\cancel{x}`、`\bcancel{y}`、`\xcancel{z}` | `cancel` | 源码可用
长箭头 | `A\xrightarrow[\beta]{\alpha}B` | `extpfeil` | 源码可用
数学工具扩展 | `\coloneqq`、`\vcentcolon`、`\prescript{a}{b}{X}` | `mathtools` | 源码可用
常用符号补充 | `\degree`、`\celsius`、`\textdegree` | `gensymb` / `textcomp` | 源码可用

默认字体会保存为对应的 LaTeX 字体命令。插件和客户端使用同一组本地 MathJax 3.2.2 扩展；不启用会吞掉错误提示的 noerrors/noundefined，也不默认启用 \require。

## Word 功能

### OLE 与 OMML

默认使用 OLE 公式对象，公式显示由 MathJax SVG 转为 EMF+Dual 矢量预览。设置中可切换到 Word OMML。

### 加载、更新和删除

选中受管理公式后用 Ribbon 加载到编辑器修改。编辑器提交后更新原公式；侧边栏不会承担更新入口。编辑器提交、加载所选、删除、重编号、OCR 等 Office 命令互斥执行，正在处理时不会排队堆积新的提交。

### 侧边栏草稿

侧边栏是独立的新公式草稿区。加载公式到编辑器时会临时显示该公式属性；编辑器提交或取消后恢复原来的侧边栏草稿。

### 添加编号与重编号

添加编号只对未编号的行间公式生效。可在设置中组合章、节、公式三级编号并选择层级分隔符；Ribbon 可插入章或节边界，后续编号会递归重置。章、节分隔符可以分别隐藏，也可以选中后通过“删除所选”移除。

### 转换、引用与格式化

“转换”会处理当前选区内的受管理公式，在 Word OMML 与 OLE 之间原位转换，不处理相邻文字或段落；多选时分批执行并在状态窗格显示进度。“引用”先插入占位符，再选择编号公式或其所在段落创建 Word REF 交叉引用；重编号时引用域同步更新，导出 PDF 后仍可点击跳转。编号边界可通过“删除所选”移除。“格式化所选”恢复默认字体、颜色和自然大小，多选时同样分批执行；“格式化全文”只恢复被手动拉伸公式的自然大小，并保留编号与引用。

### 带编号公式布局

带编号公式会将公式居中显示，并按设置把编号放在最左或最右。加载、更新和删除以公式对象或公式所在段落为稳定入口；单独选中编号数字不会反向删除公式。

### OLE 对象尺寸

新公式按光标处正文大小计算自然尺寸。更新已有 OLE 公式时保留用户在 Word 中手动拉伸出的对象倍率。

### 截图识别

点击后等待桌面端截图结果，再次点击可取消。

## PowerPoint 功能

### OLE 与 PNG 图片

默认使用 OLE 公式对象，公式显示由 MathJax SVG 转为 EMF+Dual 矢量预览。设置中可切换到 PNG 图片方式。

### 加载和删除

选中受管理公式后用 Ribbon 加载到同一套 MathLive 编辑器修改。编辑器提交后替换原位置公式，并保留用户在幻灯片中手动拉伸出的对象倍率。编辑器提交、加载所选、删除和 OCR 等 Office 命令互斥执行，正在处理时不会排队堆积新的提交。

### 侧边栏草稿

侧边栏是独立的新公式草稿区，不负责更新已有公式。

### 转换与格式化

“转换”会处理当前选区内的受管理公式，在 OLE 与 PNG 之间切换，不移动同页其他对象；多选时分批执行并在状态窗格显示进度。“格式化所选”恢复默认字体、颜色和自然大小，多选时同样分批执行；“格式化全文”只恢复被手动拉伸公式的自然大小。

### OLE 对象尺寸

新插入的 OLE 与 PNG 使用相同的初始倍率。更新已有公式时保留用户在幻灯片中手动拉伸出的对象倍率。

### 截图识别

点击后等待桌面端截图结果，识别后的 LaTeX 自动填入编辑器。再次点击可取消。

## 插件架构

项目 | 实现
--- | ---
运行方式 | Windows 原生 VSTO 插件，Ribbon、侧边栏、设置和帮助页均在 Office 内打开。
Word 公式 | 默认写入 LaTeXSnipper OLE 公式对象；OMML 是可选插入后端。
PowerPoint 公式 | 默认写入 LaTeXSnipper OLE 公式对象；PNG 图片是可选插入后端。
连接方式 | 公式在插件内本地渲染；截图识别通过本机 Bridge（`127.0.0.1:28765`）连接桌面端。
编辑器 | WebView2 托管的 MathLive 编辑器，支持可视化编辑和实时预览。编辑器提交与 Office 命令统一串行化。

## 边界说明

- 只有由 LaTeXSnipper 插入的受管理公式才能被插件加载、更新、删除和重编号。
- 普通 Office 公式不会被自动转换为 LaTeXSnipper 公式。
- 如果加载项未显示，请关闭 Office，重新运行安装包进行修复或重新安装，然后再打开 Office。

# LaTeXSnipper Office Plugin

Insert, edit, convert, and maintain LaTeXSnipper formulas in Word and PowerPoint.

## System Requirements

Component | Requirement
--- | ---
Windows | Windows 10 22H2 or later / Windows 11
Office | Microsoft 365 Apps (Current or Monthly Enterprise Channel) Office 2024 / 2021 / 2019 Retail or Volume License Office LTSC 2024 / 2021
Runtime | .NET Framework 4.8; Microsoft Edge WebView2 Runtime (built into Windows 11; auto-installed by M365)
Office Platform | 32-bit and 64-bit Windows desktop Office only; web, mobile, and macOS are not supported
LaTeXSnipper Desktop | Must be running locally with the Office plugin feature enabled; communicates via local Bridge at `127.0.0.1:28765`

## Quick Start

### 1. Start the client

Open LaTeXSnipper and enable Office plugin in settings.

### 2. Open the editor

Use Ribbon insert buttons to open the MathLive editor, then type or choose the formula to insert.

### 3. Insert into Office

OLE formula objects are the default. The side pane owns an independent draft for new insertions; formula updates are submitted only from the editor window.

Formula editing and rendering are local to the add-in. Screenshot OCR requires the local LaTeXSnipper desktop client.

## Editor Shortcuts

Press Enter in the MathLive field to start a new math row; the first line break creates a multiline math environment. Press Shift+Enter to insert or update the formula. Ctrl+F, Ctrl+R, Ctrl+H, Ctrl+L, and Ctrl+J insert a fraction, root, superscript, subscript, and combined scripts. Space inserts a mathematical thin space. Esc does not close the editor; it only retracts the MathLive virtual keyboard. Submit buttons are disabled during submission. If Office is already running load, delete, renumber, OCR, or another command, the editor reports that processing is busy instead of queueing the submit.

## Fonts and Macro Commands

The settings page includes common fonts used in academic writing. These styles can be used as new-formula defaults and as explicit source commands.

Use | Source example | MathJax extension | Add-in support
--- | --- | --- | ---
Native TeX math | `e^{i\pi}+1=0` | Built in | Default font option
Roman upright | `\mathrm{rank}\,A` | Built in | Default font option; source command
Math italic | `\mathit{ABCxyz}` | Built in | Default font option; source command
Bold letters | `\mathbf{x},\mathbf{A}` | Built in | Default font option; source command
Bold symbols | `\boldsymbol{\alpha+\nabla f}` | `boldsymbol` | Default font option; source command
Bold italic | `\mathbfit{x},\mathbfit{T}` | Built in | Default font option; source command
Sans serif | `\mathsf{ABCxyz}` | Built in | Default font option; source command
Sans serif bold | `\mathbfsf{ABC}` | Built in | Default font option; source command
Sans serif italic | `\mathsfit{ABCxyz}` | Built in | Default font option; source command
Sans serif bold italic | `\mathbfsfit{ABCxyz}` | Built in | Default font option; source command
Typewriter | `\mathtt{code123}` | Built in | Default font option; source command
Calligraphic | `\mathcal{L},\mathcal{F}` | Built in | Default font option; source command
Script | `\mathscr{F},\mathscr{O}` | Built in / AMS autoload | Default font option; source command
Fraktur | `\mathfrak{g},\mathfrak{sl}_2` | Built in / AMS autoload | Default font option; source command
Blackboard bold | `\mathbb{R},\mathbb{N}` | Built in / AMS autoload | Default font option; source command
Math text | `\text{if }x>0`, `\textrm{Re}` | `textmacros` | Source command
Upright Greek | `\upalpha,\uppi,\Updelta` | `upgreek` | Source command
Chemical text | `\ce{H2O}`, `\pu{9.8 m/s2}` | `mhchem` | Source command
Physics differentials and vectors | `\qty(\frac{a}{b})`, `\dv{f}{x}`, `\vb{E}` | `physics` | Source command
Quantum brackets | `\braket{\psi|\phi}`, `\ketbra{0}{1}` | `braket` | Source command
Piecewise functions | `\begin{cases}x^2,&x>0\\0,&x\le0\end{cases}` | `cases` | Source command
Cancellation marks | `\cancel{x}`, `\bcancel{y}`, `\xcancel{z}` | `cancel` | Source command
Long arrows | `A\xrightarrow[\beta]{\alpha}B` | `extpfeil` | Source command
Math tools | `\coloneqq`, `\vcentcolon`, `\prescript{a}{b}{X}` | `mathtools` | Source command
Additional symbols | `\degree`, `\celsius`, `\textdegree` | `gensymb` / `textcomp` | Source command

Default fonts are saved as the corresponding LaTeX font commands. The add-in and desktop client use the same local MathJax 3.2.2 extension set; noerrors/noundefined are not enabled because they hide formula errors, and \require is not enabled by default.

## Word Features

### OLE and OMML

OLE formula objects are the default. MathJax SVG output is converted to an EMF+Dual vector preview. Word OMML remains available in settings.

### Load, Update, Delete

Use the Ribbon to load a managed formula into the editor. Submitting the editor updates the original formula; the side pane is not an update entry point. Editor submit, load selected, delete, renumber, and OCR Office commands run through a single command gate; a busy command rejects new editor submits instead of queueing them.

### Side Pane Draft

The side pane is an independent new-formula draft. Loading a formula into the editor temporarily shows that formula's properties; after editor accept or cancel, the original side pane draft is restored.

### Add Number & Renumber

Add Number only applies to unnumbered display equations. Chapter, section, and equation levels can be combined with a configurable separator. Chapter and section boundaries recursively reset later counters and can be hidden independently.

### Conversion, References & Formatting

Conversion processes managed formulas in the current selection in place between Word OMML and OLE without touching adjacent text or paragraphs; multi-selection runs in batches and reports progress in the status pane. Insert Reference creates a placeholder; selecting a numbered formula or its paragraph creates a Word REF cross-reference, and renumbering updates the field. Exported PDFs keep the reference clickable. Numbering boundaries can be removed with Delete Selected. Format Selected restores the default font, color, and natural size and also runs multi-selection in batches; Format All only restores manually resized formulas to natural size while preserving numbering and references.

### Numbered Formula Layout

Numbered formulas center the formula and place the number on the left or right according to settings. Loading, updating, and deleting use the formula object or its paragraph as the stable target; selecting only the number text does not delete the formula.

### OLE Object Size

New formulas derive their natural size from the text at the insertion point. Updating an existing OLE formula preserves the object stretch factor manually set in Word.

### Screenshot OCR

Click to wait for the next desktop screenshot; click again to cancel.

## PowerPoint Features

### OLE and PNG Image

OLE formula objects are the default. MathJax SVG output is converted to an EMF+Dual vector preview. PNG image insertion remains available in settings.

### Load and Delete

Use the Ribbon to load a managed formula into the same MathLive editor. After editing, the new formula replaces the original at the same position and preserves the object stretch factor manually set on the slide. Editor submit, load selected, delete, and OCR Office commands run through a single command gate; a busy command rejects new editor submits instead of queueing them.

### Side Pane Draft

The side pane is an independent new-formula draft and is not an update entry point.

### Conversion and Formatting

Conversion processes managed formulas in the current selection between OLE and PNG without moving other slide objects; multi-selection runs in batches and reports progress in the status pane. Format Selected restores the default font, color, and natural size and also runs multi-selection in batches; Format All only restores manually resized formulas to natural size.

### OLE Object Size

New OLE and PNG formulas use the same initial scale. Updating an existing formula preserves the object stretch factor manually set on the slide.

### Screenshot OCR

Click to wait for the next desktop screenshot; recognized LaTeX is loaded into the editor. Click again to cancel.

## Plugin Architecture

Area | Implementation
--- | ---
Runtime | Native Windows VSTO add-in. Ribbon, side pane, settings, and help open inside Office.
Word Output | LaTeXSnipper OLE formula objects by default; OMML is an optional backend.
PowerPoint Output | LaTeXSnipper OLE formula objects by default; PNG image insertion is an optional backend.
Connection | Formulas render locally inside the plugin. Screenshot OCR uses the desktop client through the local Bridge at `127.0.0.1:28765`.
Editor | WebView2-hosted MathLive editor with visual editing and live preview. Editor submissions are serialized with Office commands.

## Boundaries

- Only managed formulas inserted by LaTeXSnipper can be loaded, updated, deleted, and renumbered by the plugin.
- Plain Office equations are not automatically converted into LaTeXSnipper formulas.
- If the add-in does not appear, close Office, run the installer again to repair or reinstall the add-in, then reopen Office.