Latex-workshop: LatexIndent Failed

Created on 23 Feb 2018  路  9Comments  路  Source: James-Yu/LaTeX-Workshop

[01:54:11] Formatting failed: Command failed: latexindent -c "c:\Users\usr\Desktop\Math\Tex\23FebProofs" "c:\Users\usr\Desktop\Math\Tex\23FebProofs\__latexindent_temp.tex" -y="defaultIndent: '    '"
Can't locate Log/Log4perl.pm in @INC (you may need to install the Log::Log4perl module) (@INC contains: C:/Users/usr/AppData/Roaming/MiKTeX/2.9/scripts/latexindent C:/Perl64/site/lib C:/Perl64/lib .) at C:/Users/usr/AppData/Roaming/MiKTeX/2.9/scripts/latexindent/LatexIndent/LogFile.pm line 22.
BEGIN failed--compilation aborted at C:/Users/usr/AppData/Roaming/MiKTeX/2.9/scripts/latexindent/LatexIndent/LogFile.pm line 22.
Compilation failed in require at C:/Users/usr/AppData/Roaming/MiKTeX/2.9/scripts/latexindent/LatexIndent/Document.pm line 25.
BEGIN failed--compilation aborted at C:/Users/usr/AppData/Roaming/MiKTeX/2.9/scripts/latexindent/LatexIndent/Document.pm line 25.
Compilation failed in require at C:\Users\usr\AppData\Roaming\MiKTeX\2.9\scripts\latexindent\latexindent.pl line 27.
BEGIN failed--compilation aborted at C:\Users\usr\AppData\Roaming\MiKTeX\2.9\scripts\latexindent\latexindent.pl line 27.

Getting this error whenever I try to format the document. Tried reinstalling, but it didn't fix.

Most helpful comment

i have this formatting error constantly and I'm quite at a loss what I should do (macOS 10.12.6), I'm using MacTex 2017, and have no issue running Latex otherwise. What am I supposed to do to fix this? Every compile with vscode creates this annoying formatting error.

All 9 comments

You are missing the required perl dependencies of latexindent. The easiest way to work around that is to download latexindent from ctan (because it bundles all dependencies) and then configure Latex Workshop to use that latexindent using latex-workshop.latexindent.path.

@zoehneto I downloaded latexindent from CTAN just now and I tried to run latexindent-module-installer, but it fails and I cant see the log as it instantly closes.

Update: apparently there is no reason to run that module installer. I was still getting errors with latexindent, but I noticed that in my path, I had latexindent in several folders, and even as I had new packaged latexindent location configured properly in vscode, system still ran latexindent from the environment path. This might help others debug the issue. I think it will be nice if you write a tutorial for latexindent or make it somehow easier, because this took me a while to figure out.

The module installer installs the needed modules but it requires you to have perl and cpanm installed. You want to point latex-workshop.latexindent.path to the latexindent.exe file also contained in the ctan package.

Latexindent works, but https://i.imgur.com/WcpzWz2.png I'm getting this error now.
On every save, a new filename.bak is generated

This should not be related to the extension. Did you modify the file with some other external program?

As a side note, because it seems resolved in this extent: I had exactly the same problem (missing Perl dependencies which I have attempted unsuccessfully to resolve using CPAN). The I have realized that latexindent.pl indicated in README.md works fine, because it brings all of the dependencies inside one executable. So it was as easy as downloading one zip.

i have this formatting error constantly and I'm quite at a loss what I should do (macOS 10.12.6), I'm using MacTex 2017, and have no issue running Latex otherwise. What am I supposed to do to fix this? Every compile with vscode creates this annoying formatting error.

@michaelaye these steps fixed the issue on my system.

Install perl via brew:

brew install perl

Use cpan to install the necessary perl packages:

Open cpan and select yes if necessary to setup the config automatically:


Then install any packages mentioned in your error logs, you may need to install and retry several times to figure out all of the packages you need.

In my case these packages fixed the error messages:

install Log::Log4perl
install Log::Dispatch::File
install YAML::Tiny
install File::HomeDir
Was this page helpful?
0 / 5 - 0 ratings