ProdriveTechnologies / bazel-latex

Bazel build system rules for LaTeX
Apache License 2.0
75 stars 37 forks source link

Support for TrueType fonts? #9

Closed EvyBongers closed 5 years ago

EvyBongers commented 5 years ago

Not quite sure if this is the right place to ask.

I'm currently trying to build a document in which I use Carlito as main font.

\usepackage{fontspec}

\setmainfont{Carlito}

I used to build this document with lualatex installed on my local system and recently switched to using bazel-latex. The switch went perfectly fine.

Today I attempted to build the same repository (updated to add bazel-toolchains) with bazel-buildbarn. When doing this, the build exists with an error.

ERROR: /network/nas/documents/work/cv/BUILD.bazel:3:1: LuaLatex curriculum_vitae.pdf failed (Exit 1)
cv.tex:9: error: [fontspec] "font-not-found"
      at \setmainfont{Carlito}
cv.tex:9: error: [fontspec] "font-not-found"
      at \setmainfont{Carlito}
cv.tex:9: error: [fontspec] "font-not-found"
      at \setmainfont{Carlito}
cv.tex:9: error: Font \TU/Carlito(0)/m/n/10=Carlito:mode=node;+tlig; at 10pt not loadable: metric data not found or bad
      at <to be read again>
    from \setmainfont{Carlito}

I attempted to solve the problem by adding the relevant *.ttf files to srcs, but this doesn't make a difference.

Is the use of custom fonts currently supported by bazel-latex?

mickael-carl commented 5 years ago

You will likely need to specify the full path to the font, e.g.:

\setmainfont[
    Path = ./,
    Extension = .ttf,
    Ligatures = TeX,
    BoldFont = Carlito-Bold,
    ItalicFont = Carlito-Italic,
]{Carlito-Regular}

and in your BUILD.bazel file:

latex_document(
    name = "foo",
    main = "main.tex",
    srcs = "glob(["*.ttf"]) + [
        ... other dependencies go here ....
    ],
)

Provided you copied the TTFs in your project. Can you give this a try? I just gave it a shot and it seemed to have worked for me.

EvyBongers commented 5 years ago

It works, thanks! Provided, I set path like Path = fonts/, since I keep the fonts in a subdirectory.

EdSchouten commented 5 years ago

Hmmm... Interesting. I can get the following document to build out of the box, only depending on //packages:fontspec:

\documentclass{report}
\usepackage{fontspec}
\setmainfont{Carlito}
\begin{document}
\chapter{This is a chapter}
\section{This is a section}
\textbf{This} \textit{document} uses Carlito!
\end{document}
mickael-carl commented 5 years ago

Same for me now with the font globally installed. Though I do wonder if relying on system font is a good idea.

EvyBongers commented 5 years ago

Does that example work when building against buildbarn-docker? I have the font globally installed, but the build failed as soon as I attempt to build it against the cluster. I'm assuming that this is because the font isn't installed on the build images.

Then again, even when building locally, I'd say that bazel-latex shouldn't rely on system-installed fonts. This kills reproducability.

EdSchouten commented 5 years ago

Oh, wait. I didn't test this against Buildbarn; just a direct build. Will try to figure out why this breaks.