Typstのスライドで使える小技
Typstでスライドを作成するときに使えそうな小技を,備忘のためにまとめておきます.
リストの深さに応じてフォントサイズを変更する
スライドの箇条書きでは,深さが深いところでフォントサイズを小さくしたい場合があります.

コード
#set page(width: auto, height: auto, margin: 0.5em)
#let depth = counter("list_depth")
#let freeze = state("list_freeze", false)
#let smaller_list(it) = if freeze.get() {
freeze.update(false)
it
} else {
depth.step()
context {
set text(size: 0.8em) if depth.get().first() == 2
set text(size: 0.7em) if depth.get().first() == 3
it
}
depth.update(i => i - 1)
}
#show list: smaller_list
#show enum: smaller_list
#let freeze_list = state("list_freeze").update(true)
#grid(
columns: 2
)[
- 1em
- 0.8em
- 0.8em
- $0.8 times 0.7=0.56$em
- 1em
- 0.8em
][
- 1em
#freeze_list
- 1em
- 1em
- 0.8em
- 1em
- 0.8em
]
深さ2のところは0.8倍,深さ3以降のところはfreeze_listで,深さを更新しない = フォントサイズの変更をスキップできます.
脚注に引用を書く
引用時に,そのスライド内に参考文献の情報を載せるのが一般的だと思います.ここでは,脚注に引用を載せることを考えます.
方法1 (最も簡単)
bibliographyのstyleにnoteが付くスタイルを設定します.ここでは,chicago-notesを使います.

コード
#set page(width: 15cm, height: 6cm)
#set footnote(numbering: "[1]")
#show bibliography: none
#let bib = bytes(
```bib
@inproceedings{geogc,
author = {Price, Brian L. and Morse, Bryan and Cohen, Scott},
booktitle = {Proceedings of the 2010 IEEE Computer Society Conference on Computer Vision and Pattern Recognition},
title = {Geodesic graph cut for interactive image segmentation},
year = {2010},
pages = {3161-3168},
doi = {10.1109/CVPR.2010.5540079}
}
@article{grabcut,
author = {Rother, Carsten and Kolmogorov, Vladimir and Blake, Andrew},
journal = {ACM Trans. Graph.},
title = {"GrabCut": interactive foreground extraction using iterated graph cuts},
year = {2004},
volume = {23},
number = {3},
pages = {309-314},
doi = {10.1145/1015706.1015720}
}
```.text
)
#bibliography(bib, style: "chicago-notes")
hello @geogc and #footnote[normal footnote] world @grabcut
方法2 (IEEEスタイル)
やはりIEEEスタイルを使いたいですよね.というわけで少々強引な実装をします.

コード
#set page(width: 15cm, height: 6cm)
#set footnote(numbering: "[1]")
// cite and put full information into footnote
#let footnotecite(label, lang: "en") = footnote[
#show regex("^\[\d+\]\s*"): none // remove numbering of ieee style
#text(lang: lang, cite(label, form: "full", style: "ieee"))
]
#show bibliography: none
#let bib = bytes(
```bib
@inproceedings{geogc,
author = {Price, Brian L. and Morse, Bryan and Cohen, Scott},
booktitle = {Proceedings of the 2010 IEEE Computer Society Conference on Computer Vision and Pattern Recognition},
title = {Geodesic graph cut for interactive image segmentation},
year = {2010},
pages = {3161-3168},
doi = {10.1109/CVPR.2010.5540079}
}
@article{grabcut,
author = {Rother, Carsten and Kolmogorov, Vladimir and Blake, Andrew},
journal = {ACM Trans. Graph.},
title = {"GrabCut": interactive foreground extraction using iterated graph cuts},
year = {2004},
volume = {23},
number = {3},
pages = {309-314},
doi = {10.1145/1015706.1015720}
}
```.text
)
#bibliography(bib, style: "ieee")
hello #footnotecite(<geogc>) <_geogc> and #footnote[normal footnote] world #footnotecite(<grabcut>)
hello again @_geogc
@ではなくfootnoteciteで引用することで,文献情報が脚注に載ります.footnoteciteの一番外側はfootnoteになっており,footnoteに対するラベル付けとその参照が可能です.
IEEEスタイルでフォームをfullにしてciteすると,先頭に [1] のような引用番号が付きます.この番号はfootnoteの番号とは無関係なので,これを除去して残りを脚注に入れます.
方法3 (引用番号を統一)
方法1, 2では,引用番号 = 脚注番号 としていました.方法3では,引用番号と脚注番号を独立に管理します.以下では,かなり強引な実装をしています.

