Skip to content

LaTeX diff ​

When an agent revises a derivation, proof, or section of your manuscript, you need to verify every modification. TeXRA renders each proposed change directly in the typeset document so you can evaluate edits in their full visual and mathematical context.

spectral-gap — texra-paper

2  Preliminaries

Definition 1.An Erdös-RényiErdős–Rényi random graph G(n, p) is a graph on n vertices where each posible edgepossible edge {u, v} is included with probability pindependent, independently of all other edges.

Let A be the adjacency matrix of a graph G be a graph on n vertices. Its adjacency matrix A = A(G) is an n × n matrix where Auv = 1 if {u, v} is an edge, and Auv = 0 otherwise. Since Aare denotedis symmetric, its eigenvalues are real and are denoted by λ₁ ≥ λ₂ ≥ ⋯ ≥ λₙ.

3  Spectral Gap

For a d-regular graph G (where every vertex has degree d), it is well-known that the largest eigenvalue is λ₁ = d. The spectral gap, defined as d − λ₂, governs the expansion properties of the graph.

Pick a base and an edited file (or a git commit), press latexdiff, and TeXRA compiles and opens the marked-up PDF: additions underlined in blue, deletions struck through in red.

TeXRA generates diff files after agent runs that modify .tex files (such as correct or polish), comparing the agent's run-storage output (for example r0/intro.tex or r1/intro.tex for an intro.tex input) against the original input or the previous revision's output. You can see what the agent did as soon as the run finishes.

This guide explains how to use TeXRA's LaTeXdiff features to compare arbitrary file versions and how to read the results.

CLI

The LaTeXDiffs section buttons described below belong to the VS Code extension. The automatic post-run diffs are generated on every host, including texra run polish or texra run correct in the CLI, where the TUI lists them as "Latexdiff results". To diff two arbitrary files from the terminal, use the latexDiff agent, which wraps latexdiff to compare two LaTeX versions.

Controlling between-revision diffs ​

TeXRA compares each revision of agent output to your original input and can also create diffs between consecutive revisions (_diffr1r0.tex for the r0→r1 comparison). Between-revision diffs are off by default. Enable Diff consecutive rounds on Settings → LaTeX → Compile & diff (the texra.latexdiff.generateBetweenRoundDiffs setting). When off, the run command and progress notifications only account for the original-vs-revision comparisons, so fewer diff files are created.

Focusing diff PDFs on changed pages ​

By default, TeXRA passes --subtype=ONLYCHANGEDPAGE to latexdiff so compiled diff PDFs show only pages with edits. Disable Only changed pages in diff PDFs in the LaTeX tab when you need a full-document diff PDF.

The LaTeXDiffs section ​

The LaTeX diff features live in the "LaTeXDiffs" section ( LaTeXDiffs) of the TeXRA interface, shown in the slice above.

This section provides:

  1. Base file selection: Choose an original/base document
  2. Edited file selection: Select a modified version
  3. Diff vs. edited button: Run latexdiff on the base and edited files and open the marked-up result
  4. Compare button: Open the base and edited files side by side in VS Code's diff editor
  5. Merge button: Merge changes from the edited file into the base file. Read the Intelligent Merge workflow guide for details.
  6. Accept button: Accept the changes from the edited file and overwrite the base file with them
  7. Git integration: Pick a commit and use its Diff vs. commit, Move to Diffs folder, and Delete diff files buttons to compare with previous versions using Git history

Basic file comparison ​

To compare two LaTeX files:

Step 1: select files ​

  1. In the "Base File" dropdown ( Base), select the original version
  2. In the "Edited File" dropdown ( Edited), select the modified version

TIP

The "Current" button () selects the currently open file for either role. The "Empty" button () clears the selection for that role.

Step 2: generate the diff ​

Select the Diff vs. edited button () beneath the Edited dropdown. TeXRA then runs the same five-stage pipeline for every diff route; only the tool and output name change:

1Run latexdiff

Invokes the latexdiff tool on your selected base and edited files.

2Write diff .tex

Produces a marked-up LaTeX document.

original_diff.tex
3Open in editor

Automatically opens the generated diff source.

4Trigger build

Runs LaTeX Workshop's build command, if the extension is installed.

LaTeX Workshop
5Open PDF

After compilation, triggers the view command to show the diff PDF.

auto

After you press a diff button, TeXRA runs latexdiff, writes the marked-up .tex, opens it, then (with LaTeX Workshop installed) builds and views the compiled diff PDF.

Git-based version comparison ​

TeXRA can also compare documents with previous Git versions:

Step 1: select base file and commit ​

  1. Select a base file (typically your current working file) using the "Base File" dropdown ( Base).
  2. Choose a Git commit from the "Commit" dropdown ( Commit).

INFO

The commit dropdown shows recent commits. Select the refresh icon () next to the label to update the list.

Step 2: generate the diff ​

Select the Diff vs. commit button () beneath the Commit dropdown to compare your file with its version at the selected commit.

