compile_resume
Compile LaTeX resume files to PDF format using pdflatex for professional document generation and distribution.
Instructions
Compile a LaTeX resume to PDF using pdflatex.
Args:
filename: Name of the resume file to compile
output_dir: Output directory for the PDF (default: same as resumes directory)
Returns the path to the generated PDF or compilation errors.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| filename | Yes | ||
| output_dir | No |
Implementation Reference
- src/latex_resume_mcp/server.py:358-427 (handler)The core handler function decorated with @mcp.tool(), implementing the logic to compile LaTeX resume to PDF using pdflatex. Handles file existence, LaTeX installation check, compilation (run twice), PDF generation, auxiliary file cleanup, and error reporting.@mcp.tool() def compile_resume(filename: str, output_dir: str = None) -> str: """ Compile a LaTeX resume to PDF using pdflatex. Args: filename: Name of the resume file to compile output_dir: Output directory for the PDF (default: same as resumes directory) Returns the path to the generated PDF or compilation errors. """ ensure_dirs() resumes_dir = get_resumes_dir() filepath = resumes_dir / ensure_tex_extension(filename) if not filepath.exists(): return json.dumps({"error": f"Resume '{filename}' not found"}) pdflatex_cmd = find_pdflatex() if not pdflatex_cmd: return json.dumps({ "error": "pdflatex not found. Please install LaTeX:", "install_instructions": { "macOS": "brew install --cask mactex # or: brew install --cask basictex", "Ubuntu/Debian": "sudo apt install texlive-latex-base texlive-latex-extra", "Fedora": "sudo dnf install texlive-scheme-basic", "Windows": "Download from https://miktex.org/" } }) out_dir = Path(output_dir) if output_dir else resumes_dir out_dir.mkdir(parents=True, exist_ok=True) try: # Run pdflatex twice for proper reference resolution for _ in range(2): result = subprocess.run( [pdflatex_cmd, "-interaction=nonstopmode", f"-output-directory={out_dir}", filepath.name], cwd=resumes_dir, capture_output=True, text=True, timeout=60 ) pdf_name = filepath.stem + ".pdf" pdf_path = out_dir / pdf_name if pdf_path.exists(): # Clean up auxiliary files for ext in [".aux", ".log", ".out"]: aux_file = out_dir / (filepath.stem + ext) if aux_file.exists(): aux_file.unlink() return json.dumps({ "success": True, "pdf_path": str(pdf_path), "message": f"Successfully compiled {filename} to PDF" }) else: return json.dumps({ "error": "Compilation failed", "stdout": result.stdout[-2000:] if result.stdout else "", "stderr": result.stderr[-2000:] if result.stderr else "" }) except subprocess.TimeoutExpired: return json.dumps({"error": "Compilation timed out after 60 seconds"}) except Exception as e: return json.dumps({"error": f"Compilation error: {str(e)}"})
- Helper function to locate the pdflatex executable, checking PATH and common installation paths across OS.def find_pdflatex() -> str | None: """Find pdflatex executable.""" # Check PATH first pdflatex = shutil.which("pdflatex") if pdflatex: return pdflatex # Check common installation locations common_paths = [ "/Library/TeX/texbin/pdflatex", # MacTeX "/usr/local/texlive/2024/bin/x86_64-linux/pdflatex", # TeX Live Linux "/usr/local/texlive/2024/bin/universal-darwin/pdflatex", # TeX Live macOS "/usr/bin/pdflatex", # System install ] for path in common_paths: if Path(path).exists(): return path return None
- Helper utility to ensure filenames have .tex extension.def ensure_tex_extension(filename: str) -> str: """Ensure filename has .tex extension.""" return filename if filename.endswith(".tex") else f"{filename}.tex"
- Helper to create necessary directories for resumes and templates.def ensure_dirs(): """Ensure resume and template directories exist.""" get_resumes_dir().mkdir(parents=True, exist_ok=True) get_templates_dir().mkdir(parents=True, exist_ok=True)
- src/latex_resume_mcp/server.py:358-358 (registration)The @mcp.tool() decorator registers the compile_resume function as an MCP tool.@mcp.tool()