28

I have Strawberry Perl and MiKTeX v2.9 installed on Windows 10 with the latexindent package installed via the MiKTeX console.

However, running latexindent.pl in the command prompt results in the following error

Can't locate Log/Log4perl.pm in @INC (you may need to install the Log::Log4perl module) (@INC contains: C:/Program Files/MiKTeX 2.9/scripts/latexindent C:/Strawberry/perl/site/lib C:/Strawberry/perl/vendor/lib C:/Strawberry/perl/lib) at C:/Program Files/MiKTeX 2.9/scripts/latexindent/LatexIndent/LogFile.pm line 22. BEGIN failed--compilation aborted at C:/Program Files/MiKTeX 2.9/scripts/latexindent/LatexIndent/LogFile.pm line 22. Compilation failed in require at C:/Program Files/MiKTeX 2.9/scripts/latexindent/LatexIndent/Document.pm line 25. BEGIN failed--compilation aborted at C:/Program Files/MiKTeX 2.9/scripts/latexindent/LatexIndent/Document.pm line 25. Compilation failed in require at C:\Program Files\MiKTeX 2.9\scripts\latexindent\latexindent.pl line 27. BEGIN failed--compilation aborted at C:\Program Files\MiKTeX 2.9\scripts\latexindent\latexindent.pl line 27.

Additionally, this answer doesn't help in removing the error. So, what is missing here?

4
35

For others running into the same issue but on a Mac:

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:

cpan

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

Catalina Update

If the installation fails with an error message that sounds like a permissions issue, that may be due to security changes in Catalina. In that case, try forcing the installation:

cpan -fi \
  Log::Log4perl \
  Log::Dispatch::File \
  YAML::Tiny \
  File::HomeDir \
  Unicode::GCString
7
  • 1
    The question is for OS W10. – Sebastiano Dec 22 '19 at 19:06
  • 26
    People searching for the same issue on a Mac (per my case) also end up on this page. – songololo Dec 22 '19 at 19:38
  • 6
    I also needed install Unicode::GCString Mac catalina and TeXLive 2019 – Spangen Apr 19 '20 at 9:29
  • 2
    @LaTeXereXeTaL brew is a separate package manager on the Mac. It is completely unrelated to Latex but allows you to install third-party packages (like perl in this case) that might be used by Latex. Google "homebrew" for installation instructions. – songololo Jul 22 '20 at 10:26
  • 1
    I had to add sudo: sudo cpan -fi .... – Jeffrey Knight Feb 17 at 17:29
33

Thanks to @Nicola's comment, the error can be fixed as follows:

  1. The missing module is Log::Log4perl as found in the first line of the error.
  2. Open Win 10 start menu and search for CPAN client, then open it and run install Log::Log4perl. However, it may fail due to the common bug, which needs the installtion to be forced by running force install Log::Log4perl (from the CPAN client) or the other command prompt commands given by the answers to this question. In other words, for instance, the command cpan -f -i Log::Log4perl must be run from the command prompt NOT the CPAN client.
  3. Another module might be missing whose name can be identified as similarly done in the first step and installed the same way.
9
  • 9
    For the record, on my Debian, the additional missing modules where Log::LogDispatch, Log::Dispatch::File, YAML::Tiny and File::HomeDir. You can install them all at once using cpan Log::LogDispatch Log::Dispatch::File YAML::Tiny File::HomeDir. – Clément Dec 23 '18 at 2:19
  • 3
    For MacOS, this also included Unicode::GCString, so the full installation solution was: cpan -i Log::Log4perl Log::LogDispatch Log::Dispatch::File YAML::Tiny File::HomeDir Unicode::GCString. This should be packaged to run at the end of brew install mactex. – Adam Erickson Sep 5 '19 at 20:27
  • @Clément cpan Log::Dispatch Log::Dispatch::File YAML::Tiny File::HomeDir – Bonjour123 May 3 '20 at 1:30
  • This solution finally got latexindent working after over two hours of trying to get it to work on my Mac. The perl installation didn't correctly update my PATH and I had to manually fix that. Then, as described here, I had to install the modules from inside cpan and none of the other documentation mentions that. Pretty frustrating experience. I hope I can get latexindent working on my MacBook Pro without the hassle. – LaTeXereXeTaL Jul 18 '20 at 1:39
  • 1
    Too much installation just for indenting automatically – Emre Sülün Sep 21 '20 at 13:46
1

MacOS Big Sur

New problems arise for Big Sur. Here is my Fix.

(The solution assumed you've installed homebrew. )

Step 1. Install the perl & its package manager

brew install perl
brew install cpanm

Step 2. Create symlink for MacOSX10.14.sdk

Install the missing packages directly will raise the build error:

clang: warning: no such sysroot directory: '/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk' [-Wmissing-sysroot]

That's because:

Apple decided to stop naming their SDKs with versions but rather name them MacOSX.sdk and include an alias with the version name for compatibility

So we create symlink for this folder. (Difference between recent SDKs is minor)

> cd /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs
> sudo ln -s MacOSX.sdk MacOSX10.14.sdk

Step 3. Install the missing packages

cpanm YAML::Tiny
cpanm File::HomeDir
cpanm Unicode::GCString
cpanm Log::Log4perl
cpanm Log::Dispatch
1

As of Version 3.9 the Log4Perl module is no longer loaded by latexindent.pl.

Details of the required perl modules are documented and sample installations steps are given in .travis.yml and appveyor.yml

I sincerely hope that this eases installation and use of the tool. If you can help make latexindent.pl better, or have any questions, please visit https://github.com/cmhughes/latexindent.pl.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.