41

I use MiKTeX on Windows and quite satisfied with it. Recently I started switching all my tasks toward open-source alternatives, and in the course I would love to use Linux. In Linux TeXLive is available as alternative to MiKTeX. The thing I really like about MiKTeX, is its ability to install packages automatically. Can I do the same in TeXLive too? Is there a way I can enable such or install some plugins for it?

I am using Fedora 18, if that's needed.

  • 1
    Welcome to TeX.sx! – jubobs Apr 24 '13 at 14:20
  • 8
    You are new, so @Jubobs was being friendly :-) – Joseph Wright Apr 24 '13 at 14:27
  • 8
    Oh!! That link scared me!! – rafee Apr 24 '13 at 14:30
  • 5
    If you install the complete TeX Live collection (~2400 packages) you'll never ever need to add new packages. Everything will work just fine and all you'll need to do will be a matter of tlmgr update -all from time to time or tlmgr update <package> if you need something specific. As a Linux user I strongly suggest you not to install your distribution packages but go directly to the source and install TeX Live via one of these methods. This is closer to the Unix way of doing things and you will not regret it in the long run. – Nico Boni Apr 24 '13 at 14:48
  • 1
24

While in MiKTeX an installation process is automatically triggered if you have, say, \usepackage{beamer} in a document preamble without the corresponding package installed, there is no such feature on TeX Live.

The last statement is not true actually, as pointed out by wasteofspace in the comments there is the texliveonfly package that implements the on demand installation in TeX Live 2010 and later. I never tested it and don't know if it has drawbacks.

However, if you install the full (or almost full) TeX Live collection of packages (~2400) you will not need to add new packages, a periodic tlmgr update -all will take care of everything, including the installation of packages added to the TeX Live collection after you first full installation. This feature is explained in the tlmgr manual.

Analogously, if a package has been added to a collection on the server that is also installed locally, it will be added to the local installation. This is called auto-install and is announced as such when using the option --list. This auto-installation can be suppressed using the option --no-auto-install

The manual has lots of info on useful commands and it is a recommended reading for every user.

The downside is of course that you need the full set of packages installed in your machine, which may be a problem if you don't have enough free space. If you really can't spare 2GB from your HD, it is also possible to install TeX Live in a, say, 4GB USB key and live happily ever after :)

