Tx · LaTeX & TikZ

Fix “latexdiff: The Perl Script Could Not Be Found”

Published By the 9to5Science editorial team

At a glance

  1. 1. Check the installation

    In a terminal, check whether latexdiff and Perl are both available.

  2. 2. Install or repair latexdiff

    Use MiKTeX Console to install or update the latexdiff package, then refresh the file-name database.

  3. 3. Make Perl available

    If Perl is missing, install a Perl distribution and ensure its executable is on PATH.

  4. 4. Test outside your editor

    Run latexdiff from a terminal on two source files before configuring an editor.

The message “The Perl Script could not be found” usually comes from MiKTeX’s launcher for latexdiff, not from your .tex document. latexdiff compares two LaTeX source files and produces a third file showing their changes. MiKTeX needs to find the script that performs the comparison; depending on your setup, it may also need a Perl interpreter available on your system.

The precise fix depends on which part is missing. Check the MiKTeX package installation and Perl separately rather than changing your document or repeatedly reinstalling your editor.

1. Check what Windows can find

Open Command Prompt or PowerShell and run:

where.exe latexdiff
where.exe perl

If where.exe latexdiff returns a path, Windows can find a latexdiff command. If it returns nothing, MiKTeX’s binary directory may not be on PATH, or the package may not be installed. If where.exe perl returns nothing, Perl is not available through the current PATH.

You can also check Perl directly:

perl -v

A version message means Perl is available. If the command is not recognized, install a Perl distribution such as Strawberry Perl, then open a new terminal so it reads the updated PATH.

2. Install or repair the MiKTeX package

Open MiKTeX Console for the same installation that your editor uses. In the Packages area, search for latexdiff and install it, or update it if it is already present. Then use the console’s task to refresh the file-name database.

If you have both a per-user and an administrator MiKTeX installation, make sure you are managing the one used by your editor. Installing a package in one installation does not make it available to the other. If MiKTeX asks whether to install missing packages on the fly, allow the installation or install the package in advance through the console.

Afterwards, close and reopen the terminal and check again:

where.exe latexdiff
latexdiff --version

The version command should print version information. If the command is still found at an unexpected old location, Windows may be running another copy first because of the order of entries on PATH.

3. Confirm that Perl can run the script

MiKTeX packages and launchers can differ by version and installation. If the latexdiff command is present but still reports that the script cannot be found, check whether the script itself is installed. MiKTeX’s kpsewhich utility can often locate it:

kpsewhich latexdiff.pl

If this prints a path, the script exists in a location MiKTeX can find. If it prints nothing, return to MiKTeX Console, install or repair latexdiff, and refresh the file-name database again.

If you have the script path and Perl installed, you can test the script directly by passing its full path to Perl, followed by the two input files. The precise script path varies by MiKTeX installation, so use the path reported by kpsewhich rather than copying a path from another computer. If direct execution works but latexdiff does not, the problem is likely with the launcher, a stale installation, or which executable Windows finds first.

4. Test with two files

From Command Prompt, change to the folder containing the files and run:

latexdiff old.tex new.tex > diff.tex

This compares old.tex with new.tex and writes the marked-up result to diff.tex. Then compile the result:

pdflatex diff.tex

Use quotation marks around filenames that contain spaces, for example:

latexdiff "old draft.tex" "new draft.tex" > diff.tex

If this test works in the terminal, but not from TeXnicCenter or another editor, the installation is probably fine. The editor may be using a different PATH, MiKTeX installation, or command configuration. Configure the editor to invoke the same latexdiff command that worked in the terminal, and restart it after changing environment variables.

Common mistakes

  • Treating this as a LaTeX compilation error. The message is about finding a script or interpreter; it occurs before the changed document can be compiled.
  • Installing Perl but not the MiKTeX package. Perl alone does not provide MiKTeX’s latexdiff.pl script.
  • Installing the package but assuming Perl is present. Check perl -v; installing MiKTeX does not necessarily install a system Perl distribution.
  • Updating the wrong MiKTeX installation. User and administrator installations can have separate package databases and executable directories.
  • Testing only inside an editor. A terminal test helps separate an editor configuration problem from an installation problem.
  • Copying a script into a random folder. Repair the package and file-name database instead, so MiKTeX can manage the script and its location correctly.

References

  1. CTAN: latexdiff package
  2. Strawberry Perl

Spotted an error? Send a correction. Read how we write and check articles in our editorial policy.