Fix LaTeX math formula formatting in Obsidian markdown files
This skill fixes LaTeX math formula formatting in markdown files. It converts single-line formulas delimited by single $ to double $$ for proper display math rendering.
$ formula $ to display math $$ formula $$fixFormulaFormats (formulaFixer.ts)
├── read file content
├── apply regex pattern: /^(\s*)\$(\s*)$/gm
├── replace with: $1$$$$$2
└── return fixed content
fixFormulaFormatsInFile
├── read_file(inputPath)
├── fixFormulaFormats(content)
├── if changed: write_file(inputPath, content)
└── return: boolean (modified or not)
batchFixFormulaFormatsInFolder
├── get files in folder (.md, .txt)
├── for each file
│ └── fixFormulaFormatsInFile
└── return: { modifiedCount, errors[] }
The full TypeScript code is available in: formulaFixer.ts
This file contains:
fixFormulaFormats() - Core fix functionfixFormulaFormatsInFile() - Single file processingbatchFixFormulaFormatsInFolder() - Batch processingInput:
$
x^2 + y^2 = z^2
$
Output:
$$
x^2 + y^2 = z^2
$$
// Pattern: ^(\s*)\$(\s*)$
// Matches: start of line, optional whitespace, single $, optional whitespace, end of line
// Replacement: $1$$$$$2
// Result: optional whitespace + $$ + $$ + optional whitespace
[!WARNING] Regex Fragility The current line-based regex is highly brittle. It fails to properly handle inline math (
The value is $x=2$), single-line block math containing text ($x=2$), or multi-line single-dollar blocks.
To make this Agentic skill enterprise-grade, the AI should be instructed to replace this simple Regex with an Abstract Syntax Tree (AST) parser like remark-math, or write heavily context-aware regex patterns that track state to safely distinguish between inline $..$ and block $$..$$ requirements.
import {
fixFormulaFormats,
fixFormulaFormatsInFile,
batchFixFormulaFormatsInFolder,
} from "./formulaFixer";
// Fix formulas in a string
const content = `...
$
f(x) = \int_{-\infty}^{\infty} e^{-x^2} dx
$
...`;
const fixed = fixFormulaFormats(content);
// Fix formulas in a single file
await fixFormulaFormatsInFile(inputPath, reporter);
// Fix formulas in a folder
const result = await batchFixFormulaFormatsInFolder(folderPath, reporter);
// Returns: { modifiedCount: number, errors: { file: string, message: string }[] }
| Setting | Description |
| ------------------------ | ------------------------------- |
| enableBatchParallelism | Enable parallel processing |
| batchConcurrency | Number of concurrent operations |
| batchSize | Files per batch |
The batch function reports:
After adding wiki-links, cleanupLatexDelimiters() is called to fix LaTeX:
// From mermaidProcessor.ts
export function cleanupLatexDelimiters(content: string): string {
// 1. Protect escaped dollars
processed = processed.replace(/\\\$/g, placeholder);
// 2. Convert \( and \) to $
processed = processed.replace(/\\\(/g, '$').replace(/\\\)/g, '$');
// 3. Trim whitespace inside single $...$
processed = processed.replace(/\$\s*([^$]*?)\s*\$/g, ...);
// 4. Restore escaped dollars
processed = processed.replace(new RegExp(placeholder, 'g'), '$');
return processed;
}
This function handles:
\( formula \) to $ formula $$$...$$npx skills add Jacobinwwey/notemd-formula-fix下载完整 Skill 目录,包含 SKILL.md 及所有相关文件
Search for places (restaurants, cafes, etc.) via Google Places API proxy on localhost.
Interact with GitHub using the `gh` CLI. Use `gh issue`, `gh pr`, `gh run`, and `gh api` for issues, PRs, CI runs, and advanced queries.
Create or update AgentSkills. Use when designing, structuring, or packaging skills with scripts, references, and assets.
Start voice calls via the OpenClaw voice-call plugin.
Notion API for creating and managing pages, databases, and blocks.
Gemini CLI for one-shot Q&A, summaries, and generation.
Category:developer