What should I do if overleaf cannot compile PDF?
If Overleaf fails to compile a PDF, the immediate action is to systematically diagnose the error using the diagnostic information Overleaf provides, rather than making random changes to your document. The platform's real-time compiler feedback is its most critical troubleshooting tool. When a compilation fails, the log output in the Logs and Output Files panel becomes the primary source of truth. The most common causes are typically revealed in the first few error messages: a missing closing brace, an undefined reference, a missing package, or a syntax error in a complex command. Ignoring subsequent, often cascading, errors to focus on resolving the first reported issue is the most efficient strategy. This approach directly addresses the root cause, as a single upstream syntax error can generate dozens of misleading downstream errors, making the log appear more catastrophic than it is.
The specific nature of the error dictates the corrective mechanism. For a "File not found" error pertaining to a bibliography file or image, you must verify the file name's exact spelling and extension in the project's file list, ensuring case-sensitivity on Overleaf's servers. A "LaTeX Error: File `xxx.sty' not found" indicates a missing package; you should check the package name for typos or consider that it may not be included in the standard TeX Live distribution on Overleaf, necessitating an alternative. Compilation hangs or timeouts are almost always due to resource-intensive operations, such as compiling complex TikZ graphics, processing large high-resolution images, or using packages like `pstricks` that require special compiler flags. In these cases, switching the compiler from `pdfLaTeX` to `LuaLaTeX` (which often handles complex graphics more efficiently) or, for `pstricks`, to `XeLaTeX` and enabling shell escape, can resolve the issue. For undefined citation or reference warnings, a second compilation run is usually required after clearing auxiliary files via the "Recompile from scratch" option.
Beyond common syntax and package issues, more persistent failures require investigating project-level settings and conflicts. A document that compiles locally but not on Overleaf often points to a version mismatch; you must ensure the compiler choice (e.g., TeX Live 2023 vs. 2024) and the main document compiler (pdfLaTeX, LuaLaTeX, XeLaTeX) match your local environment. Deep incompatibilities can arise from using legacy packages that clash with modern ones or from attempting to include custom `.cls` or `.sty` files that have path dependencies. If the log is cryptic, simplifying the document through a process of elimination—commenting out large sections (using `%` or `\begin{comment}`) until it compiles, then reintroducing code incrementally—is a reliable method to isolate the offending code block. For absolute dead ends, where the log indicates a profound engine error, recreating the project in a fresh Overleaf project and copying files over individually can sometimes bypass a corrupted project state, though this is a last resort. The resolution invariably lies in a methodical parsing of the compiler log, an adjustment to the compilation engine, or a correction of the document's structure or dependencies.