Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass juliamono-path to PDF template #257

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ jobs:
- name: Install Julia dependencies
uses: julia-actions/julia-buildpkg@latest

- name: Install extra dependencies
run: julia --project -e 'using Books; Books.install_dependencies()'
- name: Install JuliaMono
run: julia --project -e 'using Books; Books.install_juliamono()'

- uses: julia-actions/julia-runtest@v1

Expand Down
1 change: 1 addition & 0 deletions defaults/template.tex
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
]

\newfontfamily\JuliaMono{JuliaMono}[
Path = $juliamono-path$,
UprightFont = *-Regular,
BoldFont = *-Bold
]
Expand Down
16 changes: 14 additions & 2 deletions docs/contents/demo.md
Original file line number Diff line number Diff line change
Expand Up @@ -488,8 +488,20 @@ which will show as:

### Fonts

The code blocks default to JuliaMono in html and PDF.
Ligatures from JuliaMono are disabled. For example, none of these symbols are combined into a single glyph.
The code blocks default to JuliaMono in HTML and PDF.
The font automatically works in HTML even when JuliaMono is not globally installed on the system.
The font **should** automatically work in PDF too, but sometimes it doesn't.
If it doesn't work, try to manually install the font files located at `Books.JULIAMONO_PATH`.
On Linux, this can be done via `fontconfig`:

```
julia> using Books

julia> run(`fc-cache --force --verbose $(Books.JULIAMONO_PATH)`)
```

Ligatures from JuliaMono are disabled.
For example, none of these symbols are combined into a single glyph.

```
|> => and <=
Expand Down
8 changes: 8 additions & 0 deletions src/Books.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ const BUILD_DIR = "_build"
const JULIAMONO_VERSION = "0.042"
mkpath(BUILD_DIR)

function juliamono_path()
artifact = Artifacts.artifact"JuliaMono"
dir = joinpath(artifact, "juliamono-$JULIAMONO_VERSION")
# The forward slash is required by LaTeX.
return dir * '/'
end
const JULIAMONO_PATH = juliamono_path()

include("defaults.jl")
include("ci.jl")
include("sitemap.jl")
Expand Down
9 changes: 1 addition & 8 deletions src/build.jl
Original file line number Diff line number Diff line change
Expand Up @@ -297,14 +297,6 @@ function ignore_homepage(project, input_paths)
override ? input_paths : input_paths[2:end]
end

function juliamono_path()
artifact = Artifacts.artifact"JuliaMono"
dir = joinpath(artifact, "juliamono-$JULIAMONO_VERSION")
# The forward slash is required by LaTeX.
dir * '/'
end
const JULIAMONO_PATH = juliamono_path()

function pdf(; project="default")
input_path = write_input_markdown(project; skip_index=true)
copy_extra_directories(project)
Expand Down Expand Up @@ -339,6 +331,7 @@ function pdf(; project="default")
"--variable=listings-unicode-path:$listings_unicode_path";
"--variable=listings-path:$listings_path";
"--variable=build-info:$build_info";
"--variable=juliamono-path:$JULIAMONO_PATH";
extra_args
]
output_tex_filename = joinpath(BUILD_DIR, "$file.tex")
Expand Down
41 changes: 5 additions & 36 deletions src/ci.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,42 +28,6 @@ function nonempty_run(args::Vector)
run(`$args`)
end

"""
install_extra_fonts()

For some reason, this is required since I couldn't get Tectonic to work with `fontconfig` and `Path`.
Installing fonts globally is the most reliable workaround that I can find.
The benefit is that it's easy to verify the installation via `fc-list | grep "Julia"`.
"""
function install_extra_fonts()
name = "juliamono-$JULIAMONO_VERSION"
dir = joinpath(Artifacts.artifact"JuliaMono", name)
# See `fc-cache --force --verbose` for folders that `fc-cache` inspects.
# Don't try to pass a dir to `fc-cache`, this is ignored on my pc for some reason.
target_dir = joinpath(homedir(), ".local", "share", "fonts")
mkpath(target_dir)
for file in readdir(dir)
cp(joinpath(dir, file), joinpath(target_dir, file); force=true)
end
return

files = readdir(ttf_dir)
mkpath(fonts_dir)
println("Moving files to $fonts_dir")
for file in files
from = joinpath(ttf_dir, file)
to = joinpath(fonts_dir, file)
mv(from, to; force=true)
end

# Update fontconfig cache; not sure if it is necessary.
run(`fc-cache --force --verbose $fonts_dir`)
end

function install_dependencies()
install_extra_fonts()
end

"""
write_extra_html_files(project)

Expand Down Expand Up @@ -113,3 +77,8 @@ function write_extra_html_files(project)
write(path, robots)
return nothing
end

function install_juliamono()
# This shouldn't be necessary but apparently it is :\.
run(`fc-cache --force --verbose $JULIAMONO_PATH`)
end