New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support and document installation of LaTeXML via homebrew on Mac OS X #929

Closed
asmaier opened this Issue Jan 15, 2018 · 14 comments

Comments

Projects
None yet
4 participants
@asmaier

asmaier commented Jan 15, 2018

Many people use homebrew as package manager on Mac OS X (see https://brew.sh/analytics/os-version/). Unfortunately LaTeXML doesn't officially seem to support installation via homebrew and the available package has some issues: Homebrew/homebrew-core#22903 . Especially it is missing the dependency to Imagemagick and therefore after installation it is not possible to convert LaTeX files with images.
But I managed to install LaTeXML using homebrew with Imagemagick and want to document this here. Maybe this is helpful for someone or even can be added to the official documentation:

  1. Install LaTeXML via homebrew
$ brew install latexml
  1. Download the lastest version of ImageMagick (the formula for Imagemagick from homebrew doesn't work for LaTeXML)
$ wget https://www.imagemagick.org/download/ImageMagick.tar.gz
$ tar zxvf ImageMagick.tar.gz
$ cd ImageMagick
  1. Build and compile ImageMagick from source
$ ./configure --with-perl=/usr/bin/perl
$ make
$ make install
$ make clean
  1. Open a new terminal and check if you can use the perl package
$ /usr/bin/perl -le 'use Image::Magick; print Image::Magick->QuantumDepth'
16

After doing this the latexmlpost command should find the Image::Magick perl module and be able to convert images.

@matteosecli

This comment has been minimized.

Contributor

matteosecli commented Jan 30, 2018

Hi @asmaier, I'm able to install and use LaTeXML with Homebrew (on High Sierra 10.13.2) via:

$ brew install imagemagick --with-perl
$ brew install cpanm
$ cpanm Archive::Zip DB_File File::Which Getopt::Long Image::Size IO::String JSON::XS LWP MIME::Base64 Parse::RecDescent Pod::Parser Text::Unidecode Test::More URI XML::LibXML XML::LibXSLT UUID::Tiny
$ brew install latexml --HEAD

which installs the latest GitHub version with all the required and optional dependencies.

I agree, anyway, that the formula should be updated and that a mention in the documentation would be nice! 😉

@asmaier

This comment has been minimized.

asmaier commented Jan 30, 2018

@matteosecli Nice work. Your solution seems to work, because the HEAD version of latexml on github has fixed the shebang in the perl scripts from #!/usr/bin/perl -w to #!/usr/bin/env perl already. So the next release of LaTeXML will work better with perl installed via homebrew.

@dginev

This comment has been minimized.

Collaborator

dginev commented Jan 30, 2018

Excellent, thank you for all the information!

@matteosecli

This comment has been minimized.

Contributor

matteosecli commented Jan 30, 2018

@asmaier I'll try to figure out how to fiddle around with the current LaTeXML Homebrew formula to include these fixes, since it appears from your bug report Homebrew/homebrew-core#22903 that they only want pull requests.

@asmaier

This comment has been minimized.

asmaier commented Jan 31, 2018

I had a weird problem. The installation of the HEAD version of LaTeXML following the steps of @matteosecli failed on my machine. The two perl modules XML::LibXML XML::LibXSLT couldn't be build and installed. It turned out, that I had to outcomment the following line from my .bash_profile file:

# export PATH="/Users/andi/anaconda/bin:$PATH"

So somehow my version of Anaconda (https://www.anaconda.com/download/#macos) interfered with the build process of the Perl modules XML::LibXML XML::LibXSLT. Just in case you encounter similar problems, have a look at your .bash_profile.

@dginev

This comment has been minimized.

Collaborator

dginev commented Jan 31, 2018

... could you give us a list of files inside that /bin directory? Any chance there is some custom perl or libxml bundled in it?

matteosecli added a commit to matteosecli/homebrew-core that referenced this issue Feb 1, 2018

Update LaTeXML recipe with missing modules
Install all the necessary Perl modules for LaTeXML to work properly. Related issues: brucemiller/LaTeXML#929 and Homebrew#22903.

@matteosecli matteosecli referenced this issue Feb 1, 2018

Closed

Update LaTeXML recipe with missing modules #23562

4 of 4 tasks complete

BrewTestBot added a commit to BrewTestBot/homebrew-core that referenced this issue Feb 1, 2018

Update LaTeXML recipe with missing modules
Install all the necessary Perl modules for LaTeXML to work properly. Related issues: brucemiller/LaTeXML#929 and Homebrew#22903.
@matteosecli

This comment has been minimized.

Contributor

matteosecli commented Feb 1, 2018

@asmaier I've sent a PR to the Homebrew folks with an updated recipe for LaTeXML. It should solve many of the issues here, including your problems with the XML::LibXML and XML::LibXSLT modules; the Homebrewed LaTeXML + all the necessary modules should live in its own folder and will use Homebrew's Perl, so there are less chances of interferences.

I've tested the recipe in a clean High Sierra install and it seems to work; could you please give it a try?

Btw I've tried to track down all the non-core Perl modules (and their dependencies) that LaTeXML depends on, but there are chances I've missed some of them. If you get errors about missing modules let me know! 😉


Edit:
@asmaier I apologize, if you are on Sierra the new recipe in the PR won't work. If you are still willing to try it, I've fixed it here; now it should work!

BrewTestBot added a commit to BrewTestBot/homebrew-core that referenced this issue Feb 1, 2018

Update LaTeXML recipe with missing modules
Install all the necessary Perl modules for LaTeXML to work properly. Related issues: brucemiller/LaTeXML#929 and Homebrew#22903.
@asmaier

This comment has been minimized.

asmaier commented Feb 1, 2018

@dginev Don't worry too much about the problem with Anaconda. It turned out that my version of Anaconda was very old. I decided to simply delete it. And it seems to be a known problem, that Anaconda is often interfering with Homebrew, see https://hashrocket.com/blog/posts/keep-anaconda-from-constricting-your-homebrew-installs . So this is not a problem unique to LaTeXML.

@asmaier

This comment has been minimized.

asmaier commented Feb 1, 2018

@matteosecli I did install your new homebrew formula with

brew install https://raw.githubusercontent.com/matteosecli/homebrew-core/patch-1/Formula/latexml.rb

on Mac OS X 10.12.6 and it worked flawlessly. Imagemagick was installed and I was able to convert my latex document with images included. Thank you very much for this new homebrew formula for LaTeXML!

@matteosecli

This comment has been minimized.

Contributor

matteosecli commented Feb 1, 2018

@asmaier Happy to hear that it works! 😄

@brucemiller

This comment has been minimized.

Owner

brucemiller commented Feb 17, 2018

I'm a little confused by some of this. If there already is a Homebrew formula, the best approach would be to fix it (or get it fixed). It looks like @matteosecli submitted a PR, that wasn't accepted. While I don't know formula language, I took a look at it and was a bit confused. It seemed to have all sorts of dependencies (like HTTP::Cookie and lots of others) that aren't dependencies of LaTeXML. Perhaps this threw the Homebrew folks off, as well? The point being, I'm not sure how to distill this discussion into a "do this and that".

All the better: I've just spent some time reorganizing and fleshing out the wiki pages to hopefullly make them more welcoming :> Could I ask you guys @matteosecli and @asmaier to look at the "Installation Guide" wiki page and add something there? Thanks!!!

@matteosecli

This comment has been minimized.

Contributor

matteosecli commented Feb 18, 2018

@brucemiller you're perfectly right, the formula has to pull lots of dependencies.

My understanding is that Homebrew packages are installed in a way that limits to the lowest possible level the interference with the OS. In a certain sense, they look like small "containers" that are designed to communicate only with other Homebrew "containers" or with system libraries. So, they have to include all the necessary pieces in order to work independently from other non-Homebrew software.

Then, in a Homebrew formula you can have two kind on dependencies:

  1. software that is already shipped as a Homebrew formula, for which you can simply use something like depends_on "perl";
  2. software that is not shipped as a Homebrew formula, like language-specific dependencies (in this case, Perl modules).

In the second case, the official guidelines say that you have to pull these dependencies as resources and install them locally (not globally) as part of the "container" you are building. Take a look, for example, at this formula (which is in the official repo and it's not dissimilar to the formula I wrote). So, if you need e.g. Perl modules, you are not allowed to call cpanm from the installer and install the modules system-wide; you have to provide them locally only to LaTeXML. Of course, LaTeXML has lots of dependencies — and each of them has its dependencies; for example, HTTP::Cookies is a non-core dependency of LWP (which instead is a LaTeXML dependency) and so you have to install it if you want to install LWP.

That being said, I've recently tried to simplify a lot the formula (see Homebrew/homebrew-core#24254) by temporally using cpanm to fetch all the necessary Perl modules and install them in LaTeXML's "container", instead of manually taking care of all the sub-dependencies. The result is basically the same as before, but the formula is much more readable.

It turns out that the problem is not the readability or the complexity of the formula; they just don't like the fact that you have to pull many dependencies (despite the existence of formulas like the previous rex.rb that I linked). The only solution, according to them (see the comments in the last PR), is for you to ship LaTeXML tarballs with all the non-core modules included, which are built together with LaTeXML by a single Makefile; then the formula would just pull LaTeXML, make it, and that's done. That would mean, considering the sub-dependencies, that you would have to ship 40+ modules together with LaTeXML.

In addition, it appears that you cannot specify Homebrew dependencies with specific options. In this case, LaTeXMl depends on ImageMagick; however, Homebrew does not ship ImageMagick with it own Perl module by default. One could force a recompilation of ImageMagick with its Perl module by using depends_on "imagemagick" => "with-perl" in the formula, but this does not comply with the guidelines. Again the solution, according to them, is to ship ImageMagick with LaTeXML itself and build it locally (just for LaTeXML) with the --with-perl option.

So at this point, unless you really want to ship LaTeXML with all the modules and ImageMagick itself, I would say that there are three possibilities for the "Installation Guide" wiki:

  1. Advise people against installing LaTeXML with Homebrew, since the package is basically broken (LaTeXML is unusable if installed with Homebrew in a clean MacOS box) and people at Homebrew don't want to fix it unless there are heavy changes to the tarballs themselves.
  2. Provide LaTeXML users with a Homebrew formula which is maintained here and not in the Homebrew-core repo. Then the installation would just be brew install https://address-of/latexml.rb. However, I'd advise against it because in this way it would not possible to ship pre-compiled packages and (more importantly) provide updates, unless one sets up a specific Homebrew repository (called tap).
  3. Fill the gaps and write proper instructions for Homebrew users. That would include:
    • Install (or reinstall) ImageMagick with PerlMagick, via brew install imagemagick --with-perl;
    • Install the required Perl modules via cpanm: brew install cpanm && cpanm Archive::Zip DB_File File::Which Getopt::Long Image::Size IO::String JSON::XS LWP MIME::Base64 Parse::RecDescent Pod::Parser Text::Unidecode Test::More URI XML::LibXML XML::LibXSLT UUID::Tiny
    • Install LaTeXML itself brew install latexml. This would just pull a precompiled package of LaTeXML and install it, without caring about perl dependencies.

From my point of view, the third option is a hassle anyway since it requires different pre-installation steps; I would prefer just to pull the tarball and compile it myself. But it would have the benefit that, once installed the dependencies for the first time, all the subsequent updates would be automatic.

So, @brucemiller @asmaier what do you think? 🤔💭 Waiting for your thoughts!


PS: Sorry for the philippic! 😅

@brucemiller

This comment has been minimized.

Owner

brucemiller commented Apr 7, 2018

Sorry, I missed your response. Thanks for the detailed explanation of Homebrew formula. Actually, Homebrew's model (as I understand it) isn't actually much different from the other installation/repo systems I'm familiar with (rpm, debian, macports...), with exception of the apparent lack of formula for components. Are there really no pre-existing formula for perl's Archive::Zip, DB_File, LWP, etc? I tried searching, but maybe I did it wrong.Those "common" modules, I'd think, really deserve a separate formula of their own. Recursively disentangling their dependencies and embedding the resulting mess in any formula that needs them utterly violates any sensible modularity and maintainability. Although the resource mechanism seems to be a really useful last-resort, but hardly seems the right approach for most use cases.

But I'm confused about how introducing Image::Magick somehow cascaded into having to explicitly import all the LWP dependences. How did it work before? There's some comments in the other issues regarding which perl is used, but I didn't quite follow it. There's been a change since 0.8.2 involving the way perl gets invoked, in fact it now uses #!/usr/bin/env perl, so maybe that has an impact? Perhaps upcoming releases of LaTeXML will work as intended, and we should give up on mangling 0.8.2 to work around whichever limitations?

Not sure how to proceed for now, though. I would suppose it's possible to write a formula that uses the development version of LaTeXML, fetching a zip from github? That might answer some of these questions.

@brucemiller

This comment has been minimized.

Owner

brucemiller commented Jul 27, 2018

The best way I could think of to summarize this discussion was to put a link on the Wiki page to this discussion. Hope that helps somebody in the future.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment