是否可以在 docker 中拉取 texlive 映像(例如 https://hub.docker.com/r/texlive/texlive)并从我的计算机上使用它,而不是在我的计算机上安装 texlive?
我喜欢使用容器而不是安装软件的想法。
这应该像这样工作
sudo docker run -i --rm --name latex -v "$PWD":/usr/src/app -w /usr/src/app registry.gitlab.com/islandoftex/images/texlive:latest pdflatex essay.tex
取自https://nico.dorfbrunnen.eu/de/posts/2020/docker-latex/(德语)
检查 docker 镜像的 wiki 页面:https://gitlab.com/islandoftex/images/texlive/-/wikis/home
LaTeX 的完整分布太大。我建议使用 TinyTeX,然后根据需要添加包。这应该有效:
apt-get update
apt-get install perl wget -y
wget -qO- "https://yihui.org/tinytex/install-bin-unix.sh" | sh
export PATH="$PATH:/root/.TinyTeX/bin/x86_64-linux"
从这里开始,在容器中运行 bash,编译 Latex 文件,然后检查缺少哪些包。例如,您可能会收到诸如
! LaTeX Error: File `type1cm.sty' not found.
之类的消息。在这种情况下,从容器内部运行 tlmgr search --global --file "type1cm.sty"
将会输出如下内容:
tlmgr: package repository https://ctan.mirror.garr.it/mirrors/ctan/systems/texlive/tlnet (not verified: gpg unavailable)
type1cm:
texmf-dist/tex/latex/type1cm/type1cm.sty
然后,奔跑
tlmgr install type1cm
重复此过程,直到获得所需的所有包。就我而言,还需要添加 dvipng,这是 Python 的 matplotlib 包所需的:
apt-get install dvipng -y
(出于某种原因,我需要在TinyTeX之后安装它)。
Dockerfile 中的等效内容如下:
RUN apt-get update
RUN apt-get install perl wget -y
# fetch TinyTeX installer and run it
RUN wget -qO- "https://yihui.org/tinytex/install-bin-unix.sh" | sh
# add TinyTeX to PATH variable
ENV PATH="$PATH:/root/.TinyTeX/bin/x86_64-linux"
# add needed packages and dvipng:
RUN tlmgr install type1cm
RUN apt-get install dvipng