The design philosophy of DSH (DeepSeek Harness) is “everything is a plugin.” When creating documents that contain complex mathematical formulas, converting LaTeX into native Word/WPS formats is a common requirement. dsh-latex2office is a locally running plugin designed to address this conversion problem. It supports two modes: native OMML equations or high-resolution rendered images.
Core Capabilities¶
Conversion Modes¶
The plugin provides two core output modes:
* Native OMML Equations: Generates natively editable Word/WPS equations (math_mode=omml). Used by default for .docx files and supports double-clicking inside the document to launch the equation editor for further editing.
* High-Resolution Rendered Images: Generates PNG images (math_mode=image). Used by default for .pptx files to work around WPS display issues with OMML embedded in PowerPoint.
Batch Atomic Operations and Typesetting¶
- Batch Atomic Insertion: Supports inserting multiple formulas in a batch. If any formula in the list fails to parse or a positioning anchor is missing, the entire file-write operation is rolled back, ensuring the file remains byte-for-byte unchanged.
- Academic Tab-Stop Numbering: Supports adding numbers to formulas (e.g.,
number:"3.1") and automatically produces an academic typesetting layout with the equation centered and the number right-aligned. - Automatic Backup and Read-Back: On the first modification, automatically generates
.bak.docxor.bak.pptx(existing backups are not overwritten). After every write, it automatically reads the file back to verify the number of formulas.
Isolation and Security¶
- Zero npm Dependencies: The plugin itself does not depend on npm transitive dependencies. It uses only pure ES Modules and the bundled Python engine.
- Isolated Rendering: LibreOffice rendering uses a separate temporary user profile, so it does not lock documents currently being edited by the user.
- Error Handling: All external process invocations go through the DSH
ctx.subprocessservice. Timeout and overflow protections are included. Errors are returned as JSON without loss and do not affect the main Harness process.
Installation and Activation¶
Option 1: DSH Desktop Plugin Marketplace¶
Search for dsh-latex2office in the DSH desktop plugin marketplace. After a one-click installation, restart DSH to activate the plugin.
Option 2: Manual Installation¶
Edit the profile manifest under the DSH data directory (for desktop, it is usually located at harness/profiles/web/package.json) and add the dependency and Bundle:
{
"dependencies": {
"dsh-latex2office": "github:hufangd-2019/dsh-latex2office"
},
"dsh": {
"profile": {
"bundles": [
"dsh-latex2office"
]
}
}
}
Run pnpm install in the profile directory, then restart the DSH desktop app.
Option 3: Local Development Link¶
Write the dependency as "dsh-latex2office": "link:<local directory>". The remaining steps are the same as Option 2. After modifying the code, restart DSH to make changes take effect immediately.
Optional Configuration¶
In the profile’s own cordis.patch.yml, you can attach configuration to the plugin to override default paths or timeout settings:
- id: latex2office-tools
config:
pythonPath: 'D:\python\python.exe' # 留空则自动探测
pandocPath: ''
sofficePath: ''
renderTimeoutSec: 90
Typical Usage¶
The plugin registers three tools, which are invoked through JSON:
1. Generate a Numbered Equation Document¶
Use latex2office_generate to create a new file.
{
"tool": "latex2office_generate",
"args": {
"output": "D:/docs/equations.docx",
"title": "运动方程",
"formulas": [
{
"latex": "\\frac{\\partial u}{\\partial t} + u\\frac{\\partial u}{\\partial x} = -\\frac{1}{\\rho}\\frac{\\partial p}{\\partial x}",
"number": "1.1"
}
]
}
}
2. Insert into an Existing Document¶
Use latex2office_insert for positioned insertion.
{
"tool": "latex2office_insert",
"args": {
"file": "D:/docs/report.docx",
"formulas": [
{
"latex": "E = mc^2",
"position": { "mode": "after_text", "text": "质能方程:" },
"number": "2.1"
},
{
"latex": "\\sigma_x = \\frac{F}{A}",
"position": { "mode": "end" }
}
]
}
}
Host Dependencies¶
Running the plugin depends on non-npm tools installed on the host system. Ensure the versions meet the requirements:
| Dependency | Purpose | Description |
|---|---|---|
| Python ≥ 3.10 | Document engine | Used to invoke libraries such as python-docx and python-pptx |
| pandoc | LaTeX-to-OMML conversion | Extracts m:oMathPara through a temporary DOCX file |
| LibreOffice | Image rendering | Uses soffice --headless; a separate temporary profile is required |
The resolution order is cordis line configuration → PATH → the common installation path table. If a dependency is missing, the affected tools return a clear JSON error, without affecting plugin loading.
Uninstall / Rollback¶
To completely remove the plugin:
1. Remove the "dependencies" and "bundles" entries added to the profile manifest.
2. Restart the DSH desktop app.
This plugin has zero npm dependencies, so no transitive dependencies remain after uninstallation.
Summary¶
dsh-latex2office provides a local conversion solution from LaTeX to Office within the DSH ecosystem. It solves problems such as difficult equation editor integration, poor image rendering quality, and unsafe batch operations. For developers who need to handle academic formulas or technical documentation, this is a practical, ready-to-use tool.
More details and source code: https://github.com/hufangd-2019/dsh-latex2office