SolvedLaTeX 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.

34 Answers

✔️Accepted Answer

@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.

Other Answers:

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

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.

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

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.

Related Issues:

13
LaTeX Workshop LaTeX toolchain terminated with error
I had to completely restart VS Code (quit all instances) before it was able to find latexmk. ...
9
LaTeX Workshop Cannot compile .tex files on MacOS
Here's mine: The key is that a) the first recipe listed is used by default; b) the recipe used has t...
8
LaTeX Workshop Formatting failed error
@thedadams can u format ur code? (Not saving after formatting) Or u already solved it? It seems it's...
3
LaTeX Workshop Synctex inverse search doesn't work half the time (and How I got forward search to work for SumatraPDF)
Yes browser works indeed My apologies However still this is a maybe good work-around and not a solut...