Skip to content

Add manually-triggered GitHub Actions workflow for LaTeX diff generation#5

Merged
labarba merged 6 commits intomasterfrom
copilot/add-latexdiff-workflow
Jan 21, 2026
Merged

Add manually-triggered GitHub Actions workflow for LaTeX diff generation#5
labarba merged 6 commits intomasterfrom
copilot/add-latexdiff-workflow

Conversation

Copy link
Contributor

Copilot AI commented Jan 11, 2026

Adds a workflow_dispatch workflow that generates a PDF showing differences between the current LaTeX document and a previous version using latexdiff.

Implementation

  • Workflow file: .github/workflows/latexdiff.yml
  • Trigger: Manual execution via Actions UI
  • Input: Optional compare_with parameter (tag/commit, defaults to latest tag)
  • Steps:
    • Checkout with full history (fetch-depth: 0)
    • Auto-detect latest tag or use specified reference
    • Install LaTeX packages (texlive-latex-base, texlive-latex-extra, texlive-publishers, texlive-science, texlive-fonts-recommended) and latexdiff
    • Run latexdiff --flatten to compare old and current versions of main.tex including all \input files (introduction.tex, methods.tex, etc.)
    • Compile diff to PDF with pdflatex
    • Upload diff PDF as downloadable artifact

Usage

Navigate to Actions → "LaTeX Diff" → "Run workflow". Optionally specify a tag/commit to compare against. Download the generated diff PDF from workflow artifacts.

Security

Workflow includes explicit permissions: contents: read following least-privilege principle.

Original prompt

Objective

Add a manually-triggered GitHub Actions workflow that runs latexdiff to compare the current version of the LaTeX document with the last tagged release (or a specified commit/tag).

Requirements

  1. Create a new workflow file at .github/workflows/latexdiff.yml
  2. The workflow should use workflow_dispatch trigger for manual execution only
  3. Include an optional input parameter to specify which tag/commit to compare against (defaults to latest tag if not specified)
  4. The workflow should:
    • Checkout the repository with full history (fetch-depth: 0)
    • Determine the comparison reference (latest tag or user-specified)
    • Install all necessary LaTeX packages and latexdiff
    • Run latexdiff between the old version (from tag/commit) and current main.tex
    • Compile the diff output to PDF
    • Upload the resulting diff PDF as an artifact

Workflow Details

  • Main LaTeX file: main.tex
  • Required LaTeX packages:
    • texlive-latex-base
    • texlive-latex-extra
    • texlive-publishers (for elsarticle class)
    • texlive-science (for siunitx)
    • texlive-fonts-recommended
    • latexdiff

Workflow Content

name: LaTeX Diff

on:
  workflow_dispatch:
    inputs:
      compare_with:
        description: 'Tag or commit to compare with (leave empty for latest tag)'
        required: false
        default: ''

jobs:
  latexdiff: 
    runs-on: ubuntu-latest
    
    steps: 
    - name: Checkout code
      uses: actions/checkout@v5
      with:
        fetch-depth: 0
    
    - name: Get comparison reference
      id: ref
      run: |
        if [ -n "${{ github.event.inputs.compare_with }}" ]; then
          REF="${{ github.event.inputs.compare_with }}"
        else
          REF=$(git describe --tags --abbrev=0 2>/dev/null || echo "")
        fi
        echo "ref=$REF" >> $GITHUB_OUTPUT
        echo "Comparing with: $REF"
    
    - name: Install LaTeX and latexdiff
      run: |
        sudo apt-get update
        sudo apt-get install -y \
          texlive-latex-base \
          texlive-latex-extra \
          texlive-publishers \
          texlive-science \
          texlive-fonts-recommended \
          latexdiff
    
    - name: Run latexdiff
      if: steps.ref.outputs.ref != ''
      run: |
        TEX_FILE="main.tex"
        git show ${{ steps.ref.outputs.ref }}:$TEX_FILE > old.tex
        latexdiff old.tex $TEX_FILE > diff.tex
        
    - name: Compile diff PDF
      if: steps.ref.outputs.ref != ''
      run: |
        pdflatex diff.tex
        
    - name: Upload diff PDF as artifact
      if: steps.ref.outputs.ref != ''
      uses: actions/upload-artifact@v4
      with: 
        name: latexdiff-output
        path: diff.pdf

Usage

After merging, users can run this workflow by:

  1. Going to the "Actions" tab
  2. Selecting "LaTeX Diff" from the workflows list
  3. Clicking "Run workflow"
  4. Optionally entering a specific tag or commit to compare against
  5. Downloading the generated diff PDF from the workflow artifacts

This pull request was created from Copilot chat.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 2 commits January 11, 2026 22:22
Co-authored-by: labarba <4800109+labarba@users.noreply.github.com>
Co-authored-by: labarba <4800109+labarba@users.noreply.github.com>
Copilot AI changed the title [WIP] Add manually-triggered latexdiff workflow for LaTeX documents Add manually-triggered GitHub Actions workflow for LaTeX diff generation Jan 11, 2026
Copilot AI requested a review from labarba January 11, 2026 22:25
@labarba
Copy link
Member

labarba commented Jan 11, 2026

@piyueh – Would you mind giving this idea a sanity check? It occurred to me that it would be very nice to have a manually-triggered GitHub action that runs latexdiff and lets you download the PDF. If this works I would use it with every manuscript!

@piyueh
Copy link
Collaborator

piyueh commented Jan 21, 2026

I think this is very helpful if it works. But I'm not very familiar with GitHub Actions scripts. Let me ask another AI to take a look...

