Skip to content

brycewang-stanford/Auto-Empirical-Research-Skills / skills/35-bahayonghang-academic-writing-skills/skills/typst-paper

typst-paper

Verified

Typst academic paper assistant for existing `.typ` paper projects in English or Chinese. Use this skill whenever the user wants to compile, audit, or improve a Typst paper, including format checks, bibliography validation for BibTeX or Hayagriva, grammar/sentence/logic review, expression polishing, translation, title optimization, pseudocode review, algorithm block cleanup, de-AI editing, experiment-section review, table structure validation, three-line table generation, abstract structure diagnosis, or journal adaptation. Trigger even when the user only mentions one Typst file, one bibliography issue, one pseudocode block, one section rewrite, "three-line table", "check abstract", or "reformat for another journal". Also trigger when the user mentions ".typ files", "typst compile error", "typst export", "typst bibliography", `algorithm-figure`, `lovelace`, or `algorithmic` even without saying the word "Typst" explicitly.

FileKindSize
SKILL.mdskill md7.5 KB
agents/openai.yamlconfig330 B
evals/evals.jsonconfig7.3 KB
examples/bibliography-and-title.mdmarkdown509 B
examples/compile-and-format.mdmarkdown495 B
examples/expression-and-translation.mdmarkdown554 B
references/ABSTRACT_STRUCTURE.mdmarkdown4.9 KB
references/BEST_PRACTICES.mdmarkdown391 B
references/CITATION_STYLES.mdmarkdown4.2 KB
references/CITATION_VERIFICATION.mdmarkdown4.9 KB
references/COMMON_ERRORS.mdmarkdown5.3 KB
references/DEAI_GUIDE.mdmarkdown14.9 KB
references/JOURNAL_ABBREVIATIONS.mdmarkdown3.5 KB
references/JOURNAL_ADAPTATION_WORKFLOW.mdmarkdown3.6 KB
references/NUMBER_UNIT_GUIDE.mdmarkdown2.3 KB
references/REVIEWER_PERSPECTIVE.mdmarkdown4.9 KB
references/STYLE_GUIDE.mdmarkdown7.9 KB
references/TABLE_GUIDE.mdmarkdown2.6 KB
references/TEMPLATES.mdmarkdown2.5 KB
references/TERMINOLOGY.mdmarkdown9.9 KB
references/TRANSLATION_GUIDE.mdmarkdown11.4 KB
references/TYPST_SYNTAX.mdmarkdown9.8 KB
references/VENUES.mdmarkdown13.0 KB
references/WRITING_PHILOSOPHY.mdmarkdown6.7 KB
references/modules/ABSTRACT.mdmarkdown1.2 KB
references/modules/ADAPT.mdmarkdown1.3 KB
references/modules/BIBLIOGRAPHY.mdmarkdown1.3 KB
references/modules/CAPTION.mdmarkdown2.1 KB
references/modules/COMPILE.mdmarkdown1.2 KB
references/modules/DEAI.mdmarkdown2.8 KB
references/modules/EXPERIMENT.mdmarkdown3.8 KB
references/modules/EXPRESSION.mdmarkdown1.6 KB
references/modules/FORMAT.mdmarkdown1.1 KB
references/modules/GRAMMAR.mdmarkdown1.1 KB
references/modules/LOGIC.mdmarkdown5.4 KB
references/modules/PSEUDOCODE.mdmarkdown1.4 KB
references/modules/SENTENCES.mdmarkdown726 B
references/modules/TABLES.mdmarkdown1.3 KB
references/modules/TITLE.mdmarkdown7.3 KB
references/modules/TRANSLATION.mdmarkdown1.5 KB
references/modules/WORKFLOW.mdmarkdown706 B
scripts/analyze_abstract.pyscript17.3 KB
scripts/analyze_experiment.pyscript11.1 KB
scripts/analyze_grammar.pyscript3.6 KB
scripts/analyze_logic.pyscript18.8 KB
scripts/analyze_sentences.pyscript3.6 KB
scripts/check_format.pyscript11.3 KB
scripts/check_pseudocode.pyscript8.6 KB
scripts/check_references.pyscript14.1 KB
scripts/check_tables.pyscript9.8 KB
scripts/compile.pyscript8.1 KB
scripts/deai_batch.pyscript10.2 KB
scripts/deai_check.pyscript19.2 KB
scripts/generate_table.pyscript6.7 KB
scripts/improve_expression.pyscript3.2 KB
scripts/online_bib_verify.pyscript11.9 KB
scripts/optimize_title.pyscript16.9 KB
scripts/parsers.pyscript8.0 KB
scripts/translate_academic.pyscript4.2 KB
scripts/verify_bib.pyscript15.1 KB

scripts/check_pseudocode.py

View on GitHub
#!/usr/bin/env python3
"""
IEEE-aware pseudocode checker for Typst paper projects.

Usage:
    uv run python -B check_pseudocode.py main.typ
    uv run python -B check_pseudocode.py main.typ --venue ieee
    uv run python -B check_pseudocode.py main.typ --json
"""

from __future__ import annotations

import argparse
import json
import re
import sys
from pathlib import Path

COMMENT_PREFIX = "//"
CAPTION_RE = re.compile(r"caption\s*:\s*\[")
FIGURE_RE = re.compile(r"#figure\s*\(")
ALGORITHM_FIGURE_RE = re.compile(r"#algorithm-figure\s*\(")
ALGORITHMIC_IMPORT_RE = re.compile(r'@preview/algorithmic(?::[^"]+)?')
LOVELACE_IMPORT_RE = re.compile(r'@preview/lovelace(?::[^"]+)?')
STYLE_ALGORITHM_RE = re.compile(r"style-algorithm")
LINE_NUMBER_RE = re.compile(r"(?:line[- ]?numbers?|numbering)\s*:\s*true|line[- ]?numbers?")


class PseudocodeChecker:
    """Check Typst pseudocode blocks for IEEE-like output quality."""

    def __init__(self, typ_file: str, venue: str = "") -> None:
        self.typ_file = Path(typ_file).resolve()
        self.venue = venue.lower().strip()
        self.content = self.typ_file.read_text(encoding="utf-8")
        self.lines = self.content.splitlines()
        self.issues: list[dict] = []

    def _add_issue(self, line: int | None, severity: str, priority: str, message: str) -> None:
        self.issues.append(
            {
                "module": "PSEUDOCODE",
                "line": line,
                "severity": severity,
                "priority": priority,
                "message": message,
            }
        )

    def _line_for_token(self, token: str) -> int | None:
        for lineno, line in enumerate(self.lines, start=1):
            if token in line:
                return lineno
        return None

    def _find_parenthesized_blocks(self, pattern: re.Pattern[str]) -> list[tuple[int, int, str]]:
        blocks: list[tuple[int, int, str]] = []
        for match in pattern.finditer(self.content):
            open_idx = match.end() - 1
            depth = 0
            end_idx = open_idx
            for index in range(open_idx, len(self.content)):
                char = self.content[index]
                if char == "(":
                    depth += 1
                elif char == ")":
                    depth -= 1
                    if depth == 0:
                        end_idx = index
                        break
            start_line = self.content[: match.start()].count("\n") + 1
            end_line = self.content[:end_idx].count("\n") + 1
            blocks.append((start_line, end_line, self.content[match.start() : end_idx + 1]))
        return blocks

    def _word_count(self, text: str) -> int:
        return len(re.findall(r"[A-Za-z0-9_\-\u4e00-\u9fff]+", text))

    def check_algorithmic_blocks(self) -> None:
        uses_algorithmic = bool(ALGORITHMIC_IMPORT_RE.search(self.content)) or bool(
            ALGORITHM_FIGURE_RE.search(self.content)
        )
        if not uses_algorithmic:
            return

        if not STYLE_ALGORITHM_RE.search(self.content):
            self._add_issue(
                self._line_for_token("style-algorithm"),
                "Major",
                "P1",
                "algorithmic blocks were detected without style-algorithm. IEEE-like output is more "
                "stable when the package styling hook is applied explicitly.",
            )

        for start_line, _end_line, text in self._find_parenthesized_blocks(ALGORITHM_FIGURE_RE):
            if CAPTION_RE.search(text) is None:
                self._add_issue(
                    start_line,
                    "Major",
                    "P1",
                    "algorithm-figure is missing a caption. IEEE-like pseudocode should use a figure "
                    "caption so the block can be referenced consistently.",
                )
            if LINE_NUMBER_RE.search(text) is None:
                self._add_issue(
                    start_line,
                    "Minor",
                    "P2",
                    "Line numbers were not detected in algorithm-figure. They are recommended for "
                    "IEEE-like review but not required.",
                )

            for local_line, raw_line in enumerate(text.splitlines(), start=start_line):
                stripped = raw_line.strip()
                if "comment(" not in stripped and "//" not in stripped:
                    continue
                payload = stripped.split("comment(", 1)[-1].rstrip(")")
                if "//" in stripped:
                    payload = stripped.split("//", 1)[-1]
                if self._word_count(payload) > 16:
                    self._add_issue(
                        local_line,
                        "Minor",
                        "P2",
                        "A pseudocode comment is unusually long. Keep comments short and move "
                        "paragraph-level explanation back into the main text.",
                    )
                    break

    def check_lovelace_blocks(self) -> None:
        if not LOVELACE_IMPORT_RE.search(self.content):
            return

        has_wrapper = bool(
            FIGURE_RE.search(self.content) or ALGORITHM_FIGURE_RE.search(self.content)
        )
        if self.venue == "ieee" and not has_wrapper:
            self._add_issue(
                self._line_for_token("lovelace"),
                "Critical",
                "P0",
                "lovelace output is not wrapped in a figure-like container. IEEE-like submissions "
                "should wrap free-form pseudocode in #figure(...) with a caption.",
            )

        if has_wrapper and CAPTION_RE.search(self.content) is None:
            self._add_issue(
                self._line_for_token("lovelace"),
                "Major",
                "P1",
                "A lovelace-based pseudocode block appears to be wrapped without a caption. Add a "
                "caption for IEEE-like figure handling.",
            )

    def check_prose_length(self) -> None:
        figure_blocks = self._find_parenthesized_blocks(
            FIGURE_RE
        ) + self._find_parenthesized_blocks(ALGORITHM_FIGURE_RE)
        for start_line, _end_line, text in figure_blocks:
            if "algorithm" not in text.lower() and "lovelace" not in self.content.lower():
                continue
            for local_line, raw_line in enumerate(text.splitlines(), start=start_line):
                stripped = raw_line.strip()
                if not stripped or stripped.startswith("//") or "caption:" in stripped:
                    continue
                if self._word_count(stripped) > 24:
                    self._add_issue(
                        local_line,
                        "Minor",
                        "P2",
                        "A pseudocode line contains prose-length explanation. Prefer short algorithmic "
                        "steps and move long explanation into the surrounding paragraph.",
                    )
                    return

    def check(self) -> list[dict]:
        self.issues = []
        self.check_algorithmic_blocks()
        self.check_lovelace_blocks()
        self.check_prose_length()
        return sorted(self.issues, key=lambda item: (item.get("line") or 0, item["severity"]))

    def generate_report(self, issues: list[dict]) -> str:
        if not issues:
            return ""
        lines = []
        for issue in issues:
            line_part = f"(Line {issue['line']}) " if issue.get("line") else ""
            lines.append(
                f"{COMMENT_PREFIX} PSEUDOCODE {line_part}[Severity: {issue['severity']}] "
                f"[Priority: {issue['priority']}]: {issue['message']}"
            )
        return "\n".join(lines)