TeXRA runs the same five-stage pipeline shown above. This route uses the latexdiff-vc tool and names its output with the commit hash (for example original-diff<commit_hash>.tex).

Step 3: manage diff outputs ​

After generating a Git-based diff with Diff vs. commit, you can manage the resulting files from the Commit section's Move to Diffs folder () and Delete diff files () buttons. Move to Diffs folder moves the diff .tex and .pdf into a dated folder under Diffs/ and deletes their build files; Delete diff files removes them all.

Each diff route writes its own predictably named artifacts. latexdiff produces _diff.tex and latexdiff-vc appends the commit hash (-diff<hash>.tex), both alongside the base file. Document tasks write per-revision (_diff.tex) and between-revision (_diffr<newer>r<older>.tex) diffs into the run folder. Every .tex compiles to a matching .pdf. Both buttons act on the selected commit's diff files:

Diff artifactsnaming · lifecycle
Pack Clean
Source
  • spectral-gap.texbase
  • spectral-gap_polish_r1.texedited
Generated diffs
  • spectral-gap_diff.texlatexdiff
  • spectral-gap_diff.pdf
  • spectral-gap-diffa3f9c1.texa3f9c1latexdiff-vc
  • spectral-gap-diffa3f9c1.pdf
  • spectral-gap_diffr1r0.texbetween-round
  • spectral-gap_diffr1r0.pdf

The diff file-naming scheme as one set: the base/edited source pair, then each generated diff (latexdiff, latexdiff-vc with its commit hash, and between-revision) paired with its compiled PDF. Move to Diffs folder and Delete diff files file away or remove the selected commit's diff files.

Understanding diff output ​

The diff document uses dedicated markup to highlight changes:

Default markup ​

By default, latexdiff wraps each edit in a markup command that is defined in the preamble of the generated document and typesets the change inline:

latexdiff markupsource command · typeset result
  • Addition\DIFadd{efficient}We present an efficient method
  • Deletion\DIFdel{novel and }a novel and efficient method
  • Change\DIFdel{a graph} \DIFadd{a $d$-regular graph}Let $G$ be a grapha $d$-regular graph

latexdiff's source commands and how they typeset: \DIFadd{…} renders as a blue underlined addition, \DIFdel{…} as a red struck-through deletion, and adjacent del+add forms a change.

Math markup and multi-file projects ​

  • Math environments: The Math markup in diffs setting on Settings → LaTeX (texra.latexdiff.mathMarkup) controls how changes inside equations are marked (suppress markup, equation-level, within equations, or small changes inside equations) across every diff route.
  • Comparing multiple files: For documents split across several files, use the merge agent on each original/edited file pair, then diff the merged output against its original.

Troubleshooting ​

  • Missing or misaligned highlights: Run a formatter (latexindent or tex-fmt) on both files first so line breaks match, or adjust Math markup in diffs, Diff consecutive rounds, and Only changed pages in diff PDFs on Settings → LaTeX (the latexdiff timeout is in the CLI's /config).
  • Diff document fails to compile: Complex custom macros or unclosed environments can conflict with \DIFadd / \DIFdel markup. Check that both input files compile cleanly on their own, or lower Math markup in diffs to equation-level or suppress markup.
  • Git commit diff fails or shows no commits: Confirm the workspace is a Git repository, click the refresh icon () next to Commit, and verify the file existed at the selected commit under the same relative path.

Best practices ​

Before comparing, run a formatter (latexindent or tex-fmt) on both documents. Consistent indentation and line breaks keep latexdiff from flagging pure-whitespace changes.

When reviewing:

  1. Compile first: Compile the generated _diff.tex document to see the rendered changes (as shown in the slice at the top of this page). TeXRA does this automatically using LaTeX Workshop if it is installed. Live examples are embedded below.

  2. VS Code diff view: For a quick source-level comparison, pick the original (draft.tex) as the base file and the generated diff source (draft_diff.tex for a workspace diff, draft-diff<hash>.tex for a commit diff, or draft_diffr1r0.tex between revisions) as the edited file, then press Compare in the LaTeXDiffs section. This opens both files side by side in VS Code's diff editor, as shown below.

  3. Verify the fragile parts: mathematical expressions, cross-references, and citations are where AI edits most often go wrong.

draft.tex ↔ r0/draft.tex (Working Tree) — texra-sample
r0/draft.tex TeXRA
12\begin{abstract}
13We present an efficient method for the
14estimation of spectral gaps in random regular graphs.
15\end{abstract}
16
17\section{Preliminaries}
18Let $G$ be a $d$-regular graph.
draft.tex Previous draft
12\begin{abstract}
13We present a novel and efficient method for the
14estimation of spectral gaps in random regular graphs.
15\end{abstract}
16
17\section{Preliminaries}
18Let $G$ be a graph.

VS Code's side-by-side comparison of the original draft.tex against the generated diff source: additions and deletions highlighted line by line.

Embedded PDF examples ​

Individual PDF examples

Next steps ​