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.
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 task-storage output (for example r0/intro.tex or r1/intro.tex for an intro.tex input) against the original input or the previous round'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-round diffs
TeXRA compares each round of agent output to your original input and can also create diffs between consecutive rounds (_diffr1r0.tex for the r0→r1 comparison). Between-round diffs are off by default. Enable them from the Dashboard → LaTeX tab (the texra.latexdiff.generateBetweenRoundDiffs setting in the VS Code extension). When off, the run command and progress notifications only account for the original-vs-round 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 Show only changed pages in latexdiff PDFs in the LaTeX tab when you need a full-document diff PDF.
Understanding LaTeX diff
Standard text diff tools can be hard to read when comparing LaTeX source. LaTeX diff understands LaTeX syntax and produces readable, compilable LaTeX documents with changes highlighted. This approach has several advantages:
- Structural awareness: Respects LaTeX environments, math syntax, and macro boundaries
- Visual clarity: Highlights changes directly within the compiled PDF
- Compilable output: Produces standard, standalone LaTeX markup
- Scholarly focus: Built specifically for research documents containing complex equations, figures, and citation networks
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:
- Base file selection: Choose an original/base document
- Edited file selection: Select a modified version
- Diff button: Run
latexdiffon the base and edited files and open the marked-up result - Compare button: Open the base and edited files side by side in VS Code's diff editor
- Merge button: Merge changes from the edited file into the base file. Read the Intelligent Merge workflow guide for details.
- Accept button: Accept the changes from the edited file and overwrite the base file with them
- Git integration: Pick a commit and use its Diff, Pack, and Clean buttons to compare with previous versions using Git history
Basic file comparison
To compare two LaTeX files:
Step 1: select files
- In the "Base File" dropdown ( Base), select the original version
- 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 button () beneath the Edited dropdown. TeXRA then runs the same five-stage pipeline for every diff route; only the tool and output name change:
Invokes the latexdiff tool on your selected base and edited files.
Produces a marked-up LaTeX document.
Automatically opens the generated diff source.
Runs LaTeX Workshop's build command, if the extension is installed.
After compilation, triggers the view command to show the diff PDF.
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.
Step 3: review changes
The generated diff document highlights:
- Additions: Usually in blue or underlined
- Deletions: Usually in red or struck through
- Changes: Shown as deletions followed by additions
Git-based version comparison
TeXRA can also compare documents with previous Git versions:
Step 1: select base file and commit
- Select a base file (typically your current working file) using the "Base File" dropdown ( Base).
- 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 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 the Diff button beneath the Commit dropdown, you can manage the resulting files from the Commit section's Pack () and Clean () buttons. Pack archives the diff files; Clean removes them.
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. Agent runs write round (_diff.tex) and between-round (_diffr<newer>r<older>.tex) diffs into the run's task storage. Every .tex compiles to a matching .pdf. Pack and Clean act on the selected commit's diff files:
spectral-gap.texbasespectral-gap_polish_r1.texedited
spectral-gap_diff.texlatexdiffspectral-gap_diff.pdfspectral-gap-diffa3f9c1.texa3f9c1latexdiff-vcspectral-gap-diffa3f9c1.pdfspectral-gap_diffr1r0.texbetween-roundspectral-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-round) paired with its compiled PDF. The Pack and Clean buttons archive 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:
- Addition
\DIFadd{efficient}We present an efficient method - Deletion
\DIFdel{novel and }anovel andefficient method - Change
\DIFdel{a graph} \DIFadd{a $d$-regular graph}Let $G$ bea 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.
Interpreting complex changes
For complex LaTeX structures, pay attention to:
- Math environments: How changes inside equations are marked is configurable. The latexdiff math markup setting in the Dashboard's LaTeX tab (
texra.latexdiff.mathMarkup) offers suppress markup, equation-level, within equations, or small changes inside equations, and applies to every diff route - Nested environments: Changes within nested environments can be hard to read
- Command arguments: Changes to command arguments are marked specially
- Whitespace changes: May or may not be highlighted depending on settings
Advanced diff usage
Comparing multiple files
For documents split across multiple files:
- Use the
mergeagent instead of the basic diff - Select the multiple input files and their edited counterparts; the agent takes one or more original/edited file pairs, not a directory
- Review each merged output, then diff it against its original
Integration with workflow
LaTeX diff fits into several TeXRA workflows:
Document review workflow
- Generate the initial document with a suitable agent
- Make manual edits or use another agent for revision
- Use latexdiff to compare original and revised versions
- Review and accept or reject changes
- Use merge to create the final version
Collaborative editing workflow
- Share the base document with collaborators
- Receive edited versions back
- Use latexdiff to visualize each contributor's changes
- Use merge to incorporate changes selectively
- Generate diffs of the merged document to confirm the result
Version control workflow
- Commit document versions regularly to Git
- Use latexdiff-vc to compare with previous versions
- Track how the document evolves over time
- Identify when specific changes were made
- Recover and merge content from previous versions as needed
Under the hood
TeXRA's LaTeX diff builds on several tools:
latexdiff tool
latexdiff is a Perl script that compares LaTeX files and generates a marked-up LaTeX document highlighting differences.
TeXRA:
- Calls latexdiff with appropriate options
- Processes the output for consistency
- Applies additional formatting as needed
latexdiff-vc
latexdiff-vc (version control) extends latexdiff to work with version control systems like Git.
TeXRA:
- Retrieves file versions from Git history
- Passes them to latexdiff
- Manages the output files
Merge process
The intelligent merge process:
- Analyzes both documents semantically
- Identifies substantive changes
- Creates a new document combining the best elements
- Optionally generates a diff showing applied changes
Troubleshooting
Common diff issues
Problem: Missing or incomplete highlights
Solutions:
- Make sure both documents are valid LaTeX
- Check for complex structures that might confuse latexdiff
- Compare smaller sections of the document
Problem: Diff document doesn't compile
Solutions:
- Look for conflicting markup in the preamble
- Check for unclosed environments or commands
- Remove complex custom commands that might interfere with diff markup
Problem: Changes not aligned
Solutions:
- Keep the document structure similar between versions
- Adjust the latexdiff settings in the Dashboard's LaTeX tab: latexdiff math markup, latexdiff timeout (ms), Generate diffs between consecutive rounds, and Show only changed pages in latexdiff PDFs
- Break large changes into smaller edits
Git integration issues
Problem: No commits shown in dropdown
Solutions:
- Verify the document is in a Git repository
- Refresh the commit list using the refresh icon ()
- Check Git installation and configuration
Problem: Error when comparing with commit
Solutions:
- Make sure the file existed in the selected commit
- Check for file path changes or renames
- Verify Git access permissions
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:
Compile first: Compile the generated
_diff.texdocument 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.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.texfor a workspace diff,draft-diff<hash>.texfor a commit diff, ordraft_diffr1r0.texbetween rounds) 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.Verify the fragile parts: mathematical expressions, cross-references, and citations are where AI edits most often go wrong.
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
Version management
Keep a clear version strategy:
- Regular commits: Commit document versions at meaningful milestones
- Descriptive messages: Write commit messages that describe the changes
- Pack old diffs: Use the "Pack" button to archive diff files
- Clean unnecessary files: Remove temporary diff files when no longer needed
Next steps
- Intelligent Merge: combine changes from two versions
- File management: organize your files
- Best practices: recommended workflows using diff features