Everything I just wrote requires that you install TeX Live with one the methods described here. If you decide to use the TeX packages from your distro you are forced to follow their update policy, which is different for different distros

  • 4
    never???! so the op will never be interested in an update, or in a new package? intriguing. i would suggest the texliveonfly package. (i can’t recommend it, since i’ve never used it, but it looks appropriate.) – wasteofspace Apr 25 '13 at 9:04
  • The OP will never have to care about packages because (i) he already has all available packages at the time of installation and (ii) packages added to TeX Live list after the first install will automatically be added via tlmgr update -all. I think that in the end you will install the vast majority of packages anyway, so it is simpler to just install everything and forget about it. However the package you mentioned looks interesting, didn't know about it, too bad I can't test since I already have the full installation ;) – Nico Boni Apr 25 '13 at 12:04
  • can I use texliveonfly with TeXstudio? I tried replacing pdflatex command with "texliveonfly.py %tex", but that didn't do the job – rafee Apr 28 '13 at 15:04
  • 2
    It works for me with the following command: texliveonfly --compiler=pdflatex <filename>.tex (issued from a terminal, I don't know about TeXstudio). If you aren't using lualatex you need to specify the compiler with an option, since the default is set to lualatex. Also the documentation of the package is outdated, since the option --engine is no longer recognized. To be sure that everything is set to work, check if the a script called texliveonfly is inside your /bin directory. – Nico Boni Apr 28 '13 at 15:14
  • 1
    @rafee I would be very wary of this, personally. Either it is installing into the main or local tree, which it ought not have permission to do, or it is installing packages into your personal tree. That is asking for trouble and will certainly cause headaches - especially, though not only, in the case of font packages. If people use this, they should make absolutely certain they understand what exactly it does and that they know when they need to undo things and which errors and problems to look out for. – cfr Dec 22 '15 at 1:41
6

texliveonfly

As mentioned in comments, there is a TeX Live package called texliveonfly which you can use with texliveonfly filename.tex, and it will automatically downloaded the right TeX Live packages.

This also works for packages for which the LaTeX package name and the TeX Live package name don't match (for example the LaTeX rubikrotation package is contained in the rubik TeX Live package), and it also takes package dependencies into account.

Usage

Installing It is a Python script so it requires Python to be installed. You can then install it like usually with tlmgr install texliveonfly. If you have to use sudo tlmgr here, you will have to use sudo texliveonfly later.

Running If you go in your terminal to the directory of your filename.tex file, you can run it with texliveonfly filename.tex.

Other compilers At the moment it uses pdflatex by default, but you can configure it to run with other compiler engines by using the --compiler (or -c) flag, so like texliveonfly --compiler=lualatex filename.tex.

Compiler flags You can pass flags for the compiler you use to texliveonfly using the --arguments (or -a) flag, so for example if you previously used latexmk -shell-escape -pdf filename.tex then you now use texliveonfly --compiler=latexmk --arguments='-shell-escape -pdf' filename.tex.

Known problems

  1. There are some cases of missing packages which fail with a non-standard error message, for example babel when it's missing languages, in which case texliveonfly doesn't download them. At the moment the following packages are known to have to be installed manually: (please edit if you find more)

    • Babel languages, for example for european languages install the collection-european package
    • Biblatex styles, e.g. for the nature style you need the biblatex-nature package
    • fontenc encodings, e.g. to get t2aenc.def you need the cyrillic package, and to get the ly1enc.def you need the ly1 package.
  2. When giving options to texliveonfly, for example for a different compiler, it sometimes hangs for no apparent reason when installing packages. You can most probably work around it by first running texliveonfly without options, so texliveonfly main.tex (so it will download the packages) and then running whatever you wanted to, for example latexmk main.tex.

Background

Essentially texliveonfly is a build tool like latexmk (which is a Perl script), it wraps the TeX engine. Note however that you can chain them with texliveonfly --compiler=latexmk filename.tex.

It is a python script which works by trying to run your LaTeX file, and if it fails because a package is missing it will try to install that package.

Besides on ctan.org/pkg/texliveonfly you can view the source at ctan.org/tex-archive/support/texliveonfly or on latex.org/forum

PS I tested this on Arch Linux 4.19.4 and on Travis CI (Ubuntu 14.04).

3

My rather simplistic approach was to search for \usepackage, extract the contents and install using the distribution's package manager.

cat *.tex | sed -n 's/^[^%]*\\usepackage[^{]*{\([^}]*\)}.*$/tex\(\1.sty\)/p' | paste -sd ' ' -

This returns a list of packages with .sty and surrounded by tex(), e.g. tex(amsmath.sty) tex(enumitem.sty) tex(graphicx.sty). I can pass these straight to yum/dnf (I'm using Fedora).

sudo dnf install $( cat *.tex | sed -n 's/^[^%]*\\usepackage[^{]*{\([^}]*\)}.*$/tex\(\1.sty\)/p' | paste -sd ' ' - )

There were a couple of packages I had split over multiple lines that the sed expression missed, which I installed manually using sudo dnf install 'tex(some-package-name.sty)'.

Hopefully there's a simple .sty installing equivalent for apt-get on ubuntu.

  • 1
    Thank you jozxyqk. I used your command in this form: cat *.tex | sed -n 's~^[^%]*\\usepackage[^{]*{\([^}]*\)}.*$~\1.sty~p'|while read file; do tlmgr install $file; done This work like a charm for me. – Daniel Borges Aug 29 '16 at 16:33
2

There is no such functionality builtin as mentioned. However, with some botching one can create a small wrapper that does exactly that.

Simply scanning the packages is often not enough because you don't get the dependencies.

itex uses expect to catch errors and install the packages on the fly.

https://github.com/dopefishh/itex

With itex you only need to install the texlive infrastructure and the script will install the rest.

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.