1

For a corporate template I am building, I need to make the commercial fonts available, which our corporate design guide dictates.

These fonts are availabe to me as truetype font files, which are HelveticaNeueLTCom-Bd.ttf, HelveticaNeueLTCom-BdCn.ttf, HelveticaNeueLTCom-BdEx.ttf, HelveticaNeueLTCom-Lt.ttf, HelveticaNeueLTCom-LtCn.ttf, HelveticaNeueLTCom-LtEx.ttf, HelveticaNeueLTCom-Th.ttf and HelveticaNeueLTCom-ThEx.ttf.

The package I am creating will be available to our employees, and our corporation has licensed the font to be installed on every workplace, so legality is not in question here.

Firstly, our employees are free to use their own TeX distribution of choice, and some work with lualatex, some compile with pdflatex or a third-party service. This means, I can not rely solely (or at all) on the fontspec package, which would be the easiest (and well working) solution. Because of those third-party service-users, I can not even ask them to put my package into their texmf-local directories: We need to be able to have the packages right inside a subdirectory of our project directories.

I currently have a solution, which works when put into texmf-local. The relevant filetree looks like this:

  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

This has been generated using the script from this blog post

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

Now, I want to make the project texmf directory available to an example file:

    % 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}

Apparently, the map file is found, however, I get the following error:

    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.

I have spent all day trying to debug this, and didn't come up with a solution. What am I doing wrong here?

2
  • Not sure if there's any easier solution, but in case TeX hardcode to run that specific command then I can't see any way to modify the kpse database. One option is to execute commands to copy files to local texmf (you should have the permission. Requires write18 or lualatex)
    – user202729
    May 7, 2022 at 1:35
  • I don't like tex copying my files around, and I doubt my users will like this, either. I am now sure, that there is an easier solution, so just look at my own answer.
    – marc
    May 9, 2022 at 9:31

1 Answer 1

0

I finally found a solution. Right now, this is specific to texlive, but hopefully someone else interested will add a part about MikTeX.

Solution

The solution relies on adding a auxtree to the texlive installation. An auxtree adds to the paths kpathsea searches in. This auxtree can be a relative path, which is ideal for my purpose.

Adding the auxtree

I am calling my auxtree texmf-project, to make a clear distinction from texmf-local, texmf-dist and texmf. In my organization, for storing per-project-files, we will add the convetion of using texmf-project.

The steps are taken in part from https://tex.stackexchange.com/a/524475/53868 and https://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

We see, that kpathsea now looks for files inside the ./texmf-project directory. Note, that the correct directory structure for a texmf-tree still has to be maintained, i.e. placing ./texmf-project/article.cls, kpsewhich article.cls will not return the project-specific class file.

Using with my existing files

Using the directory structure from the question, we rename the top directory to texmf-project, such that the directory structure now look like this:

      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

My example mwe look then like this:

% 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}

Ultimately, as @UlrikeFischer pointed out, you might not want to use this MWE with lualatex. Instead, I opted for switching between \fontspec and my custom font with \fontenc by creating a custom package, and using


\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]

to define the commands I need.

There have been three changes here:

  1. package luatex85 has been loaded, to make the command \pdfmapfile available when compiling with lualatex example.
  2. the long path from \pdfmapfile is gone. kpathsea now knows how to seach for the file.
  3. Inside helveticaneue.map, I had to change paths. They now only need filenames, as kpathsea now is able to search for them correctly:
    % 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
    

Summary

With the changes described, the commands

$ pdflatex example

and

lualatex example

produce the desired output as shown: enter image description here

6
  • with miktex you can register such an auxtree with initexmf --register-root=path/to/texmf (the auxtrees option was modelled after the miktex option at my request). May 9, 2022 at 9:57
  • You can add a updmap.cfg to such a local tree and add it with initexmf --mkmaps in miktex. In texlive a call to updmap-sys should work too to add the map file. But you shouldn't use T1 fontenc with lualatex, this will give faulty chars and hyphenation. May 9, 2022 at 10:00
  • I think you required that it may be run under third party build system like overleaf? Can you run such commands in overleaf?
    – user202729
    May 9, 2022 at 11:43
  • @UlrikeFischer Regarding font encoding, are you suggesting I implement a TeX engine detection then for lualatex? Regarding the updmap command: Since we are going to use relative locations, it is unclear to me, where the updmap would look for additional font at all.
    – marc
    May 9, 2022 at 12:15
  • @UlrikeFischer Is your comment sufficient, or should I add this to my answer?
    – marc
    May 9, 2022 at 12:21

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .