Skip to content

Commit 965878e

Browse files
committed
Use Fontconfig to avoid the need for a font install
1 parent c22af3f commit 965878e

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
lines changed

.github/workflows/documentation.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ jobs:
2828
runs-on: ubuntu-latest
2929
steps:
3030
- uses: actions/checkout@v5
31-
- run: sudo apt install -y fonts-freefont-ttf
3231
- uses: julia-actions/setup-julia@v2
3332
with:
3433
version: 1

docs/Project.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
[deps]
22
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
33
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
4+
Fontconfig = "186bb1d3-e1f7-5a2c-a377-96d770f13627"
45
InverseFunctions = "3587e190-3f89-42d0-90ee-14403ec27112"
56
LaTeXStrings = "b964fa9f-0449-5b57-a5c2-d3ea65f4040f"
67
Latexify = "23fbe1c1-3f47-55db-b15f-69d7ec21a316"
@@ -16,3 +17,4 @@ Unitful = {path = ".."}
1617
Documenter = "1"
1718
Latexify = "0.16.9"
1819
Plots = "1"
20+
Fontconfig = "0.4"

docs/generate_latex_images.jl

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
using LaTeXStrings, Unitful, Latexify
22
import tectonic_jll # needed for lightweight LaTeX render
3+
using Fontconfig: format, match, Pattern
4+
5+
# Since the docs can get built on different systems, we need to find a locally installed
6+
# monospaced font that has enough Unicode coverage to handle π
7+
monofont = format(match(Pattern(spacing=100, charset="3c0")), "%{family}")
38

49
commands = [
510
:(latexify(612.2u"nm")),
@@ -20,11 +25,16 @@ end
2025
ltab1 = latextabular(tab1, adjustment=:l, transpose=true, latex=false, booktabs=true,
2126
head=["julia", "\\LaTeX", "Result"])
2227
# Setting an explicit white background color results in transparent PDF, so go offwhite.
23-
ltab1 = LaTeXString("\\definecolor{offwhite}{rgb}{0.999,0.999,0.999}\n\\pagecolor{offwhite}\n\\color{black}\n" * ltab1)
28+
ltab1 = LaTeXString("""
29+
\\setmonofont{$monofont}
30+
\\definecolor{offwhite}{rgb}{0.999,0.999,0.999}
31+
\\pagecolor{offwhite}
32+
\\color{black}
33+
""" * ltab1)
2434

2535
render(ltab1, MIME("image/png"); use_tectonic=true,
2636
name=(@__DIR__)*"/src/assets/latex-examples",
27-
packages=["booktabs", "color", "siunitx"],
37+
packages=["booktabs", "color", "siunitx", "fontspec"],
2838
documentclass=("standalone"))
2939

3040
functions = [
@@ -134,8 +144,7 @@ ltab2 = latextabular(tab2, adjustment=:l, transpose=true, latex=false, booktabs=
134144
# Set background to not-quite-white so it doesn't get treated as transparent
135145
ltab2 = LaTeXString(
136146
"""
137-
\\setmainfont{FreeSerif}
138-
\\setmonofont{FreeMono}
147+
\\setmonofont{$monofont}
139148
\\definecolor{offwhite}{rgb}{0.999,0.999,0.999}
140149
\\pagecolor{offwhite}
141150
\\color{black}

0 commit comments

Comments
 (0)