解决方案

解决方案

对于我正在构建的公司模板,我需要提供商业字体,这是我们的公司设计指南所规定的。

这些字体以 TrueType 字体文件的形式提供给我,它们是HelveticaNeueLTCom-Bd.ttfHelveticaNeueLTCom-BdCn.ttfHelveticaNeueLTCom-BdEx.ttfHelveticaNeueLTCom-Lt.ttfHelveticaNeueLTCom-LtCn.ttfHelveticaNeueLTCom-LtEx.ttfHelveticaNeueLTCom-Th.ttfHelveticaNeueLTCom-ThEx.ttf

我正在创建的软件包将提供给我们的员工,并且我们公司已经授权在每个工作场所安装该字体,因此合法性在这里不存在问题。

首先,我们的员工可以自由选择使用他们自己选择的 TeX 发行版,有些使用 lualatex,有些使用 pdflatex 或第三方服务进行编译。这意味着,我不能完全(或完全)依赖该fontspec软件包,这将是最简单(且效果良好)的解决方案。由于这些第三方服务-用户,我甚至不能要求他们将我的包放入他们的texmf-local目录中:我们需要能够将包放在我们项目目录的子目录中。

我目前有一个解决方案,放入时有效texmf-local。相关的文件树如下所示:

  texmf
    |- fonts
    |   |- map
    |   |   |- dvips
    |   |       |- helveticaneue
    |   |           |- helveticaneue.map
    |   |- tfm
    |   |   |- unknown
    |   |       |- helveticaneue
    |   |           |- hnltb8t.tfm
    |   |           |- hnltbo8t.tfm
    |   |           |- hnltr8t.tfm
    |   |           |- hnltro8t.tfm
    |   |- truetype
    |       |- unknown
    |           |- helveticaneue
    |               |- hnltb.ttf
    |               |- hnltbo.ttf
    |               |- hnltr.ttf
    |               |- hnltro.ttf
    |- tex
        |- latex
            |- unknown
                |- helveticaneue
                    |- t1hnlt.fd

这是使用以下脚本生成的这篇博文

    TEXMF="/mnt/d/desktop/fontgeneration-test/texmf"
    FONTFOUNDRY="unknown"
    FONTNAME="helveticaneue"
    FONTFAMILY="hnlt"
    FONTENC="8t"
    FONTDEFENC="t1"
    FONTENCFILE="T1-WGL4.enc"

现在,我想让项目 texmf 目录可用于示例文件:

    % file: /mnt/d/desktop/fontgeneration-test/example.tex
    % allow import of packages from subdirectories
    % this is needed to keep dependencies separated from actual code
    % https://stackoverflow.com/a/61421280/2149498
    % obviously, this needs to go in front of \documentclass as well
    \makeatletter
    \def\input@path{texmf//}
    \makeatother


    % use before running:
    % https://tex.stackexchange.com/a/31950/53868
    % export TEXINPUTS=./texmf//:${TEXINPUTS}


    \documentclass[]{article}


    %  the following lines has TeX look for T1 encoded fonts (instead of the default OT1 encoding)
    \usepackage[T1]{fontenc}


    %  where does LaTeX look for this map file?
    \pdfmapfile{+./texmf/fonts/map/dvips/helveticaneue/helveticaneue.map}

    \renewcommand{\rmdefault}{hnlt}

    \begin{document}
    Hello nthere. General Kenobi.
    \textbf{Is this too bold?}
    \end{document}

显然,找到了地图文件,但是,我收到以下错误:

    kpathsea: Running mktexmf hnltr8t
    ! I can't find file `hnltr8t'.
    <*> ...=ljfour; mag:=1; nonstopmode; input hnltr8t
                                                    
    Please type another input file name
    ! Emergency stop.
    <*> ...=ljfour; mag:=1; nonstopmode; input hnltr8t
                                                    
    Transcript written on mfput.log.
    grep: hnltr8t.log: No such file or directory
    mktextfm: `mf-nowin -progname=mf \mode:=ljfour; mag:=1; nonstopmode; input hnltr8t' failed to make hnltr8t.tfm.
    kpathsea: Appending font creation commands to missfont.log.

    ! Font T1/hnlt/m/n/10=hnltr8t at 10.0pt not loadable: Metric (TFM) file not fou
    nd.

我花了一整天时间尝试调试这个问题,但没有找到解决办法。我到底做错了什么?

答案1

我终于找到了解决方案。目前,这具体到特科利,但希望其他感兴趣的人可以添加有关 MikTeX 的部分。

解决方案

解决方案在于添加辅助树特科利安装。辅助树添加到搜索路径kpathsea。这个辅助树可以是相对路径,这对于我的目的来说是理想的。

添加辅助树

我将我的辅助树称为,以便与、和texmf-project进行明确区分。在我的组织中,为了存储每个项目的文件,我们将添加使用 的约定。texmf-localtexmf-disttexmftexmf-project

这些措施部分来自https://tex.stackexchange.com/a/524475/53868https://tex.stackexchange.com/a/632156/53868

$ sudo tlmgr conf auxtrees add ./texmf-project

# check that the auxtree path has been added successfully:
# trailing comma (or colon or semicolon) is important here
$ kpsewhich -var-value=TEXMFAUXTREES
./texmf-project,

# place a class file inside ./texmf-project/tex/latex/, e.g. by calling
$ cp $(kpsewhich article.cls) ./texmf-project/tex/latex/article.cls

# confirm the custom article is found (first):
$ kpsewhich article.cls --all
./texmf-project/tex/latex/article.cls
/usr/local/texlive/2022/texmf-dist/tex/latex/base/article.cls
/usr/local/texlive/2022/texmf-dist/tex/latex-dev/base/article.cls

我们看到,kpathsea现在查找./texmf-project目录内的文件。请注意,仍然必须维护 texmf-tree 的正确目录结构,即放置./texmf-project/article.cls不会kpsewhich article.cls返回特定于项目的类文件。

与我现有的文件一起使用

使用问题中的目录结构,我们将顶级目录重命名为texmf-project,这样目录结构现在如下所示:

      texmf-project
        |- fonts
        |   |- map
        |   |   |- dvips
        |   |       |- helveticaneue
        |   |           |- helveticaneue.map
        |   |- tfm
        |   |   |- unknown
        |   |       |- helveticaneue
        |   |           |- hnltb8t.tfm
        |   |           |- hnltbo8t.tfm
        |   |           |- hnltr8t.tfm
        |   |           |- hnltro8t.tfm
        |   |- truetype
        |       |- unknown
        |           |- helveticaneue
        |               |- hnltb.ttf
        |               |- hnltbo.ttf
        |               |- hnltr.ttf
        |               |- hnltro.ttf
        |- tex
            |- latex
                |- unknown
                    |- helveticaneue
                        |- t1hnlt.fd

我的示例如下所示:

% example.tex
\documentclass[]{article}


%  the following lines has TeX look for T1 encoded fonts (instead of the default OT1 encoding)
\usepackage[T1]{fontenc}

% compatibility package for lualatex users to enable pdflatex primitives, e.g. pdfmapfile
\usepackage{luatex85}


%  where does LaTeX look for this map file?
\pdfmapfile{+helveticaneue.map}

\renewcommand{\rmdefault}{hnlt}

\begin{document}
This is text in Helvetica Neue Lt.
\textbf{This is bold.}
\end{document}

最后,正如@UlrikeFischer 指出的那样,您可能不想将此 MWE 与 lualatex 一起使用。相反,我选择在\fontspec和我的自定义字体之间切换\fontenc通过创建自定义包


\RequirePackage{ifxetex,ifluatex,xkeyval,textcomp}
\ifxetex
    % I do not use xetex, so I don't care right now.
\else\ifluatex
    \RequirePackage{fontspec}

    \newfontfamily{\HelveticaNeueLTComLt}[
    UprightFont = hnltl.ttf,
    ] {HelveticaNeueLTComLt}

    % load additional Helvetica fonts for headers
    \newfontfamily{\HelveticaNeueLTComThEx} [
      UprightFont = hnltulx.ttf,
    ] {HelveticaNeueLTComThEx}
\else  % [pdf]LaTeX
    %  the following lines has TeX look for T1 encoded fonts (instead of the default OT1 encoding)
    \usepackage[T1]{fontenc}

    % compatibility package for lualatex users to enable pdflatex primitives, e.g. pdfmapfile
    \usepackage{luatex85}


    %  where does LaTeX look for this map file?
    \pdfmapfile{+helveticaneue.map}

    \providecommand{\HelveticaNeueLTComLt}{\usefont{T1}{hnlt}{l}{n}}
    \providecommand{\HelveticaNeueLTComThEx}{\usefont{T1}{hnlt}{ulx}{n}}
\fi\fi % endif [pdfLaTeX]

定义我需要的命令。

这里有三个变化:

  1. luatex85已经加载,以使命令\pdfmapfile在使用 进行编译时可用lualatex example
  2. 漫长的道路\pdfmapfile消失。kpathsea现在知道如何搜索文件。
  3. 在里面helveticaneue.map,我必须更改路径。他们现在只需要文件名,因为kpathsea现在能够正确搜索它们:
    % helveticalene.map
    hnltbo8t HelveticaNeueLTCom-Bd <hnltbo.ttf <T1-WGL4.enc
    hnltb8t HelveticaNeueLTCom-Bd <hnltb.ttf <T1-WGL4.enc
    hnltro8t HelveticaNeueLTCom-Th <hnltro.ttf <T1-WGL4.enc
    hnltr8t HelveticaNeueLTCom-Th <hnltr.ttf <T1-WGL4.enc
    

概括

根据所述更改,命令

$ pdflatex example

lualatex example

产生所需的输出,如下所示: 在此处输入图片描述

相关内容