def main() -> int:
    parser = argparse.ArgumentParser(description="IEEE-aware pseudocode checker for Typst papers")
    parser.add_argument("file", help="Source .typ file to check")
    parser.add_argument(
        "--venue",
        default="",
        choices=["", "ieee", "acm", "springer", "neurips", "cvpr"],
        help="Venue context used for stricter checks",
    )
    parser.add_argument("--json", action="store_true", help="Output JSON format")
    args = parser.parse_args()

    path = Path(args.file)
    if not path.exists():
        print(f"[ERROR] File not found: {args.file}", file=sys.stderr)
        return 1

    checker = PseudocodeChecker(str(path), venue=args.venue)
    issues = checker.check()

    if args.json:
        print(json.dumps(issues, indent=2, ensure_ascii=False))
    else:
        output = checker.generate_report(issues)
        if output:
            print(output)

    return 1 if any(issue["severity"] == "Critical" for issue in issues) else 0


if __name__ == "__main__":
    sys.exit(main())
rea-analysis-optimizationmorluto/reaOptimize REA providers and shared analysis workflows for agent context, latency, CPU, and memory while preserving correctness and Evidence. Use for analysis bottlenecks and cache or query design; CI/test-suite optimization belongs to rea-ci-tests-audit.Stars: 472kUpdated Claude CodeCodexVerifiedInstall
rea-ci-tests-auditmorluto/reaAudit REA CI and test suites for correctness, fixture drift, false passes, and measured performance; use for suite or workflow investigations and efficiency changes, rather than ordinary feature testing or a single test failure.Stars: 472kUpdated Claude CodeCodexVerifiedInstall
rea-tool-designmorluto/reaAudit, investigate, design, or change REA investigation tools, CLI/MCP contracts, provider capabilities, and Evidence semantics.Stars: 472kUpdated Claude CodeCodexVerifiedInstall
ponytail-auditDietrichGebert/ponytailQuality audit of the whole repo: bugs, security, real load, missing tests, speed, and what to delete. Most important first.Stars: 194kUpdated Claude CodeCodexVerifiedInstall