@piyueh
Copy link
Collaborator

piyueh commented Jan 21, 2026

@codex Can you review this pull request?

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e3193f0a25

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +48 to +50
TEX_FILE="main.tex"
git show ${{ steps.ref.outputs.ref }}:$TEX_FILE > old.tex
latexdiff old.tex $TEX_FILE > diff.tex

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Include \input files in diff generation

The workflow runs latexdiff only on main.tex, but in this repo main.tex is largely just a series of \input{...} section files. As a result, edits inside files like introduction.tex, methods.tex, etc. won’t appear in diff.tex, so the produced PDF can look unchanged even when the document content changed. To make the diff reliable, the diff step needs to flatten/include the \input files (e.g., latexdiff --flatten or latexdiff-vc).

Useful? React with 👍 / 👎.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot Is this a concern? If yes, can you fix it?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@codex Read the latest commit and see if this is fixed.

@piyueh
Copy link
Collaborator

piyueh commented Jan 21, 2026

@copilot There is a concer/comment for you to address: #5 (comment)

Please.

Co-authored-by: piyueh <7220966+piyueh@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Jan 21, 2026

@copilot There is a concer/comment for you to address: #5 (comment)

Please.

Fixed in commit 60548c6. Added --flatten flag to latexdiff to include all \input files (introduction.tex, methods.tex, etc.) in the diff generation.

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 60548c685c

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@labarba
Copy link
Member

labarba commented Jan 21, 2026

OMG this thread is fascinating

@piyueh
Copy link
Collaborator

piyueh commented Jan 21, 2026

@copilot I made some changes. Review the latest commit.

Copy link
Contributor Author

Copilot AI commented Jan 21, 2026

@copilot I made some changes. Review the latest commit.

Reviewed commit c4119d5. Excellent fix! Using git archive to extract all files from the old commit ensures that latexdiff --flatten can find all the old \input files. My previous approach only extracted main.tex, which would have caused latexdiff to fail or use the wrong (current) versions of the input files. The workflow is now correct and ready to use.

@piyueh
Copy link
Collaborator

piyueh commented Jan 21, 2026

@codex Can you give this PR another pass of review?

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c4119d54d2

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@piyueh
Copy link
Collaborator

piyueh commented Jan 21, 2026

@codex Any other issues?

@chatgpt-codex-connector
Copy link

Review Outcome: No Additional Issues Found

After reviewing the current workflow, I don’t see any additional issues beyond those already addressed. The workflow now (1) fails clearly when no tag is available and compare_with is empty, and (2) uses git archive plus latexdiff --flatten so included files from the old revision are properly compared against the current tree. These fixes address the earlier concerns about missing \input files and confusing no-op runs when tags are absent. .github/workflows/latexdiff.ymlL23-L68

Commands Used

Testing

  • Not run (workflow-only review).

View task →

@piyueh
Copy link
Collaborator

piyueh commented Jan 21, 2026

@copilot I am happy with the PR now. Do another round of review and confirm you are okay with changes I made.

Copy link
Contributor Author

Copilot AI commented Jan 21, 2026

@copilot I am happy with the PR now. Do another round of review and confirm you are okay with changes I made.

Reviewed the complete workflow. All changes look excellent:

git archive approach (c4119d5) correctly extracts all old files for latexdiff --flatten
✅ Error handling (de8bbc7) provides clear feedback when no tags exist
✅ Security permissions are appropriate
✅ YAML syntax is valid
✅ Workflow logic is sound

The workflow is ready to merge and will work correctly for generating LaTeX diffs.

@piyueh
Copy link
Collaborator

piyueh commented Jan 21, 2026

OMG this thread is fascinating

@labarba I'm not familiar with GitHub Actions scripts, but Codex and Copilot are both happy with this PR now 😆

@labarba labarba marked this pull request as ready for review January 21, 2026 17:30
@labarba labarba merged commit 13c3be4 into master Jan 21, 2026
1 check passed
@labarba
Copy link
Member

labarba commented Jan 21, 2026

@piyueh – I created a tag for the submitted version from July 2023, and ran the Action... it worked!
Check it out: https://github.com/barbagroup/jcs_paper_pinn/actions/runs/21219440436

(the references appear with ? but I'm not sure if that is a limitation of latexdiff or it needed to run latex on it again to resolve the cite commands)

@piyueh
Copy link
Collaborator

piyueh commented Jan 22, 2026

@piyueh – I created a tag for the submitted version from July 2023, and ran the Action... it worked! Check it out: https://github.com/barbagroup/jcs_paper_pinn/actions/runs/21219440436

I got a zip file and had to unzip it to see the PDF with diff. Not sure if it must be in this way when using GitHub Actions.

(the references appear with ? but I'm not sure if that is a limitation of latexdiff or it needed to run latex on it again to resolve the cite commands)

I think latexdiff only generates a tex file that highlights the difference (the diff.tex in our case). The actual generation of the PDF is still done by compiling diff.tex with pdflatex. So if we also want to show references/citations in the PDF, GitHub Actions may need to also run bibtex/biber and run pdflatex multiple times, just like how we usually compile regular latex files from scratch. Right now GitHub Actions only compiles diff.tex with pdflatex once.

@labarba
Copy link
Member

labarba commented Jan 22, 2026

Interesting: I got a PDF file when clicking the download icon next to the latexdiff-output.

Today I copied the workflow to another repository (and added a feature to compare with a main file of different file name in the past commit). I will ask Copilot about the references issue.

Cool idea no?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants