This question is not on how to manually install packages but how to install packages automatically via script. This question is not about MikTeX or the limited tex package management in certain linux distributions (e.g.Ubuntu).

This question is about the cases where those management tools are not available or when we don't want to mess with them or where they are not sufficient.

Question: Is there a script or tool that can install an arbitrary package by downloading it and installing it in the local tree?

The closest I got to that is the following script (which has lots of drawbacks):

mkdir -p ~/texmf
cd ~/texmf
wget http://mirror.ctan.org/macros/latex/contrib/$PACKAGE.zip
unzip $PACKAGE.zip
mkdir -p tex/latex/$PACKAGE
for a in *.dtx; do if [ -a $a ]; then latex $a; fi; done 
for a in *.ins; do if [ -a $a ]; then latex $a; fi; done 
cd -
cp -vf $PACKAGE/*.{sty,def,cls,cfg} tex/latex/$PACKAGE

It is pretty generic BUT the drawbacks include: not error resilient, does not track dependencies, it doesn't work for all packages, it can produce a mess of files sometimes if the script fails, it doesn't work for packages outside of contrib. Also it doesn't work for complicated packages and bundles.

The idea is to be able to just type, for example:

$ install_package pdfcomment 

Improvements to this script, or alternative tools or scripts are greatly appreciated. I'll be really happy for example, if it works for all these packages that are not available in the cluster (i.e. no root access) I use:

xkeyval oberdiek pgf pgfplots acrotex movie15 datetime filecontents
changepage paralist textcase placeins cool coollist coolstr coolstr
forloop bbm type1cm lastpage pdfmarginpar standalone tufte-latex ifpdf

EDIT: Thanks Seamus for the answer, it seems that a more robust script for TDS prepackaged packages is the following:

mkdir -p ~/texmf
cd ~/texmf
wget http://www.ctan.org/tex-archive/install/macros/latex/contrib/$PACKAGE.tds.zip
unzip $PACKAGE.tds.zip

(not all packages have a TDS version.)

  • The problem here is that different packages are sent to CTAN in different ways, and may require material is installed in various parts of the TDS tree. I know that the TeX Live people use some scripts to grab material from CTAN for incorporation, but that they have a long list of 'special cases' that the script needs to know about. On dependencies, there is no database of these, so I guess the best you could do is scan through the source files for \RequirePackage or \usepackage lines. That would not be fool-proof, though.
    – Joseph Wright
    Mar 26 '11 at 7:15
  • Your first script is missing quite a lot things. E.g. it won't install font packages, it forgots important file types like fd-files, ignores the documentation, it puts all files in tex\latex and forgets locations like tex\xetex or tex\generic etc. It won't work. Apr 1 '11 at 13:30
  • @Ulrike, that is what I say just below the code. It was just an example of what I want to achieve.
    – alfC
    Apr 1 '11 at 17:37
  • You said below the code "works with most". I doubt this. From your list of "working" packages type1cm can't work as it contains fd-files. pgf and xkeyval will perhaps work but they will not be installed correctly (they put files in tex\generic, pgf has a quite complicated folder structure), in the oberdiek package subpackages which use lua-files will probably not work and so on. Apr 1 '11 at 17:49
  • @Ulrike, I corrected the post (removed 'most')
    – alfC
    May 2 '11 at 3:36

A lot of the time, the TDS is a good option. You download package.tds.zip put it in your local texmf tree and unzip it. It puts all the files exactly where you want them.

This doesn't track dependencies, however.

  • thanks, I wasn't aware of the TDS packages. I found the actual files here ctan.org/tex-archive/install/macros/latex/contrib . I wonder what is the criterion to be in that list of TDS packages. It seems that not all packages have a TDS version, for example tufte-latex, pgfplots, pgf/tikz.
    – alfC
    Mar 26 '11 at 0:20
  • 2
    @alfC: TDS zips are contributed by package authors, and are a new-ish idea so only exist for packages updated in the last couple of years. CTAN do not require that they are supplied, so coverage is patchy.
    – Joseph Wright
    Mar 26 '11 at 7:10
  • @alfC: See tug.org/texlive/pkgupdate.html for more details on how TeX Live manages things.
    – Joseph Wright
    Mar 26 '11 at 14:49
  • I'll mark this as the accepted answer until a more generic script is presented.
    – alfC
    Apr 1 '11 at 17:39
  • 1
    @alfC What would you want a generic script to do? I'm pretty sure one doesn't exist. The best option by far is to be in charge of your own TeXLive installation and use their tlmgr
    – Seamus
    Apr 1 '11 at 18:55

alfC suggested elsewhere that my script might be "a good answer" to his question, so I'll give it a shot. The script is used instead of your favourite latex compiler; it both calls the compiler and detects missing packages to install in TeX Live. In short, it allows TeX Live "installation on the fly" similar to MiKTeX.

Dependencies: TeX Live (with its package manager, tlmgr), python (either 2 or 3 will do).

Script info + links: http://www.latex-community.org/forum/viewtopic.php?f=12&t=15194

As you can see from the dependencies, the script isn't a complete solution in itself, but rather "automates" TL's existing package management system. Technically, I believe tlmgr install [packagename] satisfies the requirements of the original question, but I suppose this counts as an "improvement" by allowing automatically running that (as well as the search) command while you're compiling.

I'm not sure if tlmgr's dependency resolving is already perfect, but even if not, the script will catch the rest of them. That's because all it does is repeatedly run the compiler until there are no more missing package errors (or until a failsafe, of course) and in the process of doing so, it should install all required packages! Note that, while it catches a fair number of fonts (thanks to Ulrike Fischer), the font algorithm is probably not perfect.

Update: Version 1.00 now allows you to set a custom TeX Live bin directory and defaults to non-sudo, thereby (I think) answering the rest of the question.

  • My question was oriented to the case where there is an incomplete latex installation at the system level (in read only dirs) and you want to complement that installation with your manually (or automatically) installed packages in your local dir, e.g. ~/.texmf. I believe tlmgr can not install additional packages in an arbitrary or local dirs instead of the existing system installation, can it? In fact, can your script add the packages without writing to the system install? (I don't have a computer to test now.)
    – alfC
    Sep 26 '11 at 7:00
  • 1
    Ah, I understand. In that case, you'd probably be interested in the new version of the script; it now allows you to set a custom texlive directory and defaults to non-sudo whenever possible. I've tested this with a texlive installed in $HOME/texlive (no superuser privileges) and it worked as expected!
    – scallops
    Sep 28 '11 at 9:36
  • I finally could test it; I really appreciate the script. However it sort falls in a crack. Since it relies in tlmgr (TeXLive), which is not available in preinstalled systems (e.g. Ubuntu) then it can't be used. Manually downloaded tlmgr executable will fail due to dependencies. I can have a manual local installation of TeXLive (tl-install) to obtain tlmgr but by that time I can already install everything from the tl-install. It still can be very useful for people used the MikTeX style of working; given that they already have a local installation of TeXLive. Why Ubuntu doesn't include "tlmgr"?
    – alfC
    Oct 4 '11 at 2:10
  • Beats me. As for tlmgr's dependences in a local install, I'm not sure how minimal a tl-install you can get away with; I usually tested it with the "basic scheme" (essentials + LaTeX) because those seem to be necessary to generate the lualatex executable, but you might be able to get away with just the essentials. Note: since my script essentially acts as a frontend to tlmgr install, it doesn't, as you've observed, provide any additional functionality, only convenience ;)
    – scallops
    Oct 4 '11 at 2:59

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.