LaTeX Formatting Set up and manage LaTeX formatting for academic papers. Input - — Action: , , - — Venue name (for ) or file path (for / ) Scripts Pre-submission format checker Checks: word count, required sections, TODO markers, anonymization, mismatched environments, content stats. Validate citations and references Clean LaTeX text (fix special characters) Replaces special/non-UTF8 characters with LaTeX equivalents, skips math environments. Key flags: , Auto-fix after checking Runs checks then applies clean latex.py fixes, writing to . References - Venue specs, project structure, packages,…

,\n '>': r'$>

LaTeX Formatting Set up and manage LaTeX formatting for academic papers. Input - — Action: , , - — Venue name (for ) or file path (for / ) Scripts Pre-submission format checker Checks: word count, required sections, TODO markers, anonymization, mismatched environments, content stats. Validate citations and references Clean LaTeX text (fix special characters) Replaces special/non-UTF8 characters with LaTeX equivalents, skips math environments. Key flags: , Auto-fix after checking Runs checks then applies clean latex.py fixes, writing to . References - Venue specs, project structure, packages,…

,\n '\\u2264': r'$\\leq

LaTeX Formatting Set up and manage LaTeX formatting for academic papers. Input - — Action: , , - — Venue name (for ) or file path (for / ) Scripts Pre-submission format checker Checks: word count, required sections, TODO markers, anonymization, mismatched environments, content stats. Validate citations and references Clean LaTeX text (fix special characters) Replaces special/non-UTF8 characters with LaTeX equivalents, skips math environments. Key flags: , Auto-fix after checking Runs checks then applies clean latex.py fixes, writing to . References - Venue specs, project structure, packages,…

, # ≤\n '\\u2265': r'$\\geq

LaTeX Formatting Set up and manage LaTeX formatting for academic papers. Input - — Action: , , - — Venue name (for ) or file path (for / ) Scripts Pre-submission format checker Checks: word count, required sections, TODO markers, anonymization, mismatched environments, content stats. Validate citations and references Clean LaTeX text (fix special characters) Replaces special/non-UTF8 characters with LaTeX equivalents, skips math environments. Key flags: , Auto-fix after checking Runs checks then applies clean latex.py fixes, writing to . References - Venue specs, project structure, packages,…

, # ≥\n '\\u2260': r'$\\neq

LaTeX Formatting Set up and manage LaTeX formatting for academic papers. Input - — Action: , , - — Venue name (for ) or file path (for / ) Scripts Pre-submission format checker Checks: word count, required sections, TODO markers, anonymization, mismatched environments, content stats. Validate citations and references Clean LaTeX text (fix special characters) Replaces special/non-UTF8 characters with LaTeX equivalents, skips math environments. Key flags: , Auto-fix after checking Runs checks then applies clean latex.py fixes, writing to . References - Venue specs, project structure, packages,…

, # ≠\n '\\u00b1': r'$\\pm

LaTeX Formatting Set up and manage LaTeX formatting for academic papers. Input - — Action: , , - — Venue name (for ) or file path (for / ) Scripts Pre-submission format checker Checks: word count, required sections, TODO markers, anonymization, mismatched environments, content stats. Validate citations and references Clean LaTeX text (fix special characters) Replaces special/non-UTF8 characters with LaTeX equivalents, skips math environments. Key flags: , Auto-fix after checking Runs checks then applies clean latex.py fixes, writing to . References - Venue specs, project structure, packages,…

, # ±\n '\\u00d7': r'$\\times

LaTeX Formatting Set up and manage LaTeX formatting for academic papers. Input - — Action: , , - — Venue name (for ) or file path (for / ) Scripts Pre-submission format checker Checks: word count, required sections, TODO markers, anonymization, mismatched environments, content stats. Validate citations and references Clean LaTeX text (fix special characters) Replaces special/non-UTF8 characters with LaTeX equivalents, skips math environments. Key flags: , Auto-fix after checking Runs checks then applies clean latex.py fixes, writing to . References - Venue specs, project structure, packages,…

, # ×\n '\\u00f7': r'$\\div

LaTeX Formatting Set up and manage LaTeX formatting for academic papers. Input - — Action: , , - — Venue name (for ) or file path (for / ) Scripts Pre-submission format checker Checks: word count, required sections, TODO markers, anonymization, mismatched environments, content stats. Validate citations and references Clean LaTeX text (fix special characters) Replaces special/non-UTF8 characters with LaTeX equivalents, skips math environments. Key flags: , Auto-fix after checking Runs checks then applies clean latex.py fixes, writing to . References - Venue specs, project structure, packages,…

, # ÷\n '\\u00b0': r'$^{\\circ}

LaTeX Formatting Set up and manage LaTeX formatting for academic papers. Input - — Action: , , - — Venue name (for ) or file path (for / ) Scripts Pre-submission format checker Checks: word count, required sections, TODO markers, anonymization, mismatched environments, content stats. Validate citations and references Clean LaTeX text (fix special characters) Replaces special/non-UTF8 characters with LaTeX equivalents, skips math environments. Key flags: , Auto-fix after checking Runs checks then applies clean latex.py fixes, writing to . References - Venue specs, project structure, packages,…

, # °\n '\\u221e': r'$\\infty

LaTeX Formatting Set up and manage LaTeX formatting for academic papers. Input - — Action: , , - — Venue name (for ) or file path (for / ) Scripts Pre-submission format checker Checks: word count, required sections, TODO markers, anonymization, mismatched environments, content stats. Validate citations and references Clean LaTeX text (fix special characters) Replaces special/non-UTF8 characters with LaTeX equivalents, skips math environments. Key flags: , Auto-fix after checking Runs checks then applies clean latex.py fixes, writing to . References - Venue specs, project structure, packages,…

, # ∞\n '\\u221a': r'$\\sqrt{}