コード
#set page(width: 15cm, height: 6cm)
#set footnote(numbering: "1")
// cite and put full information into footnote
#let footnotecite(label, lang: "en", form: auto, repeat: true) = {
let _cite_state = state("_cite_state", (:))
context {
// get cite number for the label in the document before here
let cite_s = query(selector(cite).before(here())).dedup(key: c => c.key)
let cite_n = cite_s.position(c => c.key == label)
let cite_n = if cite_n != none { cite_n } else { cite_s.len() }
_cite_state.update((num: cite_n, last: cite_n == cite_s.len()))
}
context {
let cf = counter(footnote)
let footnote_num = cf.get() // current footnote number
let cite_nl = _cite_state.get()
cf.update(cite_nl.num) // change footnote number to cite number
// footnote citation
let citation(autoform) = footnote(numbering: "[1]", {
show regex("^\[\d+\]\s*"): none
text(lang: lang,
cite(label, form: if form == auto { autoform } else { form }, style: "ieee"))
})
if cite_nl.last { // not cite yet
citation("full")
} else if repeat { // already cited but cite again
citation("author")
} else {
query(footnote.where(numbering: "[1]").before(here()))
.rev().find(x => x.body.child.key == label)
}
cf.update(footnote_num) // reset footnote number
}
}
#show bibliography: none
#let bib = bytes(
```bib
@inproceedings{geogc,
author = {Price, Brian L. and Morse, Bryan and Cohen, Scott},
booktitle = {Proceedings of the 2010 IEEE Computer Society Conference on Computer Vision and Pattern Recognition},
title = {Geodesic graph cut for interactive image segmentation},
year = {2010},
pages = {3161-3168},
doi = {10.1109/CVPR.2010.5540079}
}
@article{grabcut,
author = {Rother, Carsten and Kolmogorov, Vladimir and Blake, Andrew},
journal = {ACM Trans. Graph.},
title = {"GrabCut": interactive foreground extraction using iterated graph cuts},
year = {2004},
volume = {23},
number = {3},
pages = {309-314},
doi = {10.1145/1015706.1015720}
}
```.text
)
#bibliography(bib, style: "ieee")
hello #footnotecite(<geogc>) and #footnote[normal footnote] world #footnotecite(<grabcut>)
hello again #footnotecite(<geogc>, repeat: false)
footnoteのリファレンス・リンクが正しく動作するように実装したため,複雑になっています.見た目だけであれば,もっと簡単に実装できます.注意点として,Typst 0.14.0以上が必要です.また,同じ文献を3回目以上脚注で引用するとき,repeat: falseと設定するとWarningがでます.refを使わずに,同じfootnoteを再度呼び出しているのが原因だと思われます.
query(cite)でドキュメント内の引用を抽出し,それらからkeyが同じものを除いた(dedup)配列を用いて,引用番号を取得しています.つまりdedupしても順番が変わらない前提です.また同じ文献を複数回脚注で引用する場合,repeat: falseでは,その文献について既にある最後の脚注引用を取得しています.なお,同じラベルが乱立するのを避けるために,実装においてラベルの使用を避けています.
目次の脚注を除去する
見出しに脚注を付けると,目次にも脚注がついてしまいます.それを解決します.

コード
#set page(width: 15cm, height: 6cm)
#[
#outline(target: <f1>)
= Title #footnote[footnote] <f1>
]
#pagebreak()
#[
// use this when removing footnote from the outline
#let show-footnote = state("show-footnote", (true,))
#let footnote(..args) = context if show-footnote.get().last() { std.footnote(..args) }
// remove footnote from the outline
#let clean-footnote(it) = context {
state("show-footnote").update(stack => (..stack, false))
it
state("show-footnote").update(stack => stack.slice(0, -1))
}
#show outline: clean-footnote
#outline(target: <f2>)
= Title #footnote[footnote] <f2>
]
element functionであるfootnoteを上書きしています.具体的にはoutlineの中では無効になるようなfootnoteを再定義しています."脚注に引用を書く"の方法3とは相性が悪いです.
Touying
Touyingは,Typstでスライドを作成するための強力なパッケージです.自分が知っている小技をまとめておきます.
config-common,config-infoなどは,基本的にテーマを初期化するときに設定します.
#import "@preview/touying:0.6.1": *
#import themes.simple: *
#show: simple-theme.with(
config-common(
...
),
config-info(
...
),
)
new section slide
深さ1の見出しを書くと,セクションスライドが自動で挿入されますが,それを除去します.
config-common(new-section-slide-fn: none)
特定のセクションスライドだけを除去することもできます.
= Title <touying:skip>
見出しのコントロール
見出しを目次等から除外したいときに使います.
== First Slide <touying:hidden>
-
<touying:hidden>: 番号付け,目次,PDFのしおりから見出しを削除 -
<touying:unnumbered>: 番号付けのみを削除 -
<touying:unoutlined>: 目次から削除 -
<touying:unbookmarked>: PDFのしおりから削除
フッターの除去
特定のスライドからフッターを除去します.同じ要領でヘッダーも除去できます.また,特定のスライドのヘッダー・フッターを変更することもできます.
== Second Slide
#slide(config: (page: (footer: none)))[
hello hello
]
付録
最後のスライド番号が#show: appendixの直前になります.
#show: appendix
== Appendix
hello hello
スライド番号
utils.slide-counter.display()が現在のスライド番号,utils.last-slide-numberが最後のスライド番号です.現在のスライド番号を取得するにはcontextが必要です.
#context utils.slide-counter.display() + " / " + utils.last-slide-number
脚注引用 (現状機能しない)
実は,Touyingには引用を脚注に表示する機能があります.しかし,現状機能しません.
参考
Discussion