LaTeX
Build LaTeX documents
Write and build LaTeX papers, assignments, reports, figures, and bibliographies.
What LaTeX is for
LaTeX projects are for papers, assignments, reports, and technical documents that need high-quality typesetting, bibliographies, cross references, figures, and reproducible builds.
Build a paper
- Create or open a
.texfile. - Edit the source in the LaTeX editor.
- Build the PDF.
- Inspect errors and warnings in the build output.
- Use SyncTeX, preview panes, and project files to move between source and output.
Keep figures, bibliography files, generated data, and scripts in the same project so collaborators and agents can inspect the complete paper workflow.
Choose how the document builds
The Build tab in the output panel shows this file's build command, with the Engine... menu at its right, and a log for each stage of the last build.
- In Engine..., choose PDFLaTeX, XeLaTeX, or LuaTex to set the
command. Each runs latexmk, which repeats LaTeX and runs BibTeX as needed.
For a
.texfile, auxiliary files go to a temporary folder and the PDF is copied next to the source; the (no output dir) variants keep everything in the document's folder. PDFLaTeX (shell-escape) also builds there, and lets the document run other programs during the build, as some packages require. - To use your own command, edit the command line and press Enter. Commands run in bash. Without a semicolon, the command must end with the file name, without its folder; CoCalc replaces the last word with it. A command that contains a semicolon, such as several commands in a row, runs exactly as typed. Clearing the line restores the PDFLaTeX command.
- CoCalc saves the command with the document, so collaborators and agents who build it through CoCalc use the same command.
- In the first 1,000 lines,
% !TeX program = xelatex(orpdflatex,lualatex) picks the engine for a document with no saved command.% !TeX cocalc = <command>sets the command in the document itself; the semicolon rule applies to it too. Builds use that command while the line is present. When CoCalc reads the line, as it does when you open the file, it makes that command the document's saved command and shows it under Hardcoded build-command in the Build tab. After you add the line, reopen the file; after you change or remove it, click Rescan there. Removing the line leaves its command saved until you choose an engine or edit the command.
Some documents need a step before or between LaTeX runs. CoCalc runs it and shows its log in a tab of its own:
- Knitr: for an
.Rnwor.Rtexfile, knitr runs the R code first and writes the.texfile that LaTeX builds. - SageTex: when the document loads the sagetex package, Sage runs the
.sagetex.sagefile that LaTeX wrote, then LaTeX runs again. - PythonTeX: when the document loads the pythontex package, pythontex runs the document's PythonTeX code, then LaTeX runs again.
Documents that use SageTeX or PythonTeX build in their own folder. Each stage needs its software installed where the project runs: R with knitr, Sage, or pythontex. In the output panel, Force Build runs every stage again instead of reusing earlier results, and Delete Aux Files (Clean in the menu beside the Build button) removes auxiliary files from earlier builds; the PDF stays.
Edit a formula with Agent
In the LaTeX editor's Rich Text mode, rendered formulas have an agent editing shortcut. Use it to request a change to one formula while keeping the surrounding document in view.
- Switch the editor to Rich Text and find the rendered formula.
- Hold Shift and click the formula, or focus it and press Shift+Enter.
- In Edit formula with Agent, check the formula preview and describe the change. For example: "Replace the finite sum with an integral, keeping the same variable names."
- Choose Edit with Agent to send the request to the agent chat.
- Review the changed source and rebuild the document to check its PDF output.
The request includes the formula's current source and location. If the formula belongs to an included file, that file is identified as the edit target. The agent is instructed to edit the live document, preserve the existing formula delimiters and style, and verify its work. The shortcut requires an editable formula; read-only source does not open the edit request.
Troubleshooting
If the PDF does not build, start with the first meaningful LaTeX error rather than later follow-up errors. Clean auxiliary files when stale build state is suspect. For large documents, isolate failing sections in a small test file before changing the full paper.
Ask Agent about a LaTeX build error
When Recent agent sessions is shown, select the conversation that should receive the request. The confirmation button submits it to that conversation; follow the response there and review any changes.
An error entry with a source line can offer Fix with Agent... and Ask Agent for a Hint..., depending on the AI access allowed in the project.
- Build the document and find the first useful error in the errors panel.
- Choose Fix with Agent... to request a repair, or Ask Agent for a Hint... to request debugging guidance.
- Review the displayed error context and choose the recent agent session when the selector is shown.
- Confirm with Send to Agent for a repair, or Ask Agent for a hint.
- Follow the response in the agent chat. Review any edits and rebuild the PDF to check the result.
The repair request identifies the document, the reported error file and line, the error message, and the configured build command. This helps the agent locate an error in an included file and reproduce the build. It is instructed to use the live document when available. Warnings and errors without a source line do not receive this particular error-row shortcut.