LaTeX Formatting Set up and manage LaTeX formatting for academic papers. Input - — Action: , , - — Venue name (for ) or file path (for / ) Scripts Pre-submission format checker Checks: word count, required sections, TODO markers, anonymization, mismatched environments, content stats. Validate citations and references Clean LaTeX text (fix special characters) Replaces special/non-UTF8 characters with LaTeX equivalents, skips math environments. Key flags: , Auto-fix after checking Runs checks then applies clean latex.py fixes, writing to . References - Venue specs, project structure, packages,…

, # √\n '\\u2211': r'$\\sum

LaTeX Formatting Set up and manage LaTeX formatting for academic papers. Input - — Action: , , - — Venue name (for ) or file path (for / ) Scripts Pre-submission format checker Checks: word count, required sections, TODO markers, anonymization, mismatched environments, content stats. Validate citations and references Clean LaTeX text (fix special characters) Replaces special/non-UTF8 characters with LaTeX equivalents, skips math environments. Key flags: , Auto-fix after checking Runs checks then applies clean latex.py fixes, writing to . References - Venue specs, project structure, packages,…

, # ∑\n '\\u220f': r'$\\prod

LaTeX Formatting Set up and manage LaTeX formatting for academic papers. Input - — Action: , , - — Venue name (for ) or file path (for / ) Scripts Pre-submission format checker Checks: word count, required sections, TODO markers, anonymization, mismatched environments, content stats. Validate citations and references Clean LaTeX text (fix special characters) Replaces special/non-UTF8 characters with LaTeX equivalents, skips math environments. Key flags: , Auto-fix after checking Runs checks then applies clean latex.py fixes, writing to . References - Venue specs, project structure, packages,…

, # ∏\n '|': r'\\textbar{}',\n '\\u2208': r'$\\in

LaTeX Formatting Set up and manage LaTeX formatting for academic papers. Input - — Action: , , - — Venue name (for ) or file path (for / ) Scripts Pre-submission format checker Checks: word count, required sections, TODO markers, anonymization, mismatched environments, content stats. Validate citations and references Clean LaTeX text (fix special characters) Replaces special/non-UTF8 characters with LaTeX equivalents, skips math environments. Key flags: , Auto-fix after checking Runs checks then applies clean latex.py fixes, writing to . References - Venue specs, project structure, packages,…

, # ∈\n '\\u2209': r'$\\notin

LaTeX Formatting Set up and manage LaTeX formatting for academic papers. Input - — Action: , , - — Venue name (for ) or file path (for / ) Scripts Pre-submission format checker Checks: word count, required sections, TODO markers, anonymization, mismatched environments, content stats. Validate citations and references Clean LaTeX text (fix special characters) Replaces special/non-UTF8 characters with LaTeX equivalents, skips math environments. Key flags: , Auto-fix after checking Runs checks then applies clean latex.py fixes, writing to . References - Venue specs, project structure, packages,…

, # ∉\n '\\u2200': r'$\\forall

LaTeX Formatting Set up and manage LaTeX formatting for academic papers. Input - — Action: , , - — Venue name (for ) or file path (for / ) Scripts Pre-submission format checker Checks: word count, required sections, TODO markers, anonymization, mismatched environments, content stats. Validate citations and references Clean LaTeX text (fix special characters) Replaces special/non-UTF8 characters with LaTeX equivalents, skips math environments. Key flags: , Auto-fix after checking Runs checks then applies clean latex.py fixes, writing to . References - Venue specs, project structure, packages,…

, # ∀\n '\\u2203': r'$\\exists

LaTeX Formatting Set up and manage LaTeX formatting for academic papers. Input - — Action: , , - — Venue name (for ) or file path (for / ) Scripts Pre-submission format checker Checks: word count, required sections, TODO markers, anonymization, mismatched environments, content stats. Validate citations and references Clean LaTeX text (fix special characters) Replaces special/non-UTF8 characters with LaTeX equivalents, skips math environments. Key flags: , Auto-fix after checking Runs checks then applies clean latex.py fixes, writing to . References - Venue specs, project structure, packages,…

, # ∃\n '\\u2205': r'$\\emptyset

LaTeX Formatting Set up and manage LaTeX formatting for academic papers. Input - — Action: , , - — Venue name (for ) or file path (for / ) Scripts Pre-submission format checker Checks: word count, required sections, TODO markers, anonymization, mismatched environments, content stats. Validate citations and references Clean LaTeX text (fix special characters) Replaces special/non-UTF8 characters with LaTeX equivalents, skips math environments. Key flags: , Auto-fix after checking Runs checks then applies clean latex.py fixes, writing to . References - Venue specs, project structure, packages,…

, # ∅\n '\\u200b': '', # zero width space\n '\\u202f': ' ', # narrow no-break space\n}\n\n# Non-UTF8 characters to LaTeX-safe replacements\nNON_UTF8_CHARS = {\n '\\u2013': '--', # –\n '\\u2019': \"'\", # '\n '\\u2018': \"`\", # '\n '\\u201c': \"``\", # \"\n '\\u201d': \"''\", # \"\n '\\u00b2': r'$^2

LaTeX Formatting Set up and manage LaTeX formatting for academic papers. Input - — Action: , , - — Venue name (for ) or file path (for / ) Scripts Pre-submission format checker Checks: word count, required sections, TODO markers, anonymization, mismatched environments, content stats. Validate citations and references Clean LaTeX text (fix special characters) Replaces special/non-UTF8 characters with LaTeX equivalents, skips math environments. Key flags: , Auto-fix after checking Runs checks then applies clean latex.py fixes, writing to . References - Venue specs, project structure, packages,…

, # ²\n '\\u00b3': r'$^3

LaTeX Formatting Set up and manage LaTeX formatting for academic papers. Input - — Action: , , - — Venue name (for ) or file path (for / ) Scripts Pre-submission format checker Checks: word count, required sections, TODO markers, anonymization, mismatched environments, content stats. Validate citations and references Clean LaTeX text (fix special characters) Replaces special/non-UTF8 characters with LaTeX equivalents, skips math environments. Key flags: , Auto-fix after checking Runs checks then applies clean latex.py fixes, writing to . References - Venue specs, project structure, packages,…

, # ³\n '\\u00bc': r'$\\frac{1}{4}

LaTeX Formatting Set up and manage LaTeX formatting for academic papers. Input - — Action: , , - — Venue name (for ) or file path (for / ) Scripts Pre-submission format checker Checks: word count, required sections, TODO markers, anonymization, mismatched environments, content stats. Validate citations and references Clean LaTeX text (fix special characters) Replaces special/non-UTF8 characters with LaTeX equivalents, skips math environments. Key flags: , Auto-fix after checking Runs checks then applies clean latex.py fixes, writing to . References - Venue specs, project structure, packages,…

, # ¼\n '\\u00bd': r'$\\frac{1}{2}

LaTeX Formatting Set up and manage LaTeX formatting for academic papers. Input - — Action: , , - — Venue name (for ) or file path (for / ) Scripts Pre-submission format checker Checks: word count, required sections, TODO markers, anonymization, mismatched environments, content stats. Validate citations and references Clean LaTeX text (fix special characters) Replaces special/non-UTF8 characters with LaTeX equivalents, skips math environments. Key flags: , Auto-fix after checking Runs checks then applies clean latex.py fixes, writing to . References - Venue specs, project structure, packages,…

, # ½\n '\\u00be': r'$\\frac{3}{4}

LaTeX Formatting Set up and manage LaTeX formatting for academic papers. Input - — Action: , , - — Venue name (for ) or file path (for / ) Scripts Pre-submission format checker Checks: word count, required sections, TODO markers, anonymization, mismatched environments, content stats. Validate citations and references Clean LaTeX text (fix special characters) Replaces special/non-UTF8 characters with LaTeX equivalents, skips math environments. Key flags: , Auto-fix after checking Runs checks then applies clean latex.py fixes, writing to . References - Venue specs, project structure, packages,…

, # ¾\n '\\u2206': r'$\\Delta

LaTeX Formatting Set up and manage LaTeX formatting for academic papers. Input - — Action: , , - — Venue name (for ) or file path (for / ) Scripts Pre-submission format checker Checks: word count, required sections, TODO markers, anonymization, mismatched environments, content stats. Validate citations and references Clean LaTeX text (fix special characters) Replaces special/non-UTF8 characters with LaTeX equivalents, skips math environments. Key flags: , Auto-fix after checking Runs checks then applies clean latex.py fixes, writing to . References - Venue specs, project structure, packages,…

, # ∆\n '\\u2207': r'$\\nabla

LaTeX Formatting Set up and manage LaTeX formatting for academic papers. Input - — Action: , , - — Venue name (for ) or file path (for / ) Scripts Pre-submission format checker Checks: word count, required sections, TODO markers, anonymization, mismatched environments, content stats. Validate citations and references Clean LaTeX text (fix special characters) Replaces special/non-UTF8 characters with LaTeX equivalents, skips math environments. Key flags: , Auto-fix after checking Runs checks then applies clean latex.py fixes, writing to . References - Venue specs, project structure, packages,…

, # ∇\n '\\u2202': r'$\\partial

LaTeX Formatting Set up and manage LaTeX formatting for academic papers. Input - — Action: , , - — Venue name (for ) or file path (for / ) Scripts Pre-submission format checker Checks: word count, required sections, TODO markers, anonymization, mismatched environments, content stats. Validate citations and references Clean LaTeX text (fix special characters) Replaces special/non-UTF8 characters with LaTeX equivalents, skips math environments. Key flags: , Auto-fix after checking Runs checks then applies clean latex.py fixes, writing to . References - Venue specs, project structure, packages,…

, # ∂\n '\\u2014': '---', # —\n '\\u2026': r'\\ldots{}', # …\n '\\u00e9': r\"\\'e\", # é\n '\\u00e8': r\"\\`e\", # è\n '\\u00fc': r'\\\"u', # ü\n '\\u00f6': r'\\\"o', # ö\n '\\u00e4': r'\\\"a', # ä\n}\n\nTABLE_CHARS = {\n '>': r'$>

LaTeX Formatting Set up and manage LaTeX formatting for academic papers. Input - — Action: , , - — Venue name (for ) or file path (for / ) Scripts Pre-submission format checker Checks: word count, required sections, TODO markers, anonymization, mismatched environments, content stats. Validate citations and references Clean LaTeX text (fix special characters) Replaces special/non-UTF8 characters with LaTeX equivalents, skips math environments. Key flags: , Auto-fix after checking Runs checks then applies clean latex.py fixes, writing to . References - Venue specs, project structure, packages,…

,\n '\u003c': r'$\u003c

LaTeX Formatting Set up and manage LaTeX formatting for academic papers. Input - — Action: , , - — Venue name (for ) or file path (for / ) Scripts Pre-submission format checker Checks: word count, required sections, TODO markers, anonymization, mismatched environments, content stats. Validate citations and references Clean LaTeX text (fix special characters) Replaces special/non-UTF8 characters with LaTeX equivalents, skips math environments. Key flags: , Auto-fix after checking Runs checks then applies clean latex.py fixes, writing to . References - Venue specs, project structure, packages,…

,\n '=': r'$=

LaTeX Formatting Set up and manage LaTeX formatting for academic papers. Input - — Action: , , - — Venue name (for ) or file path (for / ) Scripts Pre-submission format checker Checks: word count, required sections, TODO markers, anonymization, mismatched environments, content stats. Validate citations and references Clean LaTeX text (fix special characters) Replaces special/non-UTF8 characters with LaTeX equivalents, skips math environments. Key flags: , Auto-fix after checking Runs checks then applies clean latex.py fixes, writing to . References - Venue specs, project structure, packages,…

,\n '|': r'\\textbar{}',\n}\n\n# Simplified math pattern (stdlib re, no recursion)\n# Matches: $...$, $...$, \\(...\\), \\[...\\], \\begin{equation}...\\end{equation},\n# \\begin{align}...\\end{align}, \\begin{figure}...\\end{figure}\nMATH_ENVS = [\n (r'\\$\\

