Notes on TeX Live setup

From STMDocs
Jump to navigation Jump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.


This page describes steps to install TeX Live (TL from now) and needed tweaks so that other kpathsea programs that are not part of TL can also use TL data. This is useful if we recompile some program from sources and want it to be able to find TL data. For example, one might want to recompile pdftex with some patch, and use it instead of the binary coming with TL.

This guide was written for TL2008 on Ubuntu linux 8.04 and should work with no or little change for other Linux/UNIX systems.

When in doubt, please refer to the official TeX Live documentation. This guide serves as a quick guide for some very specific purposes:

  • how to install TL with minimal effort and confusion
  • how to use TL data with non-TL binaries
  • how to use different versions of pdftex
  • how to add local packages in a systematic way

Install TL

  • start with a shell where no tex-related environment variables are defined. A quick check can be done by
printenv | fgrep TEX
cd $HOME/iso-images
unlzma texlive2008.iso.lzma
  • mount the TL image:
mkdir -p /mnt/texlive2008
mount -t iso 9660 -o loop $HOME/iso-images/texlive2008.iso /mnt/texlive2008/
  • run the TL installer:
perl /mnt/texlive2008/install-tl
  • in next menu, change the destination of installation to /opt/texlive/2008 by entering:
  • start the installation process by entering i<Enter>. When the installation process is done, the last messages should look like this:
 pre-generating all format files (fmtutil-sys --all), be patient...done

 for links to documentation.  The TeX Live web site ( 
 contains any updates and corrections.

 TeX Live is a joint project of the TeX user groups around the world;
 please consider supporting it by joining the group best for you. The
 list of groups is available on the web at

 Add /opt/texlive/2008/texmf/doc/man to MANPATH.
 Add /opt/texlive/2008/texmf/doc/info to INFOPATH.
 Most importantly, add /opt/texlive/2008/bin/i386-linux
 to your PATH for current and future sessions.

 Welcome to TeX Live!

/mnt/texlive2008/install-tl: done.
Logfile: /opt/texlive/2008/install-tl.log
  • N.B.: if you are not using i386-linux, the value to be added to the PATH variable is different; for example if you are using 64-bit linux, the installation log will report x86_64-linux instead of i386-linux.
  • create a partial copy of the main TL configuration file (we will modify this copy later):
cat /opt/texlive/2008/texmf/web2c/texmf.cnf | \
grep -v '^%' > /opt/texlive/2008/texmf.cnf
  • change some environment variables permanently as instructed by the installation log: add to /etc/profile the following lines (don't forget to check the value of PATH if you are not using i386-linux):
## added for TeX Live
  • logout and login again to ensure that the above environment variables are set. With bash as the default shell, it can be done by saying:
exec bash -login
  • test the installation:
pdflatex sample2e
  • if things go well, we should get a log similar to the below:
$ pdflatex sample2e
This is pdfTeXk, Version 3.1415926-1.40.9 (Web2C 7.5.7)
 %&-line parsing enabled.
entering extended mode
LaTeX2e <2005/12/01>
Output written on sample2e.pdf (3 pages, 69560 bytes).
Transcript written on sample2e.log.

Keeping packages up-to-date

There are 2 possible ways to keep packages up-to-date:

mkdir -p /opt/texlive/tds-packages
cd /opt/texlive/tds-packages
cd /opt/texlive/texmf-local
unzip ../tds-packages/
texhash `pwd`
  • it's a good idea to keep the tds packages around, so that we know which packages have been installed this way.

Use non-TL binaries with TL data

TL and all kpathsea programs use one or more config files called texmf.cnf to search for needed data. In previous steps we have already defined an environment variable TEXMFCNF, which in sequence causes that all kpathsea programs will read first the customized config file /opt/texlive/2008/texmf.cnf, then the default TL config file /opt/texlive/2008/texmf/web2c/texmf.cnf. The values defined in the first texmf.cnf will override values in the later one(s).

It is critical to have TEXMFCNF defined explicitly as above. If TEXMFCNF is not defined, it's very hard to track down which config file(s) are being read, since there can be several texmf.cnf files laying around and which of them are read depends on quite a few factors. By setting TEXMFCNF to a fixed value, we can get rid of this headache and can concentrate on our customized config file /opt/texlive/2008/texmf.cnf

Since we have already defined TEXMFCNF in previous step and made a copy of texmf.cnf, now it is simple to make non-TL binaries work with TL data: we change our texmf.cnf to get rid of SELFAUTOPARENT as follows:

sed -i -e 's:.SELFAUTOPARENT:/opt/texlive/2008:' /opt/texlive/2008/texmf.cnf

Add another texmf tree

Suppose we have tetex previously installed to /opt/tetex-3.0. The tetex texmf tree is then located at /opt/tetex-3.0/share/texmf. To add this texmf tree to our setup, we do this:

ln -s /opt/tetex-3.0/share/texmf /opt/texlive/texmf-tetex
sed -i '
TEXMFTETEX = /opt/texlive/texmf-tetex
s/^\(TEXMF = .*\)}/\1,$TEXMFTETEX}/
' /opt/texlive/2008/texmf.cnf
texhash /opt/texlive/texmf-tetex

