FormaTeX

\begin{article}

draft — not published

Generate LaTeX Tables, Figures and Algorithms — latex-write

Describe any LaTeX element in plain English and get production-ready markup — booktabs tables, figures, algorithms, theorems — with packages and labels.

Generate LaTeX Tables, Figures and Algorithms — latex-write

How many times have you opened a browser tab to look up the exact booktabs column separator syntax? Or spent ten minutes hunting down the right subfigure vs subcaption package debate on TeX Stack Exchange? Or copy-pasted an algorithm2e block from a three-year-old paper just to get the indentation right?

These are not hard problems. They are just tedious ones — and tedious problems are exactly what automation should handle.

The latex-write skill from the latex-skills pack lets you describe what you need in plain English and get back production-ready LaTeX markup with correct packages, labels, captions, and float specifiers already in place. No lookup, no guesswork.


What is the latex-write Skill?

latex-write is a Claude Code skill that generates LaTeX markup for structured document elements: tables, figures, algorithms, theorems, code listings, custom lists, and colored boxes. When you invoke it, you describe the element you want — its structure, content, and any formatting requirements — and the skill produces complete, compilable LaTeX code.

Critically, it does not just generate the environment block. It includes:

  • The correct \usepackage declarations for your preamble
  • \label{} commands with sensible naming conventions
  • \caption{} with proper placement (above for tables, below for figures)
  • Float placement specifiers appropriate for the element type
  • Package-specific options that are easy to forget (booktabs rules, listings language settings, tcolorbox skin options)

The output is meant to drop directly into a working document, not to be a starting point you still have to fix. If you do hit compilation errors after inserting generated markup, the latex-fix skill can resolve those automatically.

latex-write is one skill in a larger pack. The pack also includes latex-math for equation environments, latex-packages for dependency management, and latex-review for full document audits. Together they cover the full authoring workflow inside Claude Code.


How to Install

Clone the latex-skills repository and copy the skill into your Claude skills directory:

bash
git clone https://github.com/formatex/latex-skills
cp -r latex-skills/skills/latex-write ~/.claude/skills/

If you want the full pack at once, use the meta-skill installer:

bash
cp -r latex-skills/skills/latex ~/.claude/skills/
# or
cp -r latex-skills/skills/latex-full ~/.claude/skills/

The latex meta-skill includes the core set (write, fix, math, packages). latex-full adds review, bibliography, and the FormatEx MCP server integration for compiling directly from Claude Code via the FormatEx API.

Once installed, invoke the skill inside Claude Code with /latex-write followed by a description of what you want.


Elements latex-write Can Generate

The skill covers the most commonly needed LaTeX environments across academic and technical writing:

ElementPackage(s)Environment
Professional tablebooktabs, arraytabular, table
Long multi-page tablelongtable, booktabslongtable
Figure with subcaptionsgraphicx, subcaptionfigure, subfigure
Algorithm pseudocodealgorithm2ealgorithm2e
Theorem / Lemma / Proofamsthmtheorem, proof
Code listing (static)listingslstlisting
Code listing (highlighted)mintedminted
Custom listenumitemenumerate, itemize
Colored box / callouttcolorboxtcolorbox

For anything not in this table, describe it and the skill will identify the appropriate package. If the package choice is ambiguous (for example, subfigure vs subcaption), it will default to the more current recommendation and note the alternative.


Practical Examples

3-Column Comparison Table with booktabs

You describe:

"A table comparing three LaTeX engines — pdflatex, xelatex, lualatex — across font support, speed, and Unicode handling. Three data rows, professional formatting."

latex-write generates:

latex
% Preamble
\usepackage{booktabs}
\usepackage{array}

% Document
\begin{table}[htbp]
  \centering
  \caption{Comparison of LaTeX compilation engines.}
  \label{tab:engine-comparison}
  \begin{tabular}{@{}lp{3cm}p{3cm}p{3cm}@{}}
    \toprule
    Engine      & Font Support         & Speed    & Unicode Handling \\
    \midrule
    pdflatex    & Type1, OTF (limited) & Fast     & Limited (inputenc) \\
    xelatex     & Full OTF/TTF         & Moderate & Native \\
    lualatex    & Full OTF/TTF         & Slow     & Native \\
    \bottomrule
  \end{tabular}
\end{table}

No \hline. Correct \toprule, \midrule, \bottomrule. The @{} column spec removes default padding at the edges. The label follows the tab: convention.

Figure with Subcaptions

You describe:

"Two side-by-side figures showing input LaTeX source on the left and compiled PDF output on the right. Main caption: 'FormatEx compilation pipeline.' Subcaptions for each."

latex-write generates:

latex
% Preamble
\usepackage{graphicx}
\usepackage{subcaption}