LaTeX Formatting Set up and manage LaTeX formatting for academic papers. Input - — Action: , , - — Venue name (for ) or file path (for / ) Scripts Pre-submission format checker Checks: word count, required sections, TODO markers, anonymization, mismatched environments, content stats. Validate citations and references Clean LaTeX text (fix special characters) Replaces special/non-UTF8 characters with LaTeX equivalents, skips math environments. Key flags: , Auto-fix after checking Runs checks then applies clean latex.py fixes, writing to . References - Venue specs, project structure, packages,…

, r'\\$\\

LaTeX Formatting Set up and manage LaTeX formatting for academic papers. Input - — Action: , , - — Venue name (for ) or file path (for / ) Scripts Pre-submission format checker Checks: word count, required sections, TODO markers, anonymization, mismatched environments, content stats. Validate citations and references Clean LaTeX text (fix special characters) Replaces special/non-UTF8 characters with LaTeX equivalents, skips math environments. Key flags: , Auto-fix after checking Runs checks then applies clean latex.py fixes, writing to . References - Venue specs, project structure, packages,…

), # $...$\n (r'(?\u003c!\\$)\\$(?!\\$)', r'(?\u003c!\\$)\\$(?!\\$)'), # $...$\n (r'\\\\\\(', r'\\\\\\)'), # \\(...\\)\n (r'\\\\\\[', r'\\\\\\]'), # \\[...\\]\n]\n\nLATEX_ENV_NAMES = [\n 'equation', 'equation*', 'align', 'align*', 'gather', 'gather*',\n 'math', 'displaymath', 'figure', 'figure*', 'lstlisting',\n 'tabular', 'tabular*', 'array',\n]\n\nSKIP_COMMANDS = [r'\\\\ref\\{[^}]*\\}', r'\\\\label\\{[^}]*\\}', r'\\\\autoref\\{[^}]*\\}',\n r'\\\\cite[a-z]*\\{[^}]*\\}', r'\\\\url\\{[^}]*\\}', r'\\\\href\\{[^}]*\\}\\{[^}]*\\}']\n\n\ndef build_skip_pattern() -> re.Pattern:\n \"\"\"Build a combined regex pattern for all math/skip regions.\"\"\"\n patterns = []\n # Comments (% to end of line, unless escaped)\n patterns.append(r'(?\u003c!\\\\)%[^\\n]*')\n # Command definitions (contain # for parameters)\n patterns.append(r'\\\\(?:(?:re)?newcommand|providecommand|DeclareMathOperator)\\*?'\n r'(?:\\{[^}]*\\}|\\[[^\\]]*\\])*\\{[^}]*\\}')\n patterns.append(r'\\\\def\\\\[a-zA-Z@]+[^{]*\\{[^}]*\\}')\n # Dollar signs\n patterns.append(r'\\$\\$.*?\\$\\

