Notes on TeX Live setup: Difference between revisions

From STMDocs
Jump to navigation Jump to search
Line 141: Line 141:
/^TEXMFLOCAL/ a\
/^TEXMFLOCAL/ a\
TEXMFTETEX = /opt/texlive/texmf-tetex
TEXMFTETEX = /opt/texlive/texmf-tetex
s/^\(TEXMF = .*\)}/&,$TEXMFTETEX}/
s/^\(TEXMF = .*\)}/\1,$TEXMFTETEX}/
' /opt/texlive/2008/texmf.cnf
' /opt/texlive/2008/texmf.cnf
texhash /opt/texlive/texmf-tetex
texhash /opt/texlive/texmf-tetex

Revision as of 23:15, 20 October 2008

Introduction

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.01 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

<geshi lang="bash"> printenv | fgrep TEX </geshi>

<geshi lang="bash"> cd $HOME/iso-images unlzma texlive2008.iso.lzma </geshi>

  • mount the TL image:

<geshi lang="bash"> mkdir -p /mnt/texlive2008 mount -t iso 9660 -o loop $HOME/iso-images/texlive2008.iso /mnt/texlive2008/ </geshi>

  • run the TL installer:

<geshi lang="bash"> perl /mnt/texlive2008/install-tl </geshi>

  • in next menu, change the destination of installation to /opt/texlive/2008 by entering:
d<Enter>
1<Enter>
/opt/texlive/2008<Enter>
r<Enter>
  • 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

 See 
   /opt/texlive/2008/index.html 
 for links to documentation.  The TeX Live web site (http://tug.org/texlive/) 
 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 http://tug.org/usergroups.html.

 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):

<geshi lang="bash"> cat /opt/texlive/2008/texmf/web2c/texmf.cnf | \ grep 'SELFAUTOPARENT\|^TEXMF \|^TEXMFDBS ' | \ grep -v '^%' > /opt/texlive/2008/texmf.cnf </geshi>

  • 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):

<geshi lang="bash">

    1. added for TeX Live

TEXMFCNF=/opt/texlive/2008:/opt/texlive/2008/texmf/web2c MANPATH=/mnt/texlive2008/texmf/doc/man:$MANPATH INFOPATH=/mnt/texlive2008/texmf/doc/info:$INFOPATH PATH=/opt/texlive/2008/bin/i386-linux:$PATH export TEXMFCNF MANPATH INFOPATH PATH </geshi>

  • 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:

<geshi lang="bash"> exec bash -login </geshi>

  • test the installation:

<geshi lang="bash"> pdflatex sample2e </geshi>

  • 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
