Skip to content

Instantly share code, notes, and snippets.

@Rmano
Last active May 25, 2024 17:26
Show Gist options
  • Save Rmano/75771fae633f90d305a9dc38210e7e08 to your computer and use it in GitHub Desktop.
Save Rmano/75771fae633f90d305a9dc38210e7e08 to your computer and use it in GitHub Desktop.
My multiple TeXLIve installation

To use (and develop packages) for LaTeX I have a couple of contrasting needs:

  1. to use the most recent possible version, maybe even the development version,to check that my code/package still works, and
  2. to use the distribution-provided version which is ormally lagging behind, sometimes even years.

My solution is to install the distribution-provided package and also install a "portable" version of the current TeXLive distribution; then a bit of shell magin let you switch from one to another. The advantage of a portable installation is that you can install it with your normal user privileges, no need to go root for this.

A kind-of step by step is the following (disclaimer: tested with Ubuntu and Manjaro distros, I use zsh as my shell; it should work with bash too but I am not 100% sure). I have no idea on how to adapt this to Windows or Mac.

  1. Install your distribution texlive package. In debian related is something like sudo apt install texlive full or something like that (adapt to your choice of packages).
  2. Get the TeXLive network installer, which is basically a file called install-tl-unx.tar.gz
  3. Choose a directory under your home directory. For example, I have texliveYYYY pattern, but you may prefer to have texlive/YYYY or whatever. I will continue the example with my choice, edit as needed.
  4. Uncompress the installer file here (tar xvf location/of/install-tl-unx.tar.gz)
  5. Change directory to the one the installer creates (for example cd install-tl-20240314)
  6. Run the installer: perl ./install-tl; you can add a -repository https:/mypreferredrepo if you want, look at the list of mirrors
  7. Configure the installation (Say 'no' if you are offered to load a previous configuration, or say 'yes' and modify what's needed). You will have a screen with the default options:
    ======================> TeX Live installation procedure <=====================
    
    ======>   Letters/digits in <angle brackets> indicate   <=======
    ======>   menu items for actions or customizations      <=======
    = help>   https://tug.org/texlive/doc/install-tl.html   <=======
    
     Detected platform: GNU/Linux on x86_64
    
     <B> set binary platforms: 1 out of 15
    
     <S> set installation scheme: scheme-full
    
     <C> set installation collections:
         40 collections out of 41, disk space required: 8392 MB (free: 22810 MB)
    
     <D> set directories:
       TEXDIR (the main TeX directory):
         !! default location: /usr/local/texlive/2024
         !! is not writable or not allowed, please select a different one!
       TEXMFLOCAL (directory for site-wide local files):
         /usr/local/texlive/texmf-local
       TEXMFSYSVAR (directory for variable and automatically generated data):
         /usr/local/texlive/2024/texmf-var
       TEXMFSYSCONFIG (directory for local config):
         /usr/local/texlive/2024/texmf-config
       TEXMFVAR (personal directory for variable and automatically generated data):
         ~/.texlive2024/texmf-var
       TEXMFCONFIG (personal directory for local config):
         ~/.texlive2024/texmf-config
       TEXMFHOME (directory for user-specific files):
         ~/texmf
    
     <O> options:
       [ ] use letter size instead of A4 by default
       [X] allow execution of restricted list of programs via \write18
       [X] create all format files
       [X] install macro/font doc tree
       [X] install macro/font source tree
       [ ] create symlinks to standard directories
    
     <V> set up for portable installation
    
    Actions:
     <I> start installation to hard disk
     <P> save installation profile to 'texlive.profile' and exit
     <Q> quit
    
  8. set (with D, then 1) the main directory to your installation (it's /home/romano/texlive/2024 for me).
    ===============================================================================
    Directories customization:
    
     <1> TEXDIR:         /home/romano/texlive2024
         main tree:      /home/romano/texlive2024/texmf-dist
    
     <2> TEXMFLOCAL:     /home/romano/texlive2024/texmf-local
     <3> TEXMFSYSVAR:    /home/romano/texlive2024/texmf-var
     <4> TEXMFSYSCONFIG: /home/romano/texlive2024/texmf-config
    
     <5> TEXMFVAR:       ~/.texlive2024/texmf-var
     <6> TEXMFCONFIG:    ~/.texlive2024/texmf-config
     <7> TEXMFHOME:      ~/texmf
    
     Note: ~ will expand to $HOME (or to %USERPROFILE% on Windows)
    
    Actions:
     <R> return to main menu
     <Q> quit
    
    Enter command: 
    
  9. return to the main menu
  10. important set up for a portable installation with V
  11. Change the other parameters you want (see here for full instructions). Note that by default, your user TEXMF directory will be ~/texmf, so it will be shared among all your TeXLive versions --- be careful.
  12. Now with I you start the installation. Be patient. At the end, your TeXLive is installed.
  13. Next year, you can install the new version along the old one. So now you have a set of different TeXLive installations. Remember that you can't upgrade the installation --- every year you need to install the new release, and the old one is frozen.

Now the rest of the task is to have a mechanism to switch installations. The minimum thing is very easy: add the binary directory of the portable installation in front of your $PATH variable; this is $HOME/texlive2024/bin/x86_64-linux in my installation. The binary will know how to find the correspondig files, so it will use the right installation packages and code.

My solution below also set up other variables to make standard tools to point to the right directories (like man for example, and add $HOME/texmf/doc to the texdoc path), and, crucially, it removes the old TeXLive path if it was there, so that you can switch back and forth thriugh different years...

  1. write somewhere (for example, in your ~/bin) this script and call it texlive-on:

    # activates the named texlive directory and adds the local texmf tree
    #
    function remove_texlive_frompath {
        # see https://stackoverflow.com/questions/1854152/convert-spaces-to-tabs-in-regex
        # https://www.perlmonks.org/?node_id=1112691
        echo "$1" | perl -pe '1 while s+[/:][^:]*?texlive.*?:+:+' | perl -pe 's +^:/+/+'
        # modified again 26/08/2023 form s+[/:][^:]*?texlive.*?:++ which
        # was joining two paths if the texlive was *not* the first one
        # sure there is a better way...
        # modified 30/03/2023 from s+:/[^:]*?texlive.*?:+:+' which was
        # missing the directory if it was at the start of the path.
    }
    function select_texlive {
            TEXDIR=$(realpath $1)
            if [ ! -r "$TEXDIR/texmf.cnf" ]; then
                     echo "$TEXDIR is not a TeXLive portable root!"  1>&2
            else
                    platform=$($TEXDIR/install-tl --print-arch)
                    export PATH=$TEXDIR/bin/$platform:$(remove_texlive_frompath $PATH)
                    export MANPATH=$TEXDIR/texmf-dist/doc/man:$(remove_texlive_frompath $MANPATH)
                    export INFOPATH=$TEXDIR/texmf-dist/doc/info:$(remove_texlive_frompath $INFOPATH
                    unset TEXDOCS
                    export TEXDOCS=$($TEXDIR/bin/$platform/kpsewhich -var-value TEXDOCS | sed 's%,/home/romano/texmf%%' | sed 's%{}%{}/home/romano/texmf,%')
            fi
    }
    

    what this script does is to create a function for your shell (should work in bash and zsh) that switches a set of relevant shell variables to the new path; the only important one is really to add the new /home/romano/texlive2024/bin/x86_64-linux (may vary for your installation) to the front of the PATH environment variable.

  2. now in your shell you can do select_texlive /home/romano/texlive2024 and you are set: try pdflatex -v and see the result.

  3. This script is not able to go back to the standard installed version. Once you activate in your shell the new portable TeXLive, you need to use the full path (e.g. /usr/bin/pdflatex) to access the distribution one.

  4. I normally want the latest installation to be the default in my desktop environment. So I add to my ~/.profile file (normally the desktop login manager uses bash, not your shell) the following stanza:

    if [ -r $HOME/lib/dotfiles/texlive-on ]; then
            source  $HOME/lib/dotfiles/texlive-on
            select_texlive $HOME/texlive2024 # &> /dev/null
    fi
    

    and at the next login, the new portable installation will be the default one.

  5. Notice that other users on the system will not be able to use this installation, because they lack writing rights on some directory. If you need other users to access it, do not perform a portable installation.

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