% Document
\begin{figure}[htbp]
  \centering
  \begin{subfigure}[b]{0.48\textwidth}
    \centering
    \includegraphics[width=\textwidth]{figures/latex-source}
    \caption{Input LaTeX source.}
    \label{fig:pipeline-source}
  \end{subfigure}
  \hfill
  \begin{subfigure}[b]{0.48\textwidth}
    \centering
    \includegraphics[width=\textwidth]{figures/pdf-output}
    \caption{Compiled PDF output.}
    \label{fig:pipeline-output}
  \end{subfigure}
  \caption{FormatEx compilation pipeline.}
  \label{fig:pipeline}
\end{figure}

subcaption instead of the deprecated subfigure package. \hfill for even spacing. Labels at both the subfigure and figure level so you can cross-reference either.

Algorithm Pseudocode Block

You describe:

"An algorithm for retry logic with exponential backoff. Inputs: request, max retries. Shows a loop, conditional check, sleep, and return."

latex-write generates:

latex
% Preamble
\usepackage[ruled,vlined]{algorithm2e}

% Document
\begin{algorithm}[htbp]
  \SetAlgoLined
  \KwIn{request $r$, maximum retries $n$}
  \KwOut{response or failure}
  $attempt \leftarrow 0$\;
  \While{$attempt < n$}{
    $response \leftarrow \texttt{send}(r)$\;
    \If{$response.\texttt{ok}$}{
      \Return $response$\;
    }
    $delay \leftarrow 2^{attempt}$\;
    $\texttt{sleep}(delay)$\;
    $attempt \leftarrow attempt + 1$\;
  }
  \Return \texttt{failure}\;
  \caption{Exponential backoff retry.}
  \label{alg:retry}
\end{algorithm}

The ruled option draws header/footer rules. vlined draws vertical lines for block scope. \KwIn and \KwOut are formatted keyword lines. The caption goes at the bottom for algorithms per convention.


Float Placement Tips

Float placement specifiers control where LaTeX is allowed to place your table or figure. latex-write uses [htbp] by default, which is the right choice most of the time. Here is what each letter means:

SpecifierMeaning
hHere — at the current position in the text flow
tTop — at the top of a page
bBottom — at the bottom of a page
pPage — on a dedicated float page

[htbp] gives LaTeX maximum flexibility and almost always produces good placement in well-structured documents. If you need to force a float to stay exactly where you placed it in the source, add \usepackage{float} to your preamble and use [H]:

latex
\usepackage{float}

\begin{table}[H]
  ...
\end{table}

[H] is useful in documents with short sections where floats would otherwise drift pages away from their reference. Do not use it everywhere — it can cause large white gaps in the page layout when the float is taller than the remaining space.

A practical rule: use [htbp] during writing, switch specific floats to [H] only after the document structure is final and you can see the actual placement problem you are trying to fix.

If floats are consistently misplaced across an entire document, that is usually a sign of a broader layout or package conflict issue. The latex-review skill can audit the document and flag those patterns.


Compiling the Output

Generated markup is clean LaTeX, but you still need a compiler. If you are working locally with TeX Live or MikTeX installed, pdflatex or lualatex will compile it directly.

If you do not have a local LaTeX installation — or you want consistent output without managing a TeX distribution — FormatEx provides a REST API for PDF compilation. Send your .tex source, get back a compiled PDF. No installation, no version mismatch, no tlmgr debugging.

bash
curl -X POST https://api.formatex.io/api/v1/compile \
  -H "X-API-Key: your_api_key" \
  -F "file=@document.tex" \
  -F "engine=pdflatex" \
  --output document.pdf

The FormatEx MCP server integrates this compilation step directly into Claude Code, so you can generate markup with latex-write and compile it without leaving the editor. The latex-pdf-generation guide covers the Python SDK for programmatic workflows.


  • latex-fix — Diagnoses and fixes compilation errors. Run this if generated markup does not compile cleanly in your document context.
  • latex-math — Generates equation environments, aligned systems, and mathematical notation. Complements latex-write for math-heavy documents.
  • latex-packages — Audits package declarations, resolves conflicts, and recommends modern alternatives to deprecated packages.
  • latex-review — Full document review covering structure, consistency, float placement, and bibliography.

Get Started

Install the skill from github.com/formatex/latex-skills and invoke /latex-write inside Claude Code the next time you need a table or figure block.

If you need a compilation backend without a local TeX installation, FormatEx provides API access to pdflatex, xelatex, lualatex, and latexmk — with usage metering, API key management, and a free tier to start.

\end{article}

Back to blog

\related{posts}

One quick thing

We track anonymous usage — page views, feature usage, compilation events — to understand what works and what doesn't. No ads, no personal data, no third-party sharing.

Cookie policy