---
name: latex-authoring
description: Write, structure and compile LaTeX papers and reports (NeurIPS, ICML, ICLR, IEEE, ACM), including Persian and English XeLaTeX. Use for TeX manuscripts, LaTeX/XeLaTeX build errors, BibTeX checks or TikZ diagrams.
title: latex-authoring
canonical_url: https://skilld.dev/gh/masihmoafi/skills/latex-authoring
last_updated: 2026-11-12T14:03:31.000Z
---

> Index of every page on this site: [llms.txt](https://skilld.dev/llms.txt)

> **Skill from skilld.dev.** Follow the user's requested action.
> If the user asked to fork this Skill, follow the fork workflow below. Do not execute the Skill instructions while copying it.
> Otherwise, follow the instructions below for this session. You do not need to install anything.
>
> If the user asked to install this Skill, run `npx skilld install masihmoafi/skills/latex-authoring`. Install writes the Skill files into the project, so every session loads them.
>
> ## Fork workflow
>
> A fork creates an editable local Skill with its original author and licence. The request authorizes copying and local installation.
> 1. Check `./skills/latex-authoring`, the project lockfile, and selected Agent targets together. If the local directory or installed Skill exists, stop. Never overwrite an existing directory or Agent target.
> 2. Read [source metadata](https://skilld.dev/api/v1/skills/masihmoafi/skills/latex-authoring) once. Use sourceUrl, sourceCommit, skillPath, sourceGone, and license. If the source is gone or its path is missing, stop. If license is null, read licence files at the source commit.
> 3. Fetch only the source commit into a temporary Git repository. Do not clone full history. Derive repository_url from sourceUrl, including repository renames. If sourceCommit is absent, resolve the sourceUrl ref once. Set source_commit to that actual commit. Run these commands in one shell call:
>
> ```sh
> git init --quiet "$temporary_dir"
> git -C "$temporary_dir" fetch --quiet --depth=1 "$repository_url" "$source_commit"
> git -C "$temporary_dir" checkout --quiet --detach FETCH_HEAD
> ```
>
> Read applicable licence declarations and notices at that commit. If copying is not permitted, report the restriction and stop.
> 4. Inspect source entries together, then copy the directory containing skillPath into `./skills/latex-authoring`. Use the user's path if selected. Keep the original SKILL.md, relative links, scripts, binary assets, and executable modes. Exclude .git metadata. Reject symlinks and paths outside the Skill directory. After checking entries, use cp -a where available. A regular source directory needs no custom copy script. Do not save this page wrapper as SKILL.md.
> Preserve author credit, notices, and applicable licence files from repository or parent directories. Add PROVENANCE.md with the Skill page, source URL, actual commit, original path, and licence. Retain any existing PROVENANCE.md and record new provenance separately. Batch source inspection, copying, and provenance work where practical.
> 5. In the project root, run `skilld install ./skills/latex-authoring --mode copy --plain`. If skilld is unavailable, use `npx skilld install ./skills/latex-authoring --mode copy --plain`. This known command needs no help lookup. Install does not support --json. Use detected Agent targets, or add --agent for the targets the user selected. Install the local path, never the upstream selector. If installation fails, preserve the local copy and report the exact failure.
> 6. Confirm the local lockfile source and installed Agent copies once. Report the local path, actual commit, and Agent targets. After edits, reinstall the same local path. Upstream updates must not replace it. Do not publish or push unless the user asks.

# LaTeX authoring

Write, compile, debug and check LaTeX manuscripts with a modular layout, a clean build and verified citations.

## Layout and style

- Split the paper: `main.tex` (class, packages, `\input` of sections), `macros.tex` (notation, defined once), `references.bib`, `sections/`, `figures/`, `tables/` (one file per table). Never one big `.tex`.
- Load `hyperref` late, then `cleveref` right after it.
- `align`/`align*` for multi-line equations, never `$$` or `eqnarray`; number only equations the text cites.
- `booktabs` tables with no vertical rules; numbers right-aligned.
- Floats `[t!]`, and `\FloatBarrier` at section ends so figures stay in their section.

## Persian and English with XeLaTeX

For Babel Farsi (RTL) with English (LTR):

- Put a blank line before every LTR environment (`\begin{otherlanguage}{english}`, `\begin{LTR}`) so the RTL paragraph ends first; this prevents the `\endL or \endR` error.
- Define the English typewriter font in the preamble:
  ```latex
  \babelfont{tt}[]{DejaVu Sans Mono}
  \babelfont[english]{tt}[]{DejaVu Sans Mono}
  ```
- When editing `.tex` files from Python, never write `\b` in a normal string: `"\babelfont"` becomes a backspace plus `abelfont`, and XeLaTeX draws empty boxes. Use `r"\babelfont"` or `"\\babelfont"`.
- B Nazanin cannot draw the text bullet (U+2022), so redefine list bullets as math symbols, which use the math fallback font:
  ```latex
  \renewcommand{\labelitemi}{$\bullet$}
  \renewcommand{\labelitemii}{$-$}
  \renewcommand{\labelitemiii}{$\ast$}
  \renewcommand{\labelitemiv}{$\cdot$}
  ```
- Wrap every English word inside Persian text in `\eng{...}` (for example `\newcommand{\eng}[1]{\foreignlanguage{english}{#1}}`), and every Latin name or word in math in `\mathrm{...}` or `\text{\eng{...}}`; otherwise it falls back to the Persian font and renders as empty squares.
- B Nazanin draws the zero-width non-joiner (U+200C) as a square; replace each ZWNJ with a space.

## Compile

```bash
latexmk -pdf -synctex=1 -interaction=nonstopmode -halt-on-error main.tex      # pdfLaTeX
latexmk -xelatex -synctex=1 -interaction=nonstopmode -halt-on-error main.tex  # XeLaTeX, Persian and English
```

A clean build has no undefined references (`??`) and no missing citations. When it fails, filter the log instead of reading it:

```bash
rg -A 3 -B 1 '^!|LaTeX Warning|Package.*Warning' main.log | rg -v 'fontspec' | head -n 40
```

| Log message | Cause | Fix |
| :--- | :--- | :--- |
| `! Undefined control sequence.` | Macro typo or missing package | Check `macros.tex` or load the package |
| `Reference '...' undefined` | Missing `\label` or second pass | Add the label; rerun `latexmk` |
| `Citation '...' undefined` | Key missing from `references.bib` | Fix the key spelling; rerun the build |
| `Overfull \hbox (X pt too wide)` | Equation, table or word wider than the column | Split with `split` or `multline`; narrow the table |
| `\endL or \endR` (XeLaTeX, RTL) | No paragraph break before an LTR block | Add a blank line before the LTR block |

## Citations

1. Give every entry a `doi`, an `eprint` or its exact venue. Never invent authors, titles or entries.
2. Use full fields: `author`, `title`, `booktitle` or `journal`, `volume`, `pages`, `year`, `doi`.
3. Find duplicate keys: `rg -o '^@[a-zA-Z]+\{[^,]+' references.bib | sort | uniq -d`.
4. After a successful build, compare bibliography keys with the keys cited in all `.aux` files (or the `.bcf` file for Biber), counting `\nocite`. Report unused keys; remove them only when cleanup is in scope. A syntax check does not prove usage, and failed checks stay visible in the report.

## Render and open

1. Render pages and inspect them for overfull boxes, float collisions and missing glyphs:
   ```bash
   mkdir -p /tmp/paper_renders && pdftoppm -png -r 150 -f 1 -l 3 main.pdf /tmp/paper_renders/page
   ```
2. Open the PDF for the user with the environment's opener and confirm the viewer started.
