Skip to content

dongzhigang13305312738-art/paper-skills / complete-example

complete-example

Verified

当用户明确要求"填充示例内容""生成示例""补充 LaTeX 示例"时使用。AI 增强版 LaTeX 示例智能生成器,实现 AI 与硬编码的有机融合:AI 做"语义理解"(分析章节主题、推理资源相关性、生成连贯叙述),硬编码做"结构保护"(格式验证、哈希校验、访问控制)。

scripts/formula_generator.py

View on GitHub
"""
FormulaGenerator - render LaTeX math blocks from formula placeholders.

We intentionally keep this deterministic: the placeholder already contains the
formula (or formulas). The generator only wraps it with the configured LaTeX
templates and performs basic label sanitization.
"""

from __future__ import annotations

from typing import Dict, Any
import re


def _sanitize_label(label: str) -> str:
    label = (label or "").strip()
    if not label:
        return "eq:formula"
    # Keep common LaTeX label characters.
    label = re.sub(r"[^a-zA-Z0-9:_-]+", "-", label)
    return label[:64]


class FormulaGenerator:
    def __init__(self, templates: Dict[str, str]):
        self.templates = templates

    def inline(self, formula: str) -> str:
        from .template_renderer import render_template
        tmpl = self.templates.get("inline_math", "${{formula}}$")
        return render_template(tmpl, {"formula": formula.strip()})

    def display(self, formula: str) -> str:
        from .template_renderer import render_template
        tmpl = self.templates.get("display_math")
        if not tmpl:
            return f"\\[\n{formula.strip()}\n\\]"
        return render_template(tmpl, {"formula": formula.strip()})

    def equation(self, formula: str, label: str) -> str:
        from .template_renderer import render_template
        tmpl = self.templates.get("equation")
        safe_label = _sanitize_label(label)
        if not tmpl:
            return f"\\begin{{equation}}\n  {formula.strip()}\n  \\label{{{safe_label}}}\n\\end{{equation}}"
        return render_template(tmpl, {"formula": formula.strip(), "label": safe_label})

    def align(self, formulas_raw: str) -> str:
        from .template_renderer import render_template
        tmpl = self.templates.get("align")
        # Placeholder suggests using literal '\\\\' to separate lines.
        parts = [p.strip() for p in re.split(r"\\\\+", formulas_raw) if p.strip()]
        joined = " \\\\\n        ".join(parts) if parts else formulas_raw.strip()
        if not tmpl:
            return f"\\begin{{align}}\n  {joined}\n\\end{{align}}"
        return render_template(tmpl, {"formulas": joined})
slack-gif-creatoranthropics/skillsKnowledge and utilities for creating animated GIFs optimized for Slack. Provides constraints, validation tools, and animation concepts. Use when users request animated GIFs for Slack like "make me a GIF of X doing Y for Slack."Stars: 198kUpdated Claude CodeCodexVerifiedInstall
ponytailDietrichGebert/ponytailLazy senior dev mode for any coding task: the smallest change that fully solves it, and a reply a busy human understands in one read.Stars: 194kUpdated Claude CodeCodexVerifiedInstall
ponytail-debtDietrichGebert/ponytailHarvest every shortcut: comment into one debt ledger, so deferrals get tracked instead of forgotten. One-shot report.Stars: 194kUpdated Claude CodeCodexVerifiedInstall
ponytail-debtDietrichGebert/ponytailList every `shortcut:` comment (and older `ponytail:` ones) as a debt ledger. One-shot report, changes nothing. Use for "ponytail debt", "what did ponytail defer", "list the shortcuts", /ponytail-debt.Stars: 194kUpdated Claude CodeCodexVerifiedInstall