(/mnt/texlive2008/texmf-dist/tex/latex/base/sample2e.tex
LaTeX2e <2005/12/01>
.
.
.
Output written on sample2e.pdf (3 pages, 69560 bytes).
Transcript written on sample2e.log.

Keeping packages up-to-date

  • Tell TL that we want to update packages from TL site:

<geshi lang="bash"> tlmgr option location http://mirror.ctan.org/systems/texlive/tlnet/2008 </geshi>

  • check which packages can be updated:

<geshi lang="bash"> tlmgr update --list </geshi>

  • update one package (rerun without --dry-run when you are sure):

<geshi lang="bash"> tlmgr update --dry-run <package-name> </geshi>

  • update all package (rerun without --dry-run when you are sure):

<geshi lang="bash"> tlmgr update --dry-run --all </geshi>

  • Recommendations for update:
    • don't update until you know why you have to (don't touch things that aren't broken)
    • backup before update, so things can be reverted if needed. See tlmgr manual for further info on backup/restore.
    • do not update all packages in one go

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: <geshi lang="bash"> sed -i -e 's:.SELFAUTOPARENT:/opt/texlive/2008:' /opt/texlive/2008/texmf.cnf </geshi>

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: <geshi lang="bash"> ln -s /opt/tetex-3.0/share/texmf /opt/texlive/texmf-tetex sed -i ' /^TEXMFLOCAL/ a\ TEXMFTETEX = /opt/texlive/texmf-tetex s/^\(TEXMF = .*\)}/\1,$TEXMFTETEX}/ ' /opt/texlive/2008/texmf.cnf texhash /opt/texlive/texmf-tetex </geshi>

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.
  • update the ls-R database of the new texmf tree.

Or, it is possible to use the below script to automate the above steps. Save it to a file called eg add-texmf-tree. <geshi lang="bash">

  1. !/bin/bash
  2. script to add a texmf tree to texmf.cnf
  3. Usage: $0 <variable-name> <texmf-location> /path/to/texmf.cnf
  4. Example: $0 TEXMFTETEX /opt/texlive/texmf-tetex /opt/texlive/2008/texmf.cnf

VARNAME=$1 LOCATION=$(echo "$2" | sed 's,/$,,') CFG_FILE=$3

ExitWithError() {

   echo -e "Error: $@"
   exit

}


  1. check the arguments for possible mistakes
  2. __________________________________________

[ -n "$CFG_FILE" ] || ExitWithError "Missing argument(s).\nUsage: $0 <variable-name> <texmf-location> /path/to/texmf.cnf" [ -d $LOCATION ] || ExitWithError "$LOCATION is not a directory" [ -f $CFG_FILE ] || ExitWithError "$CFG_FILE is not a regular file" [ -w $CFG_FILE ] || ExitWithError "$CFG_FILE is not writable"

echo $VARNAME | grep -q '^TEXMF[A-Z0-9_]*$' || \

   ExitWithError "<variable-name> can contain only uppercase letter, digits and underscore and must start with 'TEXMF'"

grep -q '^TEXMF = ' $CFG_FILE || \

   ExitWithError "$CFG_FILE do not contain TEXMF; is it a texmf.cnf file?"

! grep -q "^$VARNAME = " $CFG_FILE || \

   ExitWithError "$VARNAME is already used in $CFG_FILE; choose a different name"


  1. backup texmf.cnf before changing it:
  2. _____________________________________

cp $CFG_FILE $CFG_FILE--`date '+%Y-%m-%d.%T'`


  1. change texmf.cnf
  2. _________________

sed -i " /^TEXMFLOCAL/ a\ $VARNAME = $LOCATION s/^\\(TEXMF = .*\\)}/\\1,\$$VARNAME}/ " $CFG_FILE </geshi>

Usage: <geshi lang="bash"> sh add-texmf-tree.sh TEXMFTETEX /opt/texlive/texmf-tetex /opt/texlive/2008/texmf.cnf </geshi>

Some notes on the relevant variables above:

  • 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. Edit texmf.cnf manually to change the order if needed.
  • TEXMFDBS: contains list of texmf trees with ls-R filename databases. Running texhash without arguments will re-generate ls-R for texmf trees listed in TEXMFDBS. It's OK to have ls-R in a tree not listed in TEXMFDBS; it will be used, but will not be updated by running texhash.
  • 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.

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:

<geshi lang="bash"> cd $HOME/src/pdftex-1.40.9 ./build.sh </geshi>

  • 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):

<geshi lang="bash"> 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 </geshi>

  • create formats:

<geshi lang="bash"> cd $(kpsewhich -expand-var '$TEXMFVAR')/web2c/pdftex pdftex2 -ini -translate-file=cp227.tcx '*pdfetex.ini' mv pdfetex.fmt pdftex2.fmt pdflatex2 -ini -translate-file=cp227.tcx '*pdflatex.ini' mv pdflatex.fmt pdflatex2.fmt </geshi>

  • test the new binary:

<geshi lang="bash"> pdftex2 story \\bye pdflatex2 sample2e </geshi>

  • 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 http://miktex.org/SourceCode.aspx
  • 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:

<geshi lang="bash"> cmake -G "Unix Makefiles" -DMIKTEX_INSTALLROOT=/opt/texlive/texmf-local -DCMAKE_INSTALL_PREFIX=/opt/miktex-2.7.3135 make make install </geshi>

  • 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:

<geshi lang="bash">

  1. !/bin/bash

export LD_LIBRARY_PATH=/opt/miktex-2.7.3135/lib export PATH=/opt/miktex-2.7.3135/bin:$PATH

opt="--repository=/opt/miktex-repository/package-repository" tool=$1 shift

ExecCmd() {

   echo "$@"                      
   "$@"                           

}

case "$tool" in mpm|mpc)

   ExecCmd $tool $opt "$@"        
   ;;
  • )
   ExecCmd $tool "$@"             
   ;;                             

esac exit </geshi>

  • test if it works -- we should get help messages on mpm usage from the below command:

<geshi lang="bash"> run-miktex-tools mpm --help </geshi>

  • 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. <geshi lang="bash"> mkdir -p /opt/miktex-repository/package-repository cd /opt/miktex-repository/package-repository wget http://www.ctan.org/tex-archive/systems/win32/miktex/tm/packages/miktex-zzdb1-2.7.tar.lzma wget http://www.ctan.org/tex-archive/systems/win32/miktex/tm/packages/miktex-zzdb2-2.7.tar.lzma run-miktex-tools mpm --update-db </geshi>

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)