Search code examples
dockerdebianarchlinuxtex-live

How TeXLive use font packages in Docker


I wanted to put TeXlLive in docker and then after I installed it I found that there was an error with the fonts of xelatex and lualatex, the fonts could not be found. I know that TeXLive has an official docker image to pull and this image is working fine, but I need a custom TeXLive docker image.

For example, in the following profile file, I did not install all font packages in texlive.profile, and I need to use tlmgr to install these additionally.

This is my texlive.profile file:

selected_scheme scheme-custom
TEXDIR /usr/local/texlive/2024
TEXMFCONFIG ~/.texlive2024/texmf-config
TEXMFHOME ~/texmf
TEXMFLOCAL /usr/local/texlive/texmf-local
TEXMFSYSCONFIG /usr/local/texlive/2024/texmf-config
TEXMFSYSVAR /usr/local/texlive/2024/texmf-var
TEXMFVAR ~/.texlive2024/texmf-var
binary_x86_64-linux 1
collection-basic 1
collection-bibtexextra 1
collection-binextra 1
collection-fontutils 1
collection-formatsextra 1
collection-langchinese 1
collection-langcjk 1
collection-langenglish 1
collection-latex 1
collection-latexextra 1
collection-latexrecommended 1
collection-luatex 1
collection-mathscience 1
collection-metapost 1
collection-pictures 1
collection-plaingeneric 1
collection-pstricks 1
collection-xetex 1
instopt_adjustpath 0
instopt_adjustrepo 1
instopt_letter 0
instopt_portable 0
instopt_write18_restricted 1
tlpdbopt_autobackup 1
tlpdbopt_backupdir tlpkg/backups
tlpdbopt_create_formats 1
tlpdbopt_desktop_integration 1
tlpdbopt_file_assocs 1
tlpdbopt_generate_updmap 0
tlpdbopt_install_docfiles 0
tlpdbopt_install_srcfiles 0
tlpdbopt_post_code 1
tlpdbopt_sys_bin /usr/local/bin
tlpdbopt_sys_info /usr/local/share/info
tlpdbopt_sys_man /usr/local/share/man
tlpdbopt_w32_multi_user 1

However, these Shell commands are no problem to execute in Arch Linux, and I don't know why the docker image generated in the Dockerfile cannot use fonts. I also tried to install TeXLive as portable, but TeXLive in docker still can't find the font packages.

Here are some Shell command to install TeXLive in Arch Linux (or Debian):

perl install-tl --profile=texlive.profile
# After the TeXLive installer has finished
mkdir -p ~/.fonts.conf.d
sudo cp ~/texlive/2024/texmf-var/fonts/conf/texlive-fontconfig.conf ~/.fonts.conf.d/09-texlive.conf

# Arch Linux
yes | sudo pacman -S fontconfig
# Debian
sudo apt-get install -y fontconfig

fc-cache -fv
tex -v && latex -v && bibtex -v && xetex -v && pdftex -v && luatex -v

# Use tlmgr to update
tlmgr update --self --all
# Use tlmgr to install font package
tlmgr install tex-gyre droid cm-unicode roboto junicode lm qualitype arphic-ttf fandol
# The font cache needs to be refreshed again
fc-cache -fv

Here's the Dockerfile I wrote:

FROM debian:latest

ENV LANG=C.UTF-8 \
  LC_ALL=C.UTF-8 \
  DEBIAN_FRONTEND=noninteractive

RUN apt-get update \
  && apt-get install -y \
    wget perl fontconfig make xz-utils bzip2 ca-certificates curl \
  && apt-get clean \
  && rm -rf /var/lib/apt/lists/*

COPY texlive.profile .

ARG TL_VERSION=2024 ARCH=x86_64-linux TL_URL=http://mirror.ctan.org

RUN wget -q ${TL_URL}/systems/texlive/tlnet/install-tl-unx.tar.gz \
  && tar -xzf install-tl-unx.tar.gz \
  && rm install-tl-unx.tar.gz \
  && ./install-tl-*/install-tl --profile=texlive.profile --repository=${TL_URL}/systems/texlive/tlnet --no-verify-downloads \
  && rm -rf install-tl-*

ENV PATH="/usr/local/texlive/${TL_VERSION}/bin/${ARCH}:$PATH"

RUN tlmgr update --self --all \
  && tlmgr install tex-gyre droid cm-unicode roboto junicode lm qualitype arphic-ttf fandol \
  && fc-cache -fv

RUN \
  tex -v && printf '\n' && \
  latex -v && printf '\n' && \
  bibtex -v && printf '\n' && \
  xetex -v && printf '\n' && \
  pdftex -v && printf '\n' && \
  luatex -v printf '\n'

So, how do I write a Dockerfile for TeXLive that can use font packages?


Solution

  • I referred to the official dockerfile build and successfully found a way to go. It can also be regarded as providing a working TeXLive Dockerfile for those users who want to configure the file according to texlive.profile.

    The corrected dockerfile is as follows:

    FROM debian:latest
    
    ENV LANG=C.UTF-8 \
      LC_ALL=C.UTF-8 \
      DEBIAN_FRONTEND=noninteractive
    
    RUN apt-get update \
      && apt-get install -y \
        wget perl fontconfig make xz-utils bzip2 ca-certificates curl python3 \
      && apt-get clean \
      && rm -rf /var/lib/apt/lists/*
    
    COPY texlive.profile .
    
    ARG TL_VERSION=2024 ARCH=x86_64-linux TL_URL=http://mirror.ctan.org
    
    RUN wget -q ${TL_URL}/systems/texlive/tlnet/install-tl-unx.tar.gz \
      && tar -xzf install-tl-unx.tar.gz && rm install-tl-unx.tar.gz \
      && ./install-tl-*/install-tl --profile=texlive.profile --repository=${TL_URL}/systems/texlive/tlnet \
      && rm -rf install-tl-*
    
    ENV PATH="/usr/local/texlive/${TL_VERSION}/bin/${ARCH}:$PATH"
    
    RUN tlmgr update --self --all \
      && tlmgr install tex-gyre droid cm-unicode roboto junicode lm qualitype arphic-ttf fandol \
      && (luaotfload-tool -u || true) \
      && (cp "$(find /usr/local/texlive -name texlive-fontconfig.conf)" /etc/fonts/conf.d/09-texlive-fonts.conf || true) \
      && fc-cache -fsv \
      && tex -v && latex -v && bibtex -v && xetex -v && pdftex -v && luatex -v
    

    Tip: If you don't have an additional font file installed using tlmgr like I did, you'll need to add the font option to texlive.profile.