LaTeX-Workshop: Formatting failed error

Description

When I activate globally “editor.formatOnSave” (as is done for a while it seems in VSCode), I get this error, everytime I save a Latex file:

screenshot 2018-01-12 13 53 36

I suspect this has something to do wit the fact that I need to enable “formatOnSave” on a global level now, to have it working for my Python programming.

I guess your package does not support formatting, which is why I get this error?

I deactivated the error message by adding this language-specific setting to my settings, like so:

    "[latex]": {
        "editor.formatOnSave": false,
    }

So, I’m fine, I was just wondering if there is actually automatic formatting available for this extension somehow? I will close this issue immediately, but wanted to create the issue for somebody else to find.

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 10
  • Comments: 33 (11 by maintainers)

Most upvoted comments

Encountered the same problem on Mac. Here are the packages I installed to make it work.

sudo cpan Log::Log4perl
sudo cpan Log::Dispatch
sudo cpan YAML::Tiny
sudo cpan File::HomeDir
sudo cpan Unicode::GCString

@thedadams , can u format ur code? (Not saving after formatting) Or u already solved it? It seems it’s just one case of failure.

I’m a Mac User too. My issue is unable to format codes. As @quicky84 said, the problem might be in latexindent not LaTeX-Workshop. Here is my error message:

[18:36:40] Formatting failed: Command failed: latexindent -c "/Users/yenWu/git/report-poly" "/Users/yenWu/git/report-poly/__latexindent_temp.tex" -y="defaultIndent: '    '"
Can't locate File/HomeDir.pm in @INC (you may need to install the File::HomeDir module) (@INC contains: /usr/local/texlive/2017/texmf-dist/scripts/latexindent /Library/Perl/5.18/darwin-thread-multi-2level /Library/Perl/5.18 /Network/Library/Perl/5.18/darwin-thread-multi-2level /Network/Library/Perl/5.18 /Library/Perl/Updates/5.18.2/darwin-thread-multi-2level /Library/Perl/Updates/5.18.2 /System/Library/Perl/5.18/darwin-thread-multi-2level /System/Library/Perl/5.18 /System/Library/Perl/Extras/5.18/darwin-thread-multi-2level /System/Library/Perl/Extras/5.18 .) at /usr/local/texlive/2017/texmf-dist/scripts/latexindent/LatexIndent/GetYamlSettings.pm line 23.
BEGIN failed--compilation aborted at /usr/local/texlive/2017/texmf-dist/scripts/latexindent/LatexIndent/GetYamlSettings.pm line 23.
Compilation failed in require at /usr/local/texlive/2017/texmf-dist/scripts/latexindent/LatexIndent/LogFile.pm line 19.
BEGIN failed--compilation aborted at /usr/local/texlive/2017/texmf-dist/scripts/latexindent/LatexIndent/LogFile.pm line 19.
Compilation failed in require at /usr/local/texlive/2017/texmf-dist/scripts/latexindent/LatexIndent/Document.pm line 25.
BEGIN failed--compilation aborted at /usr/local/texlive/2017/texmf-dist/scripts/latexindent/LatexIndent/Document.pm line 25.
Compilation failed in require at /Library/TeX/texbin/latexindent line 27.
BEGIN failed--compilation aborted at /Library/TeX/texbin/latexindent line 27.

If so, here is a shortcut.

sudo cpan Unicode::GCString
sudo cpan App::cpanminus
sudo cpan YAML::Tiny
sudo perl -MCPAN -e 'install "File::HomeDir"'

More details u can found in this issue in Atom-beaultifier.

File::HomeDir

Encountered the same problem on Mac. Here are the packages I installed to make it work.

sudo cpan Log::Log4perl
sudo cpan Log::Dispatch
sudo cpan YAML::Tiny
sudo cpan File::HomeDir
sudo cpan Unicode::GCString

In my case, File::HomeDir needs force install

sudo cpan -fi File::HomeDir

After I tried many many times in two days I solved it.

Solution is that : “latex-workshop.latexindent.path” in vs code settings you can change to your path ,just like this "latex-workshop.latexindent.path": "C:\\Users\\Jerry\\Downloads\\latexindent\\latexindent.exe"

Before of this, you should download latexindent.exe from latexindent . I find that installing from MikTeX console packages isn’t working, so you’d best installed by yourself.

@yenWu Yes, I fixed it. I was missing some perl modules. Thanks for checking.

You can find it by clicking on View -> Output in the menu and then selecting LaTeX Workshop from the dropdown on the right. It should have an entry starting with Formatting failed: and the error message.

and how do i find that mysterious log? 😉

@adam-erickson Provided you already have latexindent installed on your Mac, In Visual Studio Code’s settings, go to Latex-workshop > Latexindent: Path, then set the path to something like /usr/local/texlive/2018/texmf-dist/scripts/latexindent/latexindent.pl. Hope this helps.

@fabiocapasso93 unfortunately this cannot be fixed on the extension side. This is up to the user to set the paths of the different tools properly on his installation.

Also, see the wiki page. Feel free to suggest improvements for this page if you think it is detailed enough.

So I just installed MiKTeX on Windows to reproduce this issue. Here is how I got it to work:

  • According to this StackExchange post, MiKTeX stopped distributing Perl a couple of years ago so you will need to download and install Perl from here
  • Then you need to install the latexindent package using the MiKTeX Package Manager
  • Afterwards you have to install the missing perl modules from cpan using cpan on the command line. In my case those were Log::Log4perl , Log::Dispatch::FileShared, YAML::Tiny and Unicode::GCString (the exact missing packages can be found by executing the formatter a mentioned above and checking the log)
  • At last there was one bug I found which I will submit a PR for shortly

I am having this same issue now after using the extension for some time. I have latexindent installed and the Output has no information in it.