Fword — Word ↔ LaTeX Converter
You are an AI assistant equipped with the Fword skill for bidirectional Word ↔ LaTeX conversion.
When to Activate
Activate this skill when the user:
- - Wants to convert a
.docx / Word file to LaTeX - Wants to convert a
.tex / LaTeX file back to Word - Asks you to edit a Word document (convert to LaTeX first, edit, convert back)
- Mentions "fword" by name
Setup
Before first use, ensure dependencies are installed:
CODEBLOCK0
Check if setup is needed by testing: python3 -c "import pypandoc, anthropic, openai, docx". If this fails, run setup.
Supported AI Providers
| Provider | Env Variable | Default Model | Flag |
|---|
| Anthropic (Claude) | INLINECODE3 | INLINECODE4 | INLINECODE5 |
| OpenAI |
OPENAI_API_KEY |
gpt-4o |
-p openai |
| Qwen (Alibaba) |
DASHSCOPE_API_KEY |
qwen-plus |
-p qwen |
| Kimi (Moonshot) |
MOONSHOT_API_KEY |
moonshot-v1-8k |
-p kimi |
| MiniMax |
MINIMAX_API_KEY |
MiniMax-Text-01 |
-p minimax |
| DeepSeek |
DEEPSEEK_API_KEY |
deepseek-chat |
-p deepseek |
| Zhipu (GLM) |
ZHIPU_API_KEY |
glm-4-plus |
-p zhipu |
Any OpenAI-compatible API can also be used via --base-url.
Commands
Word → LaTeX
CODEBLOCK1
Options:
- -
-p, --provider PROVIDER — AI provider (default: anthropic) - INLINECODE26 — AI model (default: provider's default)
- INLINECODE27 — API key (or set provider's env var)
- INLINECODE28 — Custom API base URL
- INLINECODE29 — Pandoc-only conversion, no AI refinement (no API key needed)
- INLINECODE30 — Save Pandoc's raw output as INLINECODE31
Examples:
CODEBLOCK2
LaTeX → Word
CODEBLOCK3
Options:
- -
--reference-doc PATH — Use a specific Word template for styles (overrides workspace)
Workflow
Standard conversion
- 1. Run
convert.py on the .docx file — this creates a .fword/ workspace and outputs INLINECODE36 - The
.fword/ workspace stores the original document as a style reference - Edit the LaTeX as needed
- Run
back.py to convert back — it automatically finds the workspace and recovers styles
AI-assisted editing workflow
When the user wants to edit a Word document with AI help:
- 1. Convert:
convert.py document.docx → produces INLINECODE40 - Read the
.tex file and make the requested edits directly in LaTeX - Convert back:
back.py document.tex → produces document.docx with original styles
Quick reference
| User wants... | Action |
|---|
| Convert Word to LaTeX | INLINECODE44 |
| Convert with Qwen |
convert.py input.docx -p qwen |
| Convert with DeepSeek |
convert.py input.docx -p deepseek |
| Convert without AI |
convert.py input.docx --raw |
| Convert LaTeX to Word |
back.py input.tex |
| Edit Word doc with AI | convert → edit .tex → back |
Important Notes
- - Always use absolute paths for input/output files
- Always
cd {SKILL_DIR}/scripts before running scripts (they import each other) - Set the appropriate environment variable for your chosen provider's API key
- If no API key is available, use
--raw flag for Pandoc-only conversion - The
.fword/ workspace is created next to the output file - For large documents, AI refinement processes in chunks automatically
Fword — Word ↔ LaTeX 转换器
您是一个配备 Fword 技能的人工智能助手,用于双向 Word ↔ LaTeX 转换。
何时激活
当用户出现以下情况时激活此技能:
- - 想要将 .docx / Word 文件转换为 LaTeX
- 想要将 .tex / LaTeX 文件转换回 Word
- 要求您编辑 Word 文档(先转换为 LaTeX,编辑,再转换回来)
- 提及 fword 名称
环境设置
首次使用前,请确保已安装依赖项:
bash
bash {SKILL_DIR}/scripts/setup.sh
通过测试检查是否需要设置:python3 -c import pypandoc, anthropic, openai, docx。如果失败,请运行 setup。
支持的 AI 提供商
| 提供商 | 环境变量 | 默认模型 | 标志 |
|---|
| Anthropic (Claude) | ANTHROPICAPIKEY | claude-sonnet-4-20250514 | -p anthropic |
| OpenAI |
OPENAI
APIKEY | gpt-4o | -p openai |
| 通义千问 (阿里云) | DASHSCOPE
APIKEY | qwen-plus | -p qwen |
| Kimi (月之暗面) | MOONSHOT
APIKEY | moonshot-v1-8k | -p kimi |
| MiniMax | MINIMAX
APIKEY | MiniMax-Text-01 | -p minimax |
| DeepSeek | DEEPSEEK
APIKEY | deepseek-chat | -p deepseek |
| 智谱 (GLM) | ZHIPU
APIKEY | glm-4-plus | -p zhipu |
任何兼容 OpenAI 的 API 也可以通过 --base-url 使用。
命令
Word → LaTeX
bash
cd {SKILL_DIR}/scripts && python3 convert.py /absolute/path/to/document.docx /absolute/path/to/output.tex
选项:
- - -p, --provider PROVIDER — AI 提供商(默认:anthropic)
- --model MODEL — AI 模型(默认:提供商的默认模型)
- --api-key KEY — API 密钥(或设置提供商的环境变量)
- --base-url URL — 自定义 API 基础 URL
- --raw — 仅 Pandoc 转换,无 AI 优化(无需 API 密钥)
- --keep-intermediate — 将 Pandoc 的原始输出保存为 .raw.tex
示例:
bash
默认(Anthropic Claude)
cd {SKILL_DIR}/scripts && python3 convert.py /path/to/doc.docx
使用通义千问
cd {SKILL_DIR}/scripts && python3 convert.py /path/to/doc.docx -p qwen
使用 DeepSeek 并指定模型
cd {SKILL_DIR}/scripts && python3 convert.py /path/to/doc.docx -p deepseek --model deepseek-chat
仅 Pandoc(无 AI)
cd {SKILL_DIR}/scripts && python3 convert.py /path/to/doc.docx --raw
LaTeX → Word
bash
cd {SKILL_DIR}/scripts && python3 back.py /absolute/path/to/document.tex /absolute/path/to/output.docx
选项:
- - --reference-doc PATH — 使用特定的 Word 模板作为样式(覆盖工作区)
工作流程
标准转换
- 1. 对 .docx 文件运行 convert.py — 这会创建一个 .fword/ 工作区并输出 .tex
- .fword/ 工作区将原始文档存储为样式参考
- 根据需要编辑 LaTeX
- 运行 back.py 转换回来 — 它会自动找到工作区并恢复样式
AI 辅助编辑工作流程
当用户希望借助 AI 编辑 Word 文档时:
- 1. 转换:convert.py document.docx → 生成 document.tex
- 读取 .tex 文件并直接在 LaTeX 中进行所需的编辑
- 转换回来:back.py document.tex → 生成保留原始样式的 document.docx
快速参考
| 用户想要... | 操作 |
|---|
| 将 Word 转换为 LaTeX | convert.py input.docx |
| 使用通义千问转换 |
convert.py input.docx -p qwen |
| 使用 DeepSeek 转换 | convert.py input.docx -p deepseek |
| 无 AI 转换 | convert.py input.docx --raw |
| 将 LaTeX 转换为 Word | back.py input.tex |
| 使用 AI 编辑 Word 文档 | 转换 → 编辑 .tex → 转换回来 |
重要说明
- - 始终对输入/输出文件使用绝对路径
- 在运行脚本前始终 cd {SKILL_DIR}/scripts(它们会相互导入)
- 为您选择的提供商设置相应的环境变量以存储 API 密钥
- 如果没有可用的 API 密钥,请使用 --raw 标志进行仅 Pandoc 转换
- .fword/ 工作区会创建在输出文件旁边
- 对于大型文档,AI 优化会自动分块处理