4

I try to make an embedded version of TeX Live. My goal is to be able to use it to compile TeX documents in a web application. I can't use system LaTeX distribution due to too old packages.

To achieve this I wrote a bash script:

#!/bin/bash
set -x
#set proxy if needed
arch=x86_64-linux
tlmgr=./texlive/bin/$arch/tlmgr
fmtutils=./texlive/bin/$arch/fmtutil
webc2=./texlive/texmf-dist/web2c/
#export http_proxy

if [ -d build ]
then
   rm -rf build
fi
mkdir build

echo prepare build tree
cp texlive.profile build
pushd build
sed -i "s|%BASEDIR%|$PWD|" texlive.profile

echo download installer
wget http://mirror.ctan.org/systems/texlive/tlnet/install-tl-unx.tar.gz

echo extract installer
tar -xzf install-tl-unx.tar.gz
pushd install-tl-*

echo basic instalation of texlive
./install-tl  -profile ../texlive.profile
popd

echo custom installation
$tlmgr list --only-installed | sed -r "s/i ([a-zA-Z0-9_\.-]+):.*/\1/" > installedPkg
cp ../pkglist pkglist

for i in $(cat pkglist)
do
   if ! grep "^$i$" installedPkg
   then
       echo $i >> needInstall
   fi
done

for i in $(cat installedPkg)
do
   if ! grep "^$i$" pkglist
   then
       echo $i >> needRemove
   fi
done

$tlmgr install $(cat needInstall)
$tlmgr remove $(cat needRemove) --force

echo regenerate format
for i in mptopdf dvilualatex luatex lualatex dviluatex etex pdfetex xetex xelatex
do
    $fmtutils --disablefmt=$i --fmtdir=$webc2
done

$fmtutils --all --fmtdir=$webc2

pushd texlive/bin/*
rm pdflatex
ln -s ./pdftex pdflatex
popd
cp -R texlive ..

Actual behaviour

When I set the texlive/bin/x86_64-linux in the path, everything works fine. If I however call the texlive/bin/x86_64-linux/pdflatex executable explicitly, system library are used (and fail).

Needed behaviour

I would like to be able to run pdfLaTeX like this:

texlive/bin/x86_64-linux/pdflatex foo.tex

Moreover, I would like this way of calling pdfLaTeX to be able to search the library in the correct path without set environment variables by hand (wrapper script can be usable).

  • If you only use the binary programs then it should be fine after you have properly set up the whole system including format dumps etc. The problem is when some scripts are run, and it is not clear which tree is searched. Imagine a script using kpsewhich language.dat to search for the babel config file. Now the wrong kpsewhich might be used, and as consequence the wrong files. Easy solution is to use a wrapper that temporarily sets the PATH to include the <ARCH> dir, that is all that is needed. – norbert Apr 4 '14 at 5:47
2

After some search (and irc releated help) I have found a solution.

the fmtutils command create .fmt file for each tex releated compiler. This utility load a file that contain command needed to build properly .fmt file.

Theses commands call explicitely pdftex,xetex,luatex,...

When specifing the correct path for fmtutils, the embeded version of fmtutils is correctly call, but subprocess call the system related version of theses.

With this hint, I have edit my script to follow this way. after that, I can call properly the pdflatex compiler explicitly without conflict with system tex infrastructure

#!/bin/bash
set -x
#http_prox=
arch=x86_64-linux
tlmgr=./texlive/bin/$arch/tlmgr
fmtutils=./texlive/bin/$arch/fmtutil
texhash=./texlive/bin/$arch/texhash
webc2=./texlive/texmf-dist/web2c/
#export http_proxy

if [ -d build ]
then
   rm -rf build
fi
mkdir build

echo prepare build tree
cp texlive.profile build
pushd build
sed -i "s|%BASEDIR%|$PWD|" texlive.profile

echo download installer
wget http://mirror.ctan.org/systems/texlive/tlnet/install-tl-unx.tar.gz

echo extract installer
tar -xzf install-tl-unx.tar.gz
pushd install-tl-*

echo basic instalation of texlive
./install-tl  -profile ../texlive.profile
popd

echo custom installation
$tlmgr list --only-installed | sed -r "s/i ([a-zA-Z0-9_\.-]+):.*/\1/" > installedPkg
cp ../pkglist pkglist

for i in $(cat pkglist)
do
   if ! grep "^$i$" installedPkg
   then
       echo $i >> needInstall
   fi
done

for i in $(cat installedPkg)
do
   if ! grep "^$i$" pkglist
   then
       echo $i >> needRemove
   fi
done

$tlmgr install $(cat needInstall)
$tlmgr remove $(cat needRemove) --force

OLD_PATH=$PATH
PATH=$PWD/texlive/bin/$arch:$PATH
echo regenerate format
for i in mptopdf dvilualatex luatex lualatex dviluatex etex pdfetex xetex xelatex tex
do
    fmtutil-sys --disablefmt=$i --fmtdir=$webc2
done

fmtutil-sys --all
texhash
PATH=$OLD_PATH

pushd texlive/bin/*
rm pdflatex
ln -s ./pdftex pdflatex
chmod ax pdflatex
popd
cp -R texlive ..

this script need two additional file on the same dir :

  • pkglist : list of needed package on the minimal installation : final installation of texlive only contain this list of package
  • texlive.profile : profile for automatic installation of texlive with minimal set of package. Some vars are replaced by regexp

    # texlive.profile written on Tue Mar 18 09:05:20 2014 UTC
    # It will NOT be updated and reflects only the
    # installation profile at installation time.
    selected_scheme scheme-custom
    TEXDIR %BASEDIR%/texlive
    TEXMFCONFIG $TEXMFSYSCONFIG
    TEXMFHOME $TEXMFLOCAL
    TEXMFLOCAL %BASEDIR%/texlive/texmf-local
    TEXMFSYSCONFIG %BASEDIR%/texlive/texmf-config
    TEXMFSYSVAR %BASEDIR%/texlive/texmf-var
    TEXMFVAR $TEXMFSYSVAR
    binary_x86_64-linux 1
    collection-basic 1
    collection-langfrench 1
    in_place 0
    option_adjustrepo 1
    option_autobackup 1
    option_backupdir tlpkg/backups
    option_desktop_integration
    option_doc 0
    option_file_assocs
    option_fmt 1
    option_letter 0
    option_menu_integration
    option_path
    option_post_code 1
    option_src 0
    option_sys_bin /usr/local/bin
    option_sys_info /usr/local/share/info
    option_sys_man /usr/local/share/man
    option_w32_multi_user 1
    option_write18_restricted 1
    portable 1
    

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.