最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

debian - TeXLive inside docker not running - Stack Overflow

programmeradmin0浏览0评论

I wanted to put texlive 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 to pull (the official TeXLive docker is working fine), but I need a custom TeXLive. For example, in the following configuration, I did not install the font package, and I need to use tlmgr to install the font additionally. 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 package.

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=

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'

and texlive.profile:

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

So, how do you write a Dockerfile for TeXLive that can use fonts?

I wanted to put texlive 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 to pull (the official TeXLive docker is working fine), but I need a custom TeXLive. For example, in the following configuration, I did not install the font package, and I need to use tlmgr to install the font additionally. 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 package.

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'

and texlive.profile:

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

So, how do you write a Dockerfile for TeXLive that can use fonts?

Share Improve this question edited 2 days ago Aaron Chan asked 2 days ago Aaron ChanAaron Chan 12 bronze badges New contributor Aaron Chan is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
Add a comment  | 

1 Answer 1

Reset to default 0

I used this one

    FROM registry.gitlab.com/islandoftex/images/texlive:base

# whether to install documentation and/or source files
# this has to be yes or no
ARG DOCFILES=no
ARG SRCFILES=no
ARG SCHEME=full

# the mirror from which we will download TeX Live
ARG TLMIRRORURL

# whether to create font and ConTeXt caches
ARG GENERATE_CACHES=yes

# Make sure apt-get never asks a question (https://manpages.debian.org/testing/debconf-doc/debconf.7.fr.html#noninteractive)
ENV DEBIAN_FRONTEND=noninteractive

WORKDIR /tmp

# download and install equivs file for dummy package
RUN curl https://tug.org/texlive/files/debian-equivs-2022-ex.txt --output texlive-local && \
  sed -i "s/2022/9999/" texlive-local && \
  # freeglut3 does not ship with debian testing, so we remove it because there
  # is no GUI need in the container anyway (see #28)
  sed -i "/Depends: freeglut3/d" texlive-local && \
  apt-get update && \
  # Mark all texlive packages as installed. This enables installing
  # latex-related packges in child images.
  # Inspired by https://tex.stackexchange.com/a/95373/9075.
  apt-get install -qy --no-install-recommends equivs \
  # at this point also install gpg and gpg-agent to allow tlmgr's
  # key subcommand to work correctly (see #21)
  gpg gpg-agent \
  # we install using rsync so we need to have it installed
  rsync \
  # 2024-11-05 debian:testing-slim does not offer libcurl, needed by asy (#48)
  libcurl4t64 && \
  # we need to change into tl-equis to get it working
  equivs-build texlive-local && \
  dpkg -i texlive-local_9999.99999999-1_all.deb && \
  apt-get install -qyf --no-install-recommends && \
  # reverse the cd command from above and cleanup
  rm -rf ./*texlive* && \
  # save some space
  apt-get remove -y --purge equivs && \
  apt-get autoremove -qy --purge && \
  rm -rf /var/lib/apt/lists/* && \
  apt-get clean && \
  rm -rf /var/cache/apt/

RUN echo "Fetching installation from mirror $TLMIRRORURL" && \
  rsync -a --stats "$TLMIRRORURL" texlive && \
  cd texlive && \
  # create installation profile for full scheme installation with
  # the selected options
  echo "Building with documentation: $DOCFILES" && \
  echo "Building with sources: $SRCFILES" && \
  echo "Building with scheme: $SCHEME" && \
  # choose complete installation
  echo "selected_scheme scheme-$SCHEME" > install.profile && \
  # … but disable documentation and source files when asked to stay slim
  if [ "$DOCFILES" = "no" ]; then echo "tlpdbopt_install_docfiles 0" >> install.profile && \
    echo "BUILD: Disabling documentation files"; fi && \
  if [ "$SRCFILES" = "no" ]; then echo "tlpdbopt_install_srcfiles 0" >> install.profile && \
    echo "BUILD: Disabling source files"; fi && \
  echo "tlpdbopt_autobackup 0" >> install.profile && \
  # furthermore we want our symlinks in the system binary folder to avoid
  # fiddling around with the PATH
  echo "tlpdbopt_sys_bin /usr/bin" >> install.profile && \
  # actually install TeX Live
  ./install-tl -profile install.profile && \
  cd .. && \
  rm -rf texlive

WORKDIR /workdir
RUN echo "Set PATH to $PATH" && \
  $(find /usr/local/texlive -name tlmgr) path add && \
  # Temporary fix for ConTeXt (#30)
  (sed -i '/package.loaded\["data-ini"\]/a if os.selfpath then environment.ownbin=lfs.symlinktarget(os.selfpath..io.fileseparator..os.selfname);environment.ownpath=environment.ownbin:match("^.*"..io.fileseparator) else environment.ownpath=kpse.new("luatex"):var_value("SELFAUTOLOC");environment.ownbin=environment.ownpath..io.fileseparator..(arg[-2] or arg[-1] or arg[0] or "luatex"):match("[^"..io.fileseparator.."]*$") end' /usr/bin/mtxrun.lua || true) && \
  # pregenerate caches as per #3; overhead is < 5 MB which does not really
  # matter for images in the sizes of GBs; some TL schemes might not have
  # all the tools, therefore failure is allowed
  if [ "$GENERATE_CACHES" = "yes" ]; then \
    echo "Generating caches and ConTeXt files" && \
    (luaotfload-tool -u || true) && \
    # also generate fontconfig cache as per #18 which is approx. 20 MB but
    # benefits XeLaTeX user to load fonts from the TL tree by font name
    (cp "$(find /usr/local/texlive -name texlive-fontconfig.conf)" /etc/fonts/conf.d/09-texlive-fonts.conf || true) && \
    fc-cache -fsv && \
    if [ -f "/usr/bin/context" ]; then \
      mtxrun --generate && \
      texlua /usr/bin/mtxrun.lua --luatex --generate && \
      context --make && \
      context --luatex --make; \
    fi \
  else \
    echo "Not generating caches or ConTeXt files"; \
  fi

RUN \
  # test the installation; we only test the full installation because
  # in that, all tools are present and have to work
  if [ "$SCHEME" = "full" ]; then \
    latex --version && printf '\n' && \
    biber --version && printf '\n' && \
    xindy --version && printf '\n' && \
    arara --version && printf '\n' && \
    context --version && printf '\n' && \
    context --luatex --version && printf '\n' && \
    asy --version && printf '\n' && \
    if [ "$DOCFILES" = "yes" ]; then texdoc -l geometry; fi && \
    if [ "$SRCFILES" = "yes" ]; then kpsewhich amsmath.dtx; fi; \
  fi && \
  python --version && printf '\n' && \
  pygmentize -V && printf '\n'

Works on Ubuntu 24.04.

发布评论

评论列表(0)

  1. 暂无评论