如何使 pdflatex 与自定义 TEXMFHOME 和 TEXMFVAR 路径一起工作?

如何使 pdflatex 与自定义 TEXMFHOME 和 TEXMFVAR 路径一起工作?

这是我的代码:

% foo.tex
\documentclass{article}
\usepackage{fontawesome}
\begin{document}
\faAdjust
\end{document}

我已经安装基本文本在 Mac 上,编译上述文档将失败并出现以下预期错误:

$ pdflatex foo.tex
...
! LaTeX Error: File `fontawesome.sty' not found.
...

现在我尝试在任意位置设置我自己的个人用户树并编译此文档。以下是我尝试的方法。

rm -rf texmf texmf-var ~/Library/texlive # Cleanup remnants of previous trials
TEXMFHOME=texmf tlmgr init-usertree
TEXMFHOME=texmf tlmgr --usermode install fontawesome

这将安装fontawesometexmf目录中,但它也会尝试执行,updmap但会失败并出现以下错误:

$ TEXMFHOME=texmf tlmgr --usermode install fontawesome
tlmgr: package repository http://ctan.mirror.ac.za/systems/texlive/tlnet (not verified: gpg unavailable)
[1/1, ??:??/??:??] install: fontawesome [270k]
running mktexlsr ...
done running mktexlsr.
running updmap ...

tlmgr: updmap failed (status 1), output:
updmap [ERROR]: Either -sys or -user mode is required.
updmap [ERROR]: In nearly all cases you should use updmap -sys.
updmap [ERROR]: For special cases see http://tug.org/texlive/scripts-sys-user.html

tlmgr: package log updated: texmf/web2c/tlmgr.log
tlmgr: An error has occurred. See above messages. Exiting.

所以我现在updmap手动运行。

TEXMFVAR=texmf-var updmap-user

这成功生成了目录中的地图文件texmf-var。在此阶段,texmftexmf-var文件夹如下所示:

$ find texmf -type f
texmf/tex/latex/fontawesome/ufontawesomethree.fd
texmf/tex/latex/fontawesome/ufontawesometwo.fd
texmf/tex/latex/fontawesome/ufontawesomeone.fd
texmf/tex/latex/fontawesome/fontawesomesymbols-generic.tex
texmf/tex/latex/fontawesome/fontawesome.sty
texmf/tex/latex/fontawesome/fontawesomesymbols-pdftex.tex
texmf/tex/latex/fontawesome/fontawesomesymbols-xeluatex.tex
texmf/web2c/tlmgr.log
texmf/web2c/updmap.cfg
texmf/fonts/tfm/public/fontawesome/FontAwesome--fontawesomeone.tfm
texmf/fonts/tfm/public/fontawesome/FontAwesome--fontawesomethree.tfm
texmf/fonts/tfm/public/fontawesome/FontAwesome--fontawesometwo.tfm
texmf/fonts/opentype/public/fontawesome/FontAwesome.otf
texmf/fonts/type1/public/fontawesome/FontAwesome.pfb
texmf/fonts/enc/dvips/fontawesome/fontawesomeone.enc
texmf/fonts/enc/dvips/fontawesome/fontawesomethree.enc
texmf/fonts/enc/dvips/fontawesome/fontawesometwo.enc
texmf/fonts/map/dvips/fontawesome/fontawesome.map
texmf/tlpkg/tlpobj/fontawesome.tlpobj
texmf/tlpkg/texlive.tlpdb

$ find texmf-var -type f
texmf-var/web2c/updmap.log
texmf-var/fonts/map/pdftex/updmap/pdftex_dl14.map
texmf-var/fonts/map/pdftex/updmap/pdftex_ndl14.map
texmf-var/fonts/map/dvipdfmx/updmap/kanjix.map
texmf-var/fonts/map/dvips/updmap/ps2pk.map
texmf-var/fonts/map/dvips/updmap/download35.map
texmf-var/fonts/map/dvips/updmap/psfonts_t1.map
texmf-var/fonts/map/dvips/updmap/psfonts_pk.map
texmf-var/fonts/map/dvips/updmap/builtin35.map

现在我尝试再次编译我的 pdflatex 但失败了:

$ TEXMFHOME=texmf TEXMFVAR=texmf-var pdflatex foo.tex
This is pdfTeX, Version 3.14159265-2.6-1.40.19 (TeX Live 2018) (preloaded format=pdflatex)
 restricted \write18 enabled.
entering extended mode
(./foo.tex
LaTeX2e <2018-04-01> patch level 2
Babel <3.18> and hyphenation patterns for 22 language(s) loaded.
(/usr/local/texlive/2018basic/texmf-dist/tex/latex/base/article.cls
Document Class: article 2014/09/29 v1.4h Standard LaTeX document class
(/usr/local/texlive/2018basic/texmf-dist/tex/latex/base/size10.clo))
(texmf/tex/latex/fontawesome/fontawesome.sty
(/usr/local/texlive/2018basic/texmf-dist/tex/generic/ifxetex/ifxetex.sty)
(/usr/local/texlive/2018basic/texmf-dist/tex/generic/oberdiek/ifluatex.sty)
(texmf/tex/latex/fontawesome/fontawesomesymbols-generic.tex)
(texmf/tex/latex/fontawesome/fontawesomesymbols-pdftex.tex)) (./foo.aux)
(texmf/tex/latex/fontawesome/ufontawesomeone.fd) [1{texmf-var/fonts/map/pdftex/u
pdmap/pdftex.map}] (./foo.aux)
kpathsea: Running mktexpk --mfmode / --bdpi 600 --mag 1+0/600 --dpi 600 FontAwesome--fontawesomeone
mktexpk: don't know how to create bitmap font for FontAwesome--fontawesomeone.
mktexpk: perhaps FontAwesome--fontawesomeone is missing from the map file.
kpathsea: Appending font creation commands to missfont.log.
 )
!pdfTeX error: pdflatex (file FontAwesome--fontawesomeone): Font FontAwesome--f
ontawesomeone at 600 not found
 ==> Fatal error occurred, no output PDF file produced!

我如何使用自定义路径编译此TEXMFHOME文件TEXMFVAR

答案1

简短答案

该命令TEXMFVAR=texmf-var updmap-userTEXMFHOME=texmf TEXMFVAR=texmf-var updmap-user改为。TEXMFHOME需要指定路径,以便updmap-user从用户目录读取字体映射配置,在其中找到条目fontawesome,并在路径处生成的映射文件中包含有关它的详细信息TEXMFVAR

有关此内容的更多详细信息,请参阅下面详细答复中的第 5 点。

详细解答

我是为了完整性而写这个详细的答案,以便任何想要设置用户树来安装字体的人都可以一步一步地按照这些说明进行操作。

警告:请注意,我在步骤 2 中递归地强制删除了下面的texmftexmf-var目录,以便我可以启动一个干净的用户环境并清楚地显示安装在用户树目录中的文件。但是,如果您不想丢失现有的用户树目录,您可能需要跳过步骤 2。

  1. 以下是源代码文件:

    % foo.tex
    \documentclass{article}
    \usepackage{fontawesome}
    \begin{document}
    \faAdjust
    \end{document}
    
  2. 从干净的用户环境开始:

    rm -rf texmf texmf-var
    

    警告:阅读此列表上方的注释。

  3. 创建用户树:

    TEXMFHOME=texmf tlmgr init-usertree
    

    此时,用户树如下所示:

    $ tree -F texmf/
    texmf/
    ├── tlpkg/
    │   ├── texlive.tlpdb
    │   └── tlpobj/
    └── web2c/
    
    3 directories, 1 file
    
  4. 安装fontawesome到用户树中:

    TEXMFHOME=texmf tlmgr --usermode install fontawesome
    

    运行该命令时,出现以下错误:

    tlmgr: updmap failed (status 1), output:
    updmap [ERROR]: Either -sys or -user mode is required.
    updmap [ERROR]: In nearly all cases you should use updmap -sys.
    updmap [ERROR]: For special cases see http://tug.org/texlive/scripts-sys-user.html
    

    尽管出现上述错误,但fontawesome仍成功获取。用户树如下所示:

    $ tree -F texmf
    texmf
    ├── fonts/
    │   ├── enc/
    │   │   └── dvips/
    │   │       └── fontawesome/
    │   │           ├── fontawesomeone.enc
    │   │           ├── fontawesomethree.enc
    │   │           └── fontawesometwo.enc
    │   ├── map/
    │   │   └── dvips/
    │   │       └── fontawesome/
    │   │           └── fontawesome.map
    │   ├── opentype/
    │   │   └── public/
    │   │       └── fontawesome/
    │   │           └── FontAwesome.otf
    │   ├── tfm/
    │   │   └── public/
    │   │       └── fontawesome/
    │   │           ├── FontAwesome--fontawesomeone.tfm
    │   │           ├── FontAwesome--fontawesomethree.tfm
    │   │           └── FontAwesome--fontawesometwo.tfm
    │   └── type1/
    │       └── public/
    │           └── fontawesome/
    │               └── FontAwesome.pfb
    ├── tex/
    │   └── latex/
    │       └── fontawesome/
    │           ├── fontawesome.sty
    │           ├── fontawesomesymbols-generic.tex
    │           ├── fontawesomesymbols-pdftex.tex
    │           ├── fontawesomesymbols-xeluatex.tex
    │           ├── ufontawesomeone.fd
    │           ├── ufontawesomethree.fd
    │           └── ufontawesometwo.fd
    ├── tlpkg/
    │   ├── texlive.tlpdb
    │   └── tlpobj/
    │       └── fontawesome.tlpobj
    └── web2c/
        ├── tlmgr.log
        └── updmap.cfg
    
    22 directories, 20 files
    

    包含texmf/web2c/updmap.cfg字体映射配置:

    $ cat texmf/web2c/updmap.cfg
    # Generated by /Library/TeX/texbin/tlmgr on Sun Aug 18 14:21:53 2019
    Map fontawesome.map
    
  5. 跑步updmap-user

    TEXMFHOME=texmf TEXMFVAR=texmf-var updmap-user
    

    请注意,必须TEXMFHOME=texmf在上面的命令中指定,以便updmap-user读取texmf/web2c/updmap.cfg(即用户树中的字体映射配置文件)。如果我们不这样做,则在中生成的映射文件texmf-var将不包含有关的详细信息fontawesome

  6. 最后运行pdflatex生成输出PDF:

    TEXMFHOME=texmf TEXMFVAR=texmf-var pdflatex foo.tex
    

    另外,这也有效:

    TEXMFHOME=texmf:texmf-var pdflatex foo.tex
    

    pdflatex命令需要了解texmf(字体)和texmf-var(字体映射),这就是为什么我们需要在上述命令中指定两个目录。

概括

为了方便起见,这里再次列出所有命令:

TEXMFHOME=texmf tlmgr init-usertree
TEXMFHOME=texmf tlmgr --usermode install fontawesome
TEXMFHOME=texmf TEXMFVAR=texmf-var updmap-user
TEXMFHOME=texmf TEXMFVAR=texmf-var pdflatex foo.tex

相关内容