Skip to content

Commit

Permalink
feat: update to typst v0.10.0, texmath v0.12.8.6 (#60)
Browse files Browse the repository at this point in the history
* fix: page break inside container

* ci: use typst v0.10.0, texmath v0.12.8.6
  • Loading branch information
megakite authored Dec 13, 2023
1 parent 783fd67 commit ad3db3b
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 65 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/auto-release-typst.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ jobs:
sudo apt-get install curl git unzip imagemagick libwebp-dev librsvg2-dev fonts-noto-cjk fonts-noto-cjk-extra
sudo apt-get remove fonts-noto-color-emoji
curl -OL https://github.com/typst/typst/releases/download/v0.9.0/typst-x86_64-unknown-linux-musl.tar.xz
curl -OL https://github.com/megakite/texmath/releases/download/v0.12.8.3-20231003/texmath-arg
curl -OL https://github.com/typst/typst/releases/download/v0.10.0/typst-x86_64-unknown-linux-musl.tar.xz
curl -OL https://github.com/megakite/texmath/releases/download/v0.12.8.6-20231213/texmath-arg
xz -dc typst-x86_64-unknown-linux-musl.tar.xz | tar -x
sudo mv ./typst-x86_64-unknown-linux-musl/typst /bin/
chmod +x texmath-arg
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test-build-typst.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ jobs:
sudo apt-get install curl git unzip imagemagick libwebp-dev librsvg2-dev fonts-noto-cjk fonts-noto-cjk-extra
sudo apt-get remove fonts-noto-color-emoji
curl -OL https://github.com/typst/typst/releases/download/v0.9.0/typst-x86_64-unknown-linux-musl.tar.xz
curl -OL https://github.com/megakite/texmath/releases/download/v0.12.8.3-20231003/texmath-arg
curl -OL https://github.com/typst/typst/releases/download/v0.10.0/typst-x86_64-unknown-linux-musl.tar.xz
curl -OL https://github.com/megakite/texmath/releases/download/v0.12.8.6-20231213/texmath-arg
xz -dc typst-x86_64-unknown-linux-musl.tar.xz | tar -x
sudo mv ./typst-x86_64-unknown-linux-musl/typst /bin/
chmod +x texmath-arg
Expand Down
9 changes: 9 additions & 0 deletions oi-wiki-export-typst/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,16 @@ async function main() {
result += '{0} {1}\n'.format('='.repeat(depth + 1), escape(key))
} else {
labelHistory.push(dirName)
if (depth === 0) {
result += `#import "../oi-wiki.typ": page-header
#pagebreak(to: "odd", weak: true)
#set page(header: none)
`
}
result += '{0} {1} <{2}>\n'.format('='.repeat(depth + 1), escape(key), dirName)
if (depth === 0) {
result += '#set page(header: page-header)\n'
}
}

for (const id in object[key]) {
Expand Down
63 changes: 2 additions & 61 deletions oi-wiki-export-typst/oi-wiki-export.typ
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

/* BEGIN imports */
#import "constants.typ": *
#import "oi-wiki.typ": page-header
/* END imports */

/* BEGIN meta */
Expand Down Expand Up @@ -136,72 +137,12 @@

/* BEGIN main */
#set page(
header: locate(loc => {
if calc.odd(loc.page()) {
// NOTE: not able to programatically hide headings on new chapters for now
// issue: https://github.com/typst/typst/issues/1613

let section = query(
selector(heading.where(level: 2)).before(loc),
loc
)
if section == () {
return none
}

let sect-number(..headings) = {
let levels = headings.pos()

if levels.len() > 1 {
[#levels.at(0).#levels.at(1)]
} else {
none
}
}

text(9pt, number-width: "tabular")[
#emph[
#counter(heading).display(sect-number)
#h(1em)
#smallcaps(section.last().body)
]
#h(1fr)
#counter(page).display("1")
]
} else {
let chapters = query(
selector(heading.where(level: 1)).before(loc),
loc,
)
// HACK: don't add headers in outlines (Chapter 0)
// This is only a workaround. Detailed mechanism of typst's pagebreaks
// needs to be further researched.
let chapter-counter = counter(heading.where(level: 1)).at(loc)
if chapter-counter == (0,) {
return none
}

text(9pt, number-width: "tabular")[
#counter(page).display("1")
#h(1fr)
#counter(heading.where(level: 1)).display("一")章
#h(1em)
#chapters.last().body
]
}
})
header: page-header
)

#counter(page).update(1)

#show heading.where(level: 1): it => {
set page(
header: none,
//fill: luma(95%),
)

pagebreak(to: "odd", weak: true)

set text(
25pt,
font: ("New Computer Modern", "Noto Serif CJK SC"),
Expand Down
55 changes: 55 additions & 0 deletions oi-wiki-export-typst/oi-wiki.typ
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,61 @@
#import "@preview/tiaoma:0.1.0"
/* END imports */

#let page-header = locate(loc => {
if calc.odd(loc.page()) {
// NOTE: not able to programatically hide headings on new chapters for now
// issue: https://github.com/typst/typst/issues/1613

let section = query(
selector(heading.where(level: 2)).before(loc),
loc
)
if section == () {
return none
}

let sect-number(..headings) = {
let levels = headings.pos()

if levels.len() > 1 {
[#levels.at(0).#levels.at(1)]
} else {
none
}
}

text(9pt, number-width: "tabular")[
#emph[
#counter(heading).display(sect-number)
#h(1em)
#smallcaps(section.last().body)
]
#h(1fr)
#counter(page).display("1")
]
} else {
let chapters = query(
selector(heading.where(level: 1)).before(loc),
loc,
)
// HACK: don't add headers in outlines (Chapter 0)
// This is only a workaround. Detailed mechanism of typst's pagebreaks
// needs to be further researched.
let chapter-counter = counter(heading.where(level: 1)).at(loc)
if chapter-counter == (0,) {
return none
}

text(9pt, number-width: "tabular")[
#counter(page).display("1")
#h(1fr)
#counter(heading.where(level: 1)).display("一")章
#h(1em)
#chapters.last().body
]
}
}
)

#let horizontalrule = align(center, block(
sym.ast.op + h(1em) + sym.ast.op + h(1em) + sym.ast.op
Expand Down

0 comments on commit ad3db3b

Please sign in to comment.