Skip to content

Commit

Permalink
Fix/supplement (#36)
Browse files Browse the repository at this point in the history
* fix: Chapter supplement for heading references

* fix: Smaller font for credit note

* feat: Oldstyle figures using XCharter

* fix: Remove unused Charis SIL font

* fix: Remove redundant callPackage parameter
  • Loading branch information
otytlandsvik authored Nov 24, 2024
1 parent 9bf926b commit 4897b2f
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 16 deletions.
15 changes: 13 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,24 @@ This template uses a number of different fonts:

- Open Sans (Noto Sans)
- JetBrains Mono (Fira Code)
- Charis SIL (Charter)
- XCharter (Charter)

The above parenthesized fonts are fallback typefaces available by default in [the web app](https://typst.app).
If you'd like to use the main fonts instead, simply upload the `.ttf`s to the web app and it will detect and apply them automatically.
If you'd like to use the main fonts instead, simply upload the `.ttf`s or `.otf`s to the web app and it will detect and apply them automatically.

XCharter is commonly packaged only for LaTeX, however to use it with typst, we need to fetch the archive from [CTAN](https://mirrors.ctan.org/fonts/xcharter.zip).
The required `.otf` font files are in the `opentype` directory of the archive.

If you're running typst locally, install the fonts in a directory of your choosing and specify it with `--font-path`.

> [!IMPORTANT]
> We use XCharter to access additional font features not available in Charter, such as smallcaps and oldstyle figures.
> If you instead use the fallback font Charter to compile your document, be aware that these are unavailable.
### Nix

If you're using the nix package manager, simply run the provided dev shell. It includes all dependencies needed to write and build the document locally, including the main fonts.

## License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
3 changes: 2 additions & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,14 @@
...
}:
let
xcharter = pkgs.callPackage ./xcharter.nix { };
fontPackages = pkgs.symlinkJoin {
name = "typst-fonts";
paths = with pkgs; [
noto-fonts
open-sans
jetbrains-mono
charis-sil
xcharter
];
};
in
Expand Down
29 changes: 19 additions & 10 deletions lib.typ
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@

// Common styles for main matter
#let main-matter(body) = {
set text(features: ("onum",))
set page(numbering: "1",
// Only show numbering in footer when no chapter header is present
footer: context {
Expand Down Expand Up @@ -250,8 +251,8 @@
show footnote.entry: set par(hanging-indent: 1.5em)

// Set the body font.
// Default is Charis SIL at 11pt
set text(font: ("Charis SIL", "Charter"), size: 11pt)
// Default is XCharter at 11pt
set text(font: ("XCharter", "Charter"), size: 11pt)

// Set raw text font.
// Default is JetBrains Mono at 9tp with DejaVu Sans Mono as fallback
Expand Down Expand Up @@ -280,6 +281,15 @@
spacing: 1.35em,
)

// Configure reference supplement for headings
set ref(supplement: it => {
if it.func() == heading {
[Chapter]
} else {
it.supplement
}
})

// Add some vertical spacing for all headings
show heading: it => {
let body = if it.level > 1 {
Expand All @@ -297,13 +307,14 @@
show heading.where(level: 1): it => {
set text(font: ("Open Sans", "Noto Sans"), weight: "bold", size: 24pt)

// FIXME: Has no effect, still shows "Section"
set heading(supplement: [Chapter])

let heading-number = if heading.numbering == none {
[]
} else {
text(counter(heading.where(level: 1)).display(), size: 62pt)
text(
counter(heading.where(level: 1)).display(),
features: ("lnum",),
size: 62pt,
)
}

// Reset figure numbering on every chapter start
Expand Down Expand Up @@ -344,11 +355,11 @@
// Configure heading numbering.
set heading(numbering: "1.1")


// Do not hyphenate headings.
show heading: set text(
font: ("Open Sans", "Noto Sans"),
weight: "bold",
features: ("sc", "si", "scit"),
hyphenate: false,
)

Expand Down Expand Up @@ -433,8 +444,6 @@
font: ("Open Sans", "Noto Sans"),
size: 8pt,
fill: uit-gray-color,
// FIXME: Seems to have no effect
// features: ("sc", "si", "scit"),
fill-line(upper(left-text), upper(right-text)),
)
}
Expand All @@ -446,6 +455,7 @@

// Configure equation numbering.
set math.equation(numbering: n => {
set text(font: ("XCharter", "Charter"))
let h1 = counter(heading).get().first()
numbering("(1.1)", h1, n)
})
Expand Down Expand Up @@ -568,7 +578,6 @@
..outrageous.presets.typst,
font-weight: ("bold", auto),
fill: (none, auto),
font: (("Charis SIL", "Charter"), ("Charis SIL", "Charter")),
vspace: (1.5em, 0.5em),

// Manually add indent and spacing
Expand Down
8 changes: 5 additions & 3 deletions modules/supervisors.typ
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@
footer: [
#align(center)[
#par(spacing: .75em)[
This document was typeset with Typst using the _modern UiT thesis_ template
#text(size: 9pt)[
This document was typeset with Typst using the _modern UiT thesis_ template

#sym.copyright 2024 -- Moritz Jörg and Ole Tytlandsvik
#sym.copyright 2024 -- Moritz Jörg and Ole Tytlandsvik

#link("https://github.com/mrtz-j/typst-thesis-template")
#link("https://github.com/mrtz-j/typst-thesis-template")
]
]
]
],
Expand Down
Binary file modified template/thesis.pdf
Binary file not shown.
3 changes: 3 additions & 0 deletions template/thesis.typ
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@
),
))
// If you wish to use lining figures rather than oldstyle figures, uncomment this line.
// #set text(features: ("lnum",))
// Include as many chapters as you like.
= Introduction <chp:introduction>
Expand Down
17 changes: 17 additions & 0 deletions xcharter.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{ pkgs }:

pkgs.stdenv.mkDerivation {
pname = "XCharter";
version = "1.26";

src = pkgs.fetchzip {
url = "https://mirrors.ctan.org/fonts/xcharter.zip";
hash = "sha256-2PfPmG15Q+woBzZ7BSC/6aq566/4PM40w1766+miRgg=";
};

installPhase = ''
runHook preInstall
install -Dm644 -t $out/share/fonts/opentype/ opentype/*.otf
runHook postInstall
'';
}

0 comments on commit 4897b2f

Please sign in to comment.