15

I'm using the basicTeX distribution, rather than the MacTeX distribution. I prefer it this way, but there is one problem. I does not come with the tool latexindent which MacTeX does.

I can't figure out how to install this tool manually. There is no proper description on the CTAN page or on it's Github page. Any help? I want to install it in the PATH.

Andrew Swann
  • 95,762
eivindml
  • 534

5 Answers5

13

OK, things are a little bit different now:

brew install --cask basictex
sudo tlmgr install latexindent
cpan -i YAML::Tiny File::HomeDir Unicode::GCString

and if you want to have the LaTeX Workshop extension on Visual Studio Code working, add the line

"latex-workshop.latexindent.path": "/Library/TeX/texbin/latexindent"

in the settings.json, you need to also install

sudo tlmgr install latexmk

tested on macOS Catalina 10.15.4.

cmhughes
  • 100,947
Foad
  • 893
11

I found a solution. Latexindent was not present using tlmgr at first, but after updating repository and trying again, I was able to install it.

For anyone else, this is what I did (root required):

sudo tlmgr option repository ctan
sudo tlmgr update --self
sudo tlmgr install latexindent

So probably outdated or a wrong repo URL at first.

ctan is just an alias for http://mirror.ctan.org/systems/texlive/tlnet

eivindml
  • 534
  • 1
    glad you found a solution! :) you can also download the .zip file from https://github.com/cmhughes/latexindent.pl and then use one of the helper scripts to help with path variables, detailed in the documentation – cmhughes Sep 11 '17 at 17:34
  • 2
    This works in Windows PowerShell as well if you remove sudo and instead run PowerShell as Administrator – Jan Hohenheim Apr 05 '18 at 00:12
4

For anyone trying to install Latexindent.pl on a clean Mojave installation (macOS 10.14.1, November 2018) so that it works with Atom and other IDEs, there are some more steps required.

First, because some of the perl helper modules require compilation, you'll need a working installation of C and perl:

  1. Make sure that you have Xcode installed and working, including command line tools.

    sudo xcode-select --switch /Library/Developer/CommandLineTools

  2. Make the header files for c etc. available; see the comment from @Maxx here (https://stackoverflow.com/questions/52509602/cant-compile-c-program-on-a-mac-after-upgrade-to-mojave):

I quote:

If we are using XCode 10, you will notice that if you navigate to /usr in the Finder, you will not see a folder called 'include' anymore which is why the terminal complains of the absence of the header files which is contained inside the 'include' folder. In this release statement, developer.apple.com/documentation/xcode_release_notes/… (you navigate to /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg and run that package to have the 'include' folder installed). Then you should be good to go.

  1. Install cpan through the terminal to help with perl installations:

cpan App::cpanminus

The next step is to get Latexindent working as a standalone tool:

  1. Install it using tlmgr as described elsewhere on this page
  2. Download the entire Latexindent zip from https://github.com/cmhughes/latexindent.pl.
  3. Open a terminal window
  4. In the terminal navigate to the "helper-scripts" directory
  5. Run sudo perl latexindent-module-installer.pl to get all of the other required perl modules installed.

You can now test latexindent.pl by opening a new terminal and navigating to the directory where your .tex file is (let`s call it test.tex). Once there, you can test it without changing your file:

latexindent.pl test.tex

From this point on there are many more useful examples in the documentation on readthedocs or the CTAN Package PDF.

This means that latexindent.pl now works with atom-beautify.

Andy Clifton
  • 3,699
  • ... I do wonder if this train wreck was caused by a failed latexindent install when I didn't have X-code installed – Andy Clifton Nov 25 '18 at 13:25
  • I just spent the past three hours getting latexindent working and installing the required modules from the command line installed them, but latexindent still complained it couldn't find one of them (Log::Log4perl). The only way I got everything working was to follow the instructions here https://tex.stackexchange.com/a/445536 and installing the modules form inside cpan. I've no idea why this was necessary. – LaTeXereXeTaL Jul 18 '20 at 01:06
  • Log4perl no longer required, I sincerely hope this eases installation – cmhughes Sep 23 '21 at 18:46
4

Nowadays(2022), just using brew:

brew install latexindent

See also: Homebrew latexindent

杨雪念
  • 41
  • 1
1

To install the missing Perl modules I have followed the instructions in:

https://gist.github.com/LucaCappelletti94/920186303d71c85e66e76ff989ea6b62#cpan--latexindent

installing Perl modules with "sudo" option. After that, I am able to run latexindent