We can repeat the above steps to add as many texmf trees as we need. For each texmf tree we must:

  • choose a variable name that it's not used yet (TEXMFTETEX in the above example)
  • locate the path to the texmf tree, and make a symlink in /opt/texlive
  • adjust the above commands accordingly.

Or, it is possible to use this script to automate the above steps. Usage:

sh TEXMFTETEX /opt/texlive/texmf-tetex /opt/texlive/2008/texmf.cnf

The script will do some checking before changing texmf.cnf to ensure that the parameters are correct. The current texmf.cnf will be backed up with timestamp appended like e.g. texmf.cnf--2008-10-20.19:43:05

Use ls-R or not

Each texmf tree can have a file called ls-R at the top level, which can help to speed up searching if the texmf tree is large. But using ls-R is not always the best option, since it requires some extra effort to get it right. If a texmf tree is small and changes often, it's better not to use ls-R. If a texmf tree is large, then it's worthwhile to go for the trouble.

To use ls-R with the texmf tree in the previous example, we must:

  • edit texmf.cnf:
    • change $TEXMFTETEX to !!$TEXMFTETEX (only on one line -- the one starting with TEXMF = ...
  • run texhash /opt/texlive/texmf-tetex to make ls-R in sync with the contents of texmf tree.

Failing to do any of the above steps will cause that some files might not be found as expected, and it's not always easy to trace down the reason.

Change the order of file searching

If we need to change the precedence of a texmf tree, we can edit texmf.cnf and change the variable TEXMF. TEXMF specifies which texmf trees are searched, and in which order. The order of the texmf trees given in TEXMF is important: earlier trees take precedence over the later ones in TEXMF.

Some notes on other relevant variables

  • TEXMFDBS: contains list of texmf trees with ls-R filename databases. It's not clear how the presence of ls-R in a texmf tree and the presence of that tree in TEXMF and TEXMFDBS are related. To avoid potential problems, it's better to stick with either one of the below scenarios:
    • no ls-R, no presence of texmf tree in TEXMFDBS, presence in TEXMF without !!
    • ls-R in sync with contents of texmf tree, presence in TEXMF and TEXMFDBS with !!
  • SYSTEXMF (not listed above): contains a list of system texmf trees; its meaning is roughly this: if the source of a font is found in a system texmf tree and that tree is not writable for the current user, then the scripts mktexpk, mktextfm, and mktexmf will install their output into VARTEXFONTS, otherwise the generated fonts (tfm/pk/mf) will be left in the current directory. If we are not using MF fonts, we can safely forget this variable. If we are using MF fonts and want the fonts generated on-the-fly to be placed to proper location, we must add the relevant texmf tree to SYSTEXMF. Usually not needed, since most TeX fonts are available in outline formats and when not, they can be easily converted from MF to Type1 format using textrace. It is best if we can avoid touching this variable.

Run pdftex compiled from sources

Sometimes it's desirable to run a different version of pdftex than the one that comes with TL, for example when we want to run pdftex with some features or bugfixes not included in the version in TL. Then we must compile pdftex from sources and do some extra steps.

  • compiling pdftex from sources: download pdftex sources tarball and apply patches if needed. Suppose that we have unpacked pdftex sources to $HOME/src/pdftex-1.40.9, then to build it:
cd $HOME/src/pdftex-1.40.9
  • when the above process finishes, the pdftex binary should be located at $HOME/src/pdftex-1.40.9/build/texk/web2c/pdftex
  • make symlinks (suppose that $HOME/bin is in $PATH):
ln -s $HOME/src/pdftex-1.40.9/build/texk/web2c/pdftex $HOME/bin/pdftex2
ln -s $HOME/src/pdftex-1.40.9/build/texk/web2c/pdftex $HOME/bin/pdflatex2
  • find out the location of format files:
ls -d $(dirname $(kpsewhich -engine=pdftex pdflatex.fmt) )
  • create formats:
cd /tmp

pdftex2 -ini -translate-file=cp227.tcx '*pdfetex.ini'
mv pdfetex.fmt /opt/texlive/2008/texmf-var/web2c/pdftex/pdftex2.fmt

pdflatex2 -ini -translate-file=cp227.tcx '*pdflatex.ini'
mv pdflatex.fmt /opt/texlive/2008/texmf-var/web2c/pdftex/pdflatex2.fmt

  • test the new binary:
pdftex2 story \\bye
pdflatex2 sample2e
  • repeat the above steps for other versions if needed; substitute pdftex2/pdflatex2 with whichever names that suit better your need/taste.

Maintain packages installed locally

If we keep installing local packages to a texmf tree for some time, we will find out that it's getting difficult to keep track of what has been installed, and how to remove or upgrade a package. This is the place where a package management system is useful. We will use miktex tools to maintain our local packages.

Install miktex tools

  • download miktex sources from
  • unpack the source tarball to $HOME/src/miktex-2.7.3135
  • install all PREREQUISITES listed in ~/src/miktex-2.7.3135/README.unx
  • compile and install:
cmake -G "Unix Makefiles" -DMIKTEX_INSTALLROOT=/opt/texlive/texmf-local -DCMAKE_INSTALL_PREFIX=/opt/miktex-2.7.3135
make install
  • if things go well, the miktex tools will be installed to /opt/miktex-2.7.3135.
  • TODO: we will make a tarball of pre-compiled miktex tools binaries for i386-linux and x86_64-linux, to save the compilation step for you. Then to install it, one can simply unpack the tarball to /opt.
  • we need to make a wrapper to run miktex tools. Create a file named run-miktex-tools with file mode 755 and with the following contents:
export LD_LIBRARY_PATH=/opt/miktex-2.7.3135/lib
export PATH=/opt/miktex-2.7.3135/bin:$PATH
ExecCmd() {
    echo "$@"                      
case "$tool" in                    
    ExecCmd $tool $opt "$@"        
    ExecCmd $tool "$@"             
  • test if it works -- we should get help messages on mpm usage from the below command:
run-miktex-tools mpm --help
  • up to this point, miktex tools are setup so that it will look for available packages at /opt/miktex-repository/package-repository and install requested packages to /opt/texlive/texmf-local.

Set up miktex repository

Before we can use miktex tools to install any packages, we must set up the local package repository.

mkdir -p  /opt/miktex-repository/package-repository
cd /opt/miktex-repository/package-repository
run-miktex-tools mpm --update-db

Create a package for use with miktex tools

Suppose we have a texmf tree and we want to create a package from that texmf tree.

(to be continued)