Skip to content

Commit

Permalink
Add page header
Browse files Browse the repository at this point in the history
  • Loading branch information
kdkasad committed Dec 16, 2024
1 parent cb5d624 commit 406ba43
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 12 deletions.
Binary file modified examples/computer-science.pdf
Binary file not shown.
2 changes: 1 addition & 1 deletion examples/computer-science/main.typ
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#show: khw.with(
title: [Homework 3],
course: "CS 250",
course: "CS 250: Computer Architecture",
author: "Kian Kasad",
)

Expand Down
Binary file modified examples/english.pdf
Binary file not shown.
35 changes: 27 additions & 8 deletions khw.typ
Original file line number Diff line number Diff line change
Expand Up @@ -72,17 +72,36 @@
set math.equation(numbering: "(1)")
set page(numbering: "1")

// Title block {{{2
if title != none {
align(center, {
text(weight: "bold", size: 18pt, {
// Page header {{{2
set page(
header-ascent: 50%,
header: context {
set text(10pt)
let pagenum = counter(page).get().first()
if pagenum != 1 {
if course != none {
course + [ --- ]
if type(course) == str {
course.replace(regex("(:\s+|\s+-+\s+).*$"), "")
} else {
course
}
[ --- ]
}
title
})
parbreak()
author
h(1fr)
author
}
}
)

// Title block {{{2
if title != none {
align(center, {
text(18pt, weight: "bold", title)
linebreak()
text(12pt, course)
linebreak()
text(12pt, author)
})
v(1cm, weak: true)
}
Expand Down
Binary file modified manual.pdf
Binary file not shown.
20 changes: 17 additions & 3 deletions manual.typ
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,9 @@ it to all content using a show rule:
)[Document setup code.]

The `title` and `author` fields are used to print a title
block on the first page, as well as to set the document's
metadata using ```typc document()```.
block on the first page, set the document's metadata using
```typc document()```, and print a header on every page except
the first.

The `khw()` function supports the following optional parameters:

Expand Down Expand Up @@ -188,7 +189,20 @@ used to set default options for the ```typc problem()``` and
handle storing functions, but I have not verified this.
]

#pagebreak()
== Page header
On every page except the first, a header will be displayed,
consisting of the course and title on the left and the author
on the right.

The course is preprocessed in a special way: if the `course`
parameter to the `khw()` function was a string, a _course
prefix separator_ and everything after it is removed.
The course prefix separator is anything that matches the
following regular expression: ```regex (:\s+|\s+-+\s+)```.
This allows you to print something like "CS 250: Computer
Architecture" in the title block while still keeping the
header short enough.

== Typesetting problems
Use the `problem()` function to typeset a problem. The
function takes a non-optional content argument which can be
Expand Down

0 comments on commit 406ba43

Please sign in to comment.