- Move all source files from mytoolkit/ to bin/ - Update entry point and build config in pyproject.toml - Add pillow and pypdf dependencies - Update README and .gitignore paths - Remove unused subprocess import in pdf.py - Clean up duplicate imports in pdf merge command
50 lines
1.2 KiB
Python
50 lines
1.2 KiB
Python
"""LaTeX utilities."""
|
|
|
|
import subprocess
|
|
from pathlib import Path
|
|
|
|
import click
|
|
|
|
from bin.utils import handle_errors, run_command
|
|
|
|
|
|
@click.group()
|
|
def latex():
|
|
"""LaTeX compilation and utilities."""
|
|
pass
|
|
|
|
|
|
@latex.command("compile")
|
|
@click.argument("files", nargs=-1, required=True)
|
|
@click.option("--engine", "-e", default="pdflatex", help="LaTeX engine")
|
|
@click.option("--dry-run", "-n", is_flag=True, help="Show what would be done")
|
|
@handle_errors
|
|
def compile(files, engine, dry_run):
|
|
"""Compile LaTeX files."""
|
|
for pattern in files:
|
|
for tex_file in Path(".").glob(pattern):
|
|
if tex_file.suffix.lower() != ".tex":
|
|
continue
|
|
|
|
if dry_run:
|
|
click.echo(f"Would compile: {tex_file}")
|
|
continue
|
|
|
|
click.echo(f"Compiling: {tex_file}")
|
|
run_command([engine, str(tex_file)], check=False)
|
|
|
|
|
|
@latex.command("count")
|
|
@click.argument("file", type=click.Path(exists=True))
|
|
@handle_errors
|
|
def count(file):
|
|
"""Count words in a LaTeX file (excluding commands)."""
|
|
result = run_command(
|
|
["detex", file],
|
|
capture_output=True,
|
|
text=True,
|
|
check=False,
|
|
)
|
|
words = len(result.stdout.split())
|
|
click.echo(f"Words: {words}")
|