LaTeX Formatting Set up and manage LaTeX formatting for academic papers. Input - — Action: , , - — Venue name (for ) or file path (for / ) Scripts Pre-submission format checker Checks: word count, required sections, TODO markers, anonymization, mismatched environments, content stats. Validate citations and references Clean LaTeX text (fix special characters) Replaces special/non-UTF8 characters with LaTeX equivalents, skips math environments. Key flags: , Auto-fix after checking Runs checks then applies clean latex.py fixes, writing to . References - Venue specs, project structure, packages,…

)\n patterns.append(r'(?\u003c!\\$)\\$(?!\\$).*?(?\u003c!\\$)\\$(?!\\$)')\n # Escaped delimiters\n patterns.append(r'\\\\\\(.*?\\\\\\)')\n patterns.append(r'\\\\\\[.*?\\\\\\]')\n # Named environments\n for env in LATEX_ENV_NAMES:\n esc = re.escape(env)\n patterns.append(rf'\\\\begin\\{{{esc}\\}}.*?\\\\end\\{{{esc}\\}}')\n # Skip commands\n patterns.extend(SKIP_COMMANDS)\n\n return re.compile('|'.join(patterns), re.DOTALL)\n\n\nSKIP_RE = build_skip_pattern()\n\n\ndef replace_special_latex_chars(text: str) -> str:\n \"\"\"Replace special characters in text (non-math) with LaTeX equivalents.\"\"\"\n chars_pattern = '|'.join(re.escape(c) for c in CHARS.keys())\n pattern = re.compile(rf'(?\u003c!\\\\)({chars_pattern})')\n return pattern.sub(lambda m: CHARS[m.group(1)], text)\n\n\ndef replace_non_utf8_chars(text: str) -> str:\n \"\"\"Replace non-UTF8 characters with LaTeX-safe equivalents.\"\"\"\n for char, replacement in NON_UTF8_CHARS.items():\n text = text.replace(char, replacement)\n return text\n\n\ndef process_latex_text_and_math(text: str, process_text=None, process_math=None) -> str:\n \"\"\"Process text and math regions separately.\n\n Applies process_text to non-math regions and process_math to math regions.\n \"\"\"\n if process_text is None:\n process_text = replace_special_latex_chars\n if process_math is None:\n process_math = lambda x: x\n\n result = []\n last_end = 0\n\n for match in SKIP_RE.finditer(text):\n # Process non-math text before this match\n non_math = text[last_end:match.start()]\n result.append(process_text(non_math))\n # Keep math region as-is (or apply process_math)\n result.append(process_math(match.group()))\n last_end = match.end()\n\n # Process remaining text after last match\n result.append(process_text(text[last_end:]))\n return \"\".join(result)\n\n\ndef escape_table_chars(text: str) -> str:\n \"\"\"Escape special characters in table cells.\"\"\"\n pattern = re.compile('|'.join(re.escape(k) for k in TABLE_CHARS.keys()))\n return pattern.sub(lambda m: TABLE_CHARS[m.group()], text)\n\n\ndef escape_special_chars_in_table(table: str,\n begin: str = r'\\begin{tabular}',\n end: str = r'\\end{tabular}') -> str:\n \"\"\"Apply character escaping to the tabular content of a LaTeX table.\"\"\"\n if begin not in table:\n return table\n if end not in table:\n return table\n before, rest = table.split(begin, 1)\n tabular, after = rest.split(end, 1)\n tabular = process_latex_text_and_math(tabular, escape_table_chars)\n return before + begin + tabular + end + after\n\n\ndef clean_latex_file(content: str, tables_only: bool = False) -> str:\n \"\"\"Clean a full LaTeX file content.\"\"\"\n if tables_only:\n # Only clean table environments\n parts = re.split(r'(\\\\begin\\{tabular\\}.*?\\\\end\\{tabular\\})', content, flags=re.DOTALL)\n result = []\n for part in parts:\n if part.startswith(r'\\begin{tabular}'):\n result.append(escape_special_chars_in_table(part))\n else:\n result.append(part)\n return ''.join(result)\n\n # Full cleaning\n content = replace_non_utf8_chars(content)\n content = process_latex_text_and_math(content)\n return content\n\n\ndef main():\n parser = argparse.ArgumentParser(description=\"Clean and sanitize LaTeX text\")\n parser.add_argument(\"--input\", required=True, help=\"Input .tex file\")\n parser.add_argument(\"--output\", \"-o\", help=\"Output .tex file (default: stdout)\")\n parser.add_argument(\"--dry-run\", action=\"store_true\", help=\"Show changes without writing\")\n parser.add_argument(\"--tables-only\", action=\"store_true\", help=\"Only clean table environments\")\n args = parser.parse_args()\n\n with open(args.input, encoding=\"utf-8\", errors=\"replace\") as f:\n content = f.read()\n\n cleaned = clean_latex_file(content, tables_only=args.tables_only)\n\n if args.dry_run:\n # Show diff summary\n orig_lines = content.splitlines()\n new_lines = cleaned.splitlines()\n changes = 0\n for i, (old, new) in enumerate(zip(orig_lines, new_lines)):\n if old != new:\n changes += 1\n if changes \u003c= 20:\n print(f\"Line {i+1}:\")\n print(f\" - {old[:100]}\")\n print(f\" + {new[:100]}\")\n if changes > 20:\n print(f\"... and {changes - 20} more changes\")\n print(f\"\\nTotal lines changed: {changes}\")\n return\n\n if args.output:\n with open(args.output, \"w\", encoding=\"utf-8\") as f:\n f.write(cleaned)\n print(f\"Cleaned file written to {args.output}\", file=sys.stderr)\n else:\n sys.stdout.write(cleaned)\n\n\nif __name__ == \"__main__\":\n main()\n","content_type":"text/x-python; charset=utf-8","language":"python","size":8460,"content_sha256":"cb704de50d1474ed4b73ef78bd5204d908abd521dd215ab196e68cb87495a0d4"},{"filename":"scripts/latex_checker.py","content":"#!/usr/bin/env python3\n\"\"\"Pre-submission LaTeX format checker.\n\nValidates a LaTeX paper against common venue requirements:\npage count, anonymization, required sections, formatting issues.\n\nSelf-contained: uses only stdlib.\n\nUsage:\n python latex_checker.py paper/main.tex\n python latex_checker.py paper/main.tex --venue neurips --page-limit 9\n python latex_checker.py paper/main.tex --check-anon\n\"\"\"\n\nimport argparse\nimport os\nimport re\nimport sys\n\n\nVENUE_LIMITS = {\n \"neurips\": {\"pages\": 9, \"columns\": 1, \"anonymous\": True},\n \"icml\": {\"pages\": 8, \"columns\": 2, \"anonymous\": True},\n \"iclr\": {\"pages\": 9, \"columns\": 1, \"anonymous\": True},\n \"aaai\": {\"pages\": 7, \"columns\": 2, \"anonymous\": True},\n \"acl\": {\"pages\": 8, \"columns\": 2, \"anonymous\": True},\n \"emnlp\": {\"pages\": 8, \"columns\": 2, \"anonymous\": True},\n \"cvpr\": {\"pages\": 8, \"columns\": 2, \"anonymous\": True},\n \"icbinb\": {\"pages\": 4, \"columns\": 2, \"anonymous\": True},\n \"arxiv\": {\"pages\": None, \"columns\": None, \"anonymous\": False},\n}\n\nREQUIRED_SECTIONS = [\n \"abstract\", \"introduction\",\n]\n\nEXPECTED_SECTIONS = [\n \"abstract\", \"introduction\", \"related work\",\n \"method\", \"experiment\", \"result\", \"conclusion\",\n]\n\n\ndef load_tex(path: str) -> str:\n \"\"\"Load tex file, following \\\\input{} directives.\"\"\"\n with open(path, encoding=\"utf-8\", errors=\"replace\") as f:\n content = f.read()\n\n # Resolve \\input{file} directives\n base_dir = os.path.dirname(path)\n\n def resolve_input(match):\n fname = match.group(1)\n if not fname.endswith(\".tex\"):\n fname += \".tex\"\n fpath = os.path.join(base_dir, fname)\n if os.path.exists(fpath):\n with open(fpath, encoding=\"utf-8\", errors=\"replace\") as f:\n return f.read()\n return match.group(0)\n\n content = re.sub(r\"\\\\input\\{([^}]+)\\}\", resolve_input, content)\n return content\n\n\ndef estimate_word_count(tex_content: str) -> int:\n \"\"\"Rough word count excluding LaTeX commands, math, and comments.\"\"\"\n # Remove comments\n text = re.sub(r\"%.*$\", \"\", tex_content, flags=re.MULTILINE)\n # Remove math environments\n text = re.sub(r\"\\$\\$.*?\\$\\$\", \"\", text, flags=re.DOTALL)\n text = re.sub(r\"\\$.*?\\$\", \"\", text)\n text = re.sub(r\"\\\\begin\\{(?:equation|align|gather|math).*?\\}.*?\\\\end\\{(?:equation|align|gather|math).*?\\}\", \"\", text, flags=re.DOTALL)\n # Remove LaTeX commands\n text = re.sub(r\"\\\\[a-zA-Z]+(?:\\[.*?\\])?\\{([^}]*)\\}\", r\"\\1\", text)\n text = re.sub(r\"\\\\[a-zA-Z]+\", \"\", text)\n # Remove braces and special chars\n text = re.sub(r\"[{}\\\\]\", \"\", text)\n words = text.split()\n return len(words)\n\n\ndef check_anonymization(tex_content: str) -> list[str]:\n \"\"\"Check for anonymization violations.\"\"\"\n issues = []\n\n # Check for author names in common locations\n author_match = re.search(r\"\\\\author\\{([^}]+)\\}\", tex_content)\n if author_match:\n author_text = author_match.group(1)\n if \"anonymous\" not in author_text.lower() and \"author\" not in author_text.lower():\n issues.append(f\"Author field contains names: {author_text[:50]}...\")\n\n # Check for self-citations like \"our previous work [1]\"\n self_cite_patterns = [\n r\"our (?:previous|prior|earlier|recent) (?:work|paper|study)\",\n r\"we (?:previously|earlier|recently) (?:proposed|showed|demonstrated)\",\n r\"in our (?:previous|prior|earlier) (?:work|paper)\",\n ]\n for pat in self_cite_patterns:\n if re.search(pat, tex_content, re.IGNORECASE):\n issues.append(f\"Possible self-citation: pattern '{pat}' found\")\n\n # Check for GitHub/institutional links\n url_patterns = [\n (r\"github\\.com/[a-zA-Z0-9_-]+/\", \"GitHub link found\"),\n (r\"gitlab\\.com/[a-zA-Z0-9_-]+/\", \"GitLab link found\"),\n (r\"\\\\url\\{https?://(?!arxiv|doi|paperswithcode)[^}]+\\}\", \"Non-anonymous URL found\"),\n ]\n for pat, msg in url_patterns:\n match = re.search(pat, tex_content)\n if match:\n issues.append(f\"{msg}: {match.group(0)[:60]}\")\n\n # Check for acknowledgments (should be removed for review)\n if re.search(r\"\\\\section\\*?\\{Acknowledgment\", tex_content, re.IGNORECASE):\n issues.append(\"Acknowledgments section present (remove for anonymous submission)\")\n\n return issues\n\n\ndef check_required_sections(tex_content: str) -> tuple[list[str], list[str]]:\n \"\"\"Check for required and expected sections.\"\"\"\n sections = re.findall(r\"\\\\section\\*?\\{([^}]+)\\}\", tex_content)\n section_names_lower = [s.lower().strip() for s in sections]\n\n # Check abstract\n has_abstract = bool(re.search(r\"\\\\begin\\{abstract\\}\", tex_content))\n\n missing_required = []\n if not has_abstract and \"abstract\" not in section_names_lower:\n missing_required.append(\"Abstract\")\n\n if not any(\"introduction\" in s for s in section_names_lower):\n missing_required.append(\"Introduction\")\n\n missing_expected = []\n for expected in EXPECTED_SECTIONS:\n if expected == \"abstract\":\n if not has_abstract:\n missing_expected.append(\"Abstract\")\n elif not any(expected in s for s in section_names_lower):\n missing_expected.append(expected.title())\n\n return missing_required, missing_expected\n\n\ndef check_todos(tex_content: str) -> list[str]:\n \"\"\"Find remaining TODO/TBD/FIXME markers.\"\"\"\n issues = []\n patterns = [r\"TODO\", r\"TBD\", r\"FIXME\", r\"XXX\", r\"HACK\"]\n for pat in patterns:\n matches = list(re.finditer(pat, tex_content, re.IGNORECASE))\n for m in matches:\n # Get surrounding context\n start = max(0, m.start() - 30)\n end = min(len(tex_content), m.end() + 30)\n context = tex_content[start:end].replace(\"\\n\", \" \").strip()\n # Skip if in a comment\n line_start = tex_content.rfind(\"\\n\", 0, m.start()) + 1\n line = tex_content[line_start:m.end()]\n if \"%\" in line[:line.index(pat) if pat in line else 0]:\n continue\n issues.append(f\"{pat} found: ...{context}...\")\n return issues\n\n\ndef main():\n parser = argparse.ArgumentParser(description=\"Pre-submission LaTeX checker\")\n parser.add_argument(\"tex_file\", help=\"Main .tex file\")\n parser.add_argument(\"--venue\", choices=list(VENUE_LIMITS.keys()), help=\"Target venue\")\n parser.add_argument(\"--page-limit\", type=int, help=\"Override page limit\")\n parser.add_argument(\"--check-anon\", action=\"store_true\", help=\"Check anonymization\")\n parser.add_argument(\"--fix\", action=\"store_true\", help=\"Apply fixes using clean_latex.py\")\n args = parser.parse_args()\n\n tex_content = load_tex(args.tex_file)\n issues_total = 0\n\n print(f\"Checking: {args.tex_file}\")\n if args.venue:\n print(f\"Venue: {args.venue.upper()}\")\n print()\n\n # Word count\n word_count = estimate_word_count(tex_content)\n print(f\"Estimated word count: {word_count}\")\n\n # Section count\n sections = re.findall(r\"\\\\section\\*?\\{([^}]+)\\}\", tex_content)\n print(f\"Sections: {len(sections)}\")\n for s in sections:\n print(f\" - {s}\")\n print()\n\n # Required sections\n missing_req, missing_exp = check_required_sections(tex_content)\n if missing_req:\n print(f\"MISSING REQUIRED SECTIONS:\")\n for s in missing_req:\n print(f\" - {s}\")\n issues_total += len(missing_req)\n if missing_exp:\n print(f\"MISSING EXPECTED SECTIONS:\")\n for s in missing_exp:\n print(f\" - {s}\")\n print()\n\n # TODOs\n todos = check_todos(tex_content)\n if todos:\n print(f\"REMAINING MARKERS ({len(todos)}):\")\n for t in todos[:10]:\n print(f\" - {t}\")\n issues_total += len(todos)\n print()\n\n # Anonymization\n if args.check_anon or (args.venue and VENUE_LIMITS.get(args.venue, {}).get(\"anonymous\")):\n anon_issues = check_anonymization(tex_content)\n if anon_issues:\n print(f\"ANONYMIZATION ISSUES ({len(anon_issues)}):\")\n for issue in anon_issues:\n print(f\" - {issue}\")\n issues_total += len(anon_issues)\n else:\n print(\"Anonymization: OK\")\n print()\n\n # Common formatting issues\n fmt_issues = []\n\n # Check for unescaped special chars (outside math mode, simplified)\n for char, escaped in [(\"_\", r\"\\_\"), (\"%\", r\"\\%\"), (\"&\", r\"\\&\")]:\n # This is a simplified check\n pass\n\n # Check for \\begin without \\end\n begins = re.findall(r\"\\\\begin\\{(\\w+)\\}\", tex_content)\n ends = re.findall(r\"\\\\end\\{(\\w+)\\}\", tex_content)\n begin_counts = {}\n end_counts = {}\n for b in begins:\n begin_counts[b] = begin_counts.get(b, 0) + 1\n for e in ends:\n end_counts[e] = end_counts.get(e, 0) + 1\n for env in set(list(begin_counts.keys()) + list(end_counts.keys())):\n bc = begin_counts.get(env, 0)\n ec = end_counts.get(env, 0)\n if bc != ec:\n fmt_issues.append(f\"Mismatched environment: \\\\begin{{{env}}} ({bc}x) vs \\\\end{{{env}}} ({ec}x)\")\n\n if fmt_issues:\n print(f\"FORMATTING ISSUES ({len(fmt_issues)}):\")\n for issue in fmt_issues:\n print(f\" - {issue}\")\n issues_total += len(fmt_issues)\n print()\n\n # Stats\n cite_count = len(re.findall(r\"\\\\cite[a-z]*\\{\", tex_content))\n fig_count = len(re.findall(r\"\\\\begin\\{figure\", tex_content))\n table_count = len(re.findall(r\"\\\\begin\\{table\", tex_content))\n eq_count = len(re.findall(r\"\\\\begin\\{(?:equation|align)\", tex_content))\n\n print(f\"Content stats:\")\n print(f\" Citations: {cite_count}\")\n print(f\" Figures: {fig_count}\")\n print(f\" Tables: {table_count}\")\n print(f\" Equations: {eq_count}\")\n print()\n\n # Summary\n if issues_total == 0:\n print(\"All checks passed!\")\n else:\n print(f\"Total issues: {issues_total}\")\n\n if args.fix and issues_total > 0:\n clean_script = os.path.join(os.path.dirname(__file__), \"clean_latex.py\")\n if os.path.exists(clean_script):\n import subprocess\n fixed_path = args.tex_file.replace(\".tex\", \"_fixed.tex\")\n fix_cmd = [sys.executable, clean_script, \"--input\", args.tex_file, \"--output\", fixed_path]\n result = subprocess.run(fix_cmd, capture_output=True, text=True)\n if result.returncode == 0:\n print(f\"\\nFixed file written to: {fixed_path}\")\n if result.stderr:\n print(result.stderr)\n else:\n print(f\"\\nFix failed: {result.stderr}\", file=sys.stderr)\n\n sys.exit(1 if issues_total > 0 else 0)\n\n\nif __name__ == \"__main__\":\n main()\n","content_type":"text/x-python; charset=utf-8","language":"python","size":10626,"content_sha256":"81e9080683c3bb8713eefa97c03ebb8fdee15be1e0156a712cf482b55d8e3e64"}],"content_json":{"type":"doc","content":[{"type":"heading","attrs":{"level":1},"content":[{"text":"LaTeX Formatting","type":"text"}]},{"type":"paragraph","content":[{"text":"Set up and manage LaTeX formatting for academic papers.","type":"text"}]},{"type":"heading","attrs":{"level":2},"content":[{"text":"Input","type":"text"}]},{"type":"bullet_list","content":[{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"$0","type":"text","marks":[{"type":"code_inline"}]},{"text":" — Action: ","type":"text"},{"text":"setup","type":"text","marks":[{"type":"code_inline"}]},{"text":", ","type":"text"},{"text":"fix","type":"text","marks":[{"type":"code_inline"}]},{"text":", ","type":"text"},{"text":"check","type":"text","marks":[{"type":"code_inline"}]}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"$1","type":"text","marks":[{"type":"code_inline"}]},{"text":" — Venue name (for ","type":"text"},{"text":"setup","type":"text","marks":[{"type":"code_inline"}]},{"text":") or ","type":"text"},{"text":".tex","type":"text","marks":[{"type":"code_inline"}]},{"text":" file path (for ","type":"text"},{"text":"fix","type":"text","marks":[{"type":"code_inline"}]},{"text":"/","type":"text"},{"text":"check","type":"text","marks":[{"type":"code_inline"}]},{"text":")","type":"text"}]}]}]},{"type":"heading","attrs":{"level":2},"content":[{"text":"Scripts","type":"text"}]},{"type":"heading","attrs":{"level":3},"content":[{"text":"Pre-submission format checker","type":"text"}]},{"type":"code_block","attrs":{"wrap":false,"language":"bash"},"content":[{"text":"python ~/.claude/skills/latex-formatting/scripts/latex_checker.py paper/main.tex --venue neurips --check-anon","type":"text"}]},{"type":"paragraph","content":[{"text":"Checks: word count, required sections, TODO markers, anonymization, mismatched environments, content stats.","type":"text"}]},{"type":"heading","attrs":{"level":3},"content":[{"text":"Validate citations and references","type":"text"}]},{"type":"code_block","attrs":{"wrap":false,"language":"bash"},"content":[{"text":"python ~/.claude/skills/citation-management/scripts/validate_citations.py \\\n --tex paper/main.tex --bib paper/references.bib --check-figures","type":"text"}]},{"type":"heading","attrs":{"level":3},"content":[{"text":"Clean LaTeX text (fix special characters)","type":"text"}]},{"type":"code_block","attrs":{"wrap":false,"language":"bash"},"content":[{"text":"python ~/.claude/skills/latex-formatting/scripts/clean_latex.py \\\n --input paper/main.tex --output paper/main_cleaned.tex","type":"text"}]},{"type":"paragraph","content":[{"text":"Replaces special/non-UTF8 characters with LaTeX equivalents, skips math environments. Key flags: ","type":"text"},{"text":"--dry-run","type":"text","marks":[{"type":"code_inline"}]},{"text":", ","type":"text"},{"text":"--tables-only","type":"text","marks":[{"type":"code_inline"}]}]},{"type":"heading","attrs":{"level":3},"content":[{"text":"Auto-fix after checking","type":"text"}]},{"type":"code_block","attrs":{"wrap":false,"language":"bash"},"content":[{"text":"python ~/.claude/skills/latex-formatting/scripts/latex_checker.py paper/main.tex --venue neurips --fix","type":"text"}]},{"type":"paragraph","content":[{"text":"Runs checks then applies clean_latex.py fixes, writing to ","type":"text"},{"text":"main_fixed.tex","type":"text","marks":[{"type":"code_inline"}]},{"text":".","type":"text"}]},{"type":"heading","attrs":{"level":2},"content":[{"text":"References","type":"text"}]},{"type":"bullet_list","content":[{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"Venue specs, project structure, packages, commands: ","type":"text"},{"text":"~/.claude/skills/latex-formatting/references/venue-templates.md","type":"text","marks":[{"type":"code_inline"}]}]}]}]},{"type":"heading","attrs":{"level":2},"content":[{"text":"Action: ","type":"text"},{"text":"setup","type":"text","marks":[{"type":"code_inline"}]}]},{"type":"paragraph","content":[{"text":"Create the project directory structure and main.tex for the specified venue. Use the template from ","type":"text"},{"text":"references/venue-templates.md","type":"text","marks":[{"type":"code_inline"}]},{"text":".","type":"text"}]},{"type":"heading","attrs":{"level":2},"content":[{"text":"Action: ","type":"text"},{"text":"fix","type":"text","marks":[{"type":"code_inline"}]}]},{"type":"paragraph","content":[{"text":"Fix common LaTeX issues: unescaped special chars, math mode errors, float placement, overfull/underfull boxes, cross-reference issues.","type":"text"}]},{"type":"heading","attrs":{"level":2},"content":[{"text":"Action: ","type":"text"},{"text":"check","type":"text","marks":[{"type":"code_inline"}]}]},{"type":"paragraph","content":[{"text":"Run ","type":"text"},{"text":"latex_checker.py","type":"text","marks":[{"type":"code_inline"}]},{"text":" for pre-submission validation. Check page count, anonymization, required sections, TODO markers.","type":"text"}]},{"type":"heading","attrs":{"level":2},"content":[{"text":"Related Skills","type":"text"}]},{"type":"bullet_list","content":[{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"Upstream: ","type":"text"},{"text":"paper-writing-section","type":"text","marks":[{"type":"link","attrs":{"href":"../paper-writing-section/","title":null}}]},{"text":", ","type":"text"},{"text":"table-generation","type":"text","marks":[{"type":"link","attrs":{"href":"../table-generation/","title":null}}]}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"Downstream: ","type":"text"},{"text":"paper-compilation","type":"text","marks":[{"type":"link","attrs":{"href":"../paper-compilation/","title":null}}]}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"See also: ","type":"text"},{"text":"citation-management","type":"text","marks":[{"type":"link","attrs":{"href":"../citation-management/","title":null}}]}]}]}]}]},"metadata":{"date":"2026-11-02","name":"latex-formatting","author":"@skillopedia","source":{"stars":446,"repo_name":"agent-research-skills","origin_url":"https://github.com/lingzhi227/agent-research-skills/blob/HEAD/skills/latex-formatting/SKILL.md","repo_owner":"lingzhi227","body_sha256":"37fd1a6ee4f6b68928c77c490a96232a8cde80ef8d535da9b6f3fd7f1fb05586","cluster_key":"e98516b03cb8ea9ea1842a899703fc0df006a076fa8b943b165f492c680c960a","clean_bundle":{"format":"clean-skill-bundle-v1","source":"lingzhi227/agent-research-skills/skills/latex-formatting/SKILL.md","text_bytes":21399,"source_commit":"9e6c085d65e313e475e921fdfe795ac11eb7589e","skills_sh_rank":7909,"attachment_count":3,"text_attachments":3,"attachment_storage":"skill_attachments","binary_attachments":0},"cluster_size":1,"skill_md_path":"skills/latex-formatting/SKILL.md","import_metadata":{"date":"2026-11-02","author":"@skillopedia","version":"v1","category":"documents-office","category_label":"Documents"},"exact_dupes_collapsed_into_this":0},"version":"v1","category":"documents-office","import_tag":"skills-sh-top20k-2026-11","description":"Handle LaTeX formatting, templates, and styling for academic papers. Set up conference templates (ICML, ICLR, NeurIPS, AAAI, ACL), fix formatting issues, manage packages, and ensure venue-specific compliance. Use when the user needs to set up a paper template, fix LaTeX formatting, or prepare for submission.","argument-hint":["venue-or-file"]}},"renderedAt":1793671654631}

LaTeX Formatting Set up and manage LaTeX formatting for academic papers. Input - — Action: , , - — Venue name (for ) or file path (for / ) Scripts Pre-submission format checker Checks: word count, required sections, TODO markers, anonymization, mismatched environments, content stats. Validate citations and references Clean LaTeX text (fix special characters) Replaces special/non-UTF8 characters with LaTeX equivalents, skips math environments. Key flags: , Auto-fix after checking Runs checks then applies clean latex.py fixes, writing to . References - Venue specs, project structure, packages,…