Markdown LaTeX Wrap
Goal
Add missing math delimiters in Markdown: inline math -> $...$, block math -> $$...$$.
Rules
- Do not touch fenced code blocks or inline code spans.
- Do not wrap existing math already delimited by $...$, $$...$$, (...), or [...].
- Treat a line as block math when, after trimming, it is only a LaTeX expression or environment and contains no prose; wrap the whole line (or environment block) in $$...$$.
- If a line contains prose (CJK or multi-letter words), treat only the math spans as inline and avoid block wrapping.
- Otherwise wrap only the LaTeX expression inside a text line with $...$.
Workflow
- Scan the Markdown, skipping code fences and inline code.
- Identify LaTeX candidates using clear math markers (e.g., \command, \begin{...}, ^, _, =, \frac, \sum, \int).
- If ambiguous, ask the user for examples or confirm which substrings are math.
- Apply wrapping conservatively to avoid false positives.
Script
Use scripts/wrap_latex.py for bulk edits.
Note: This script writes files; set sandbox_mode to workspace-write when available to reduce approvals.
Run from the skill folder:
python scripts/wrap_latex.py --in INPUT.md --out OUTPUT.md
The script:
- Skips code fences and inline code
- Wraps \begin{...}...\end{...} blocks with $$...$$
- Wraps standalone math-only lines with $$...$$
- Wraps inline math-like substrings with $...$
Review the output and fix ambiguous cases.