全局设置
全局样式
对 Touying 而言,全局样式即为需要应用到所有地方的 set rules 或 show rules,例如 #set text(size: 20pt)。
其中,Touying 的主题会封装一些自己的全局样式,他们会被放在 #self.methods.init 中,例如 simple 主题就封装了:
config-methods(
init: (self: none, body) => {
set text(size: 25pt)
show footnote.entry: set text(size: .6em)
show heading.where(level: 1): set text(1.4em)
body
},
alert: utils.alert-with-primary-color,
)
如果你并非一个主题制作者,而只是想给你的 slides 添加一些自己的全局样式,你可以简单地将它们放在 #show: xxx-theme.with() 之前或之后。例如 metropolis 主题就推荐你自行加入以下全局样式:
#set text(font: "Fira Sans", weight: "light", size: 20pt)
#show math.equation: set text(font: "Fira Math")
#set strong(delta: 100)
#set par(justify: true)
全局信息
就像 Beamer 一样,Touying 通过统一 API 设计,能够帮助您更好地维护全局信息,让您可以方便地在不同的主题之间切换,全局信息就是一个很典型的例子。
你可以通过
config-info(
title: [Title],
short-title: [Short Title],
subtitle: [Subtitle],
short-subtitle: [Short Subtitle],
author: [Authors],
date: datetime.today(),
institution: [Institution],
contact: [contact\@mail.com],
logo: [logo.png],
extra: (supervisor:[Supervisor],),
)
其中 short-title 和 short-subtitle 是给页眉、页脚这种空间有限的位置准备的短标题,默认值为 auto,此时会回退到 title 和 subtitle。
你甚至可以传入额外信息,以维护其他属性未涵盖的演示文稿信息。
在后续,你就可以通过 self.info 这样的方式访问它们。
这些信息一般会在主题的 title-slide、header 和 footer 被使用到,例如 #show: metropolis-theme.with(aspect-ratio: "16-9", footer: self => self.info.institution)。
其中 date 可以接收 datetime 格式和 content 格式,并且 datetime 格式的日期显示格式,可以通过
config-common(datetime-format: "[year]-[month]-[day]")
的方式更改。
配置函数一览
Touying 的所有配置都通过一组 config-* 函数传给主题,它们返回的字典会被合并成 self:
| 函数 | 作用 |
|---|---|
config-common(..) | 通用配置:slide-fn、slide-level、handout、preamble、frozen-counters 等。 |
config-page(..) | 页面配置:paper、margin、header、footer、fill 等,对应 set page(..) 的参数。 |
config-info(..) | 演示文稿元信息,见上文。 |
config-colors(..) | 主题色板,通过 self.colors 访问。 |
config-methods(..) | 主题方法,例如 init、alert,通过 self.methods 访问。 |
config-store(..) | 主题自定义的存储字段,通过 self.store 访问。 |
config-article(..) | article(文章)模 式下的排版选项,见下文。 |
演讲者备注面板
config-common(notes-fn: ..) 决定演讲者备注面板的渲染方式,第二屏输出和 show-only-notes 模式都使用它。它接收 (self: none, note: none, slide-preview: none) 并返回内容,默认值是 touying-notes;主题覆盖它的方式与覆盖 slide-fn 完全一样。详见演讲者备注。
输出模式与 article 模式
| 键 | 默认值 | 说明 |
|---|---|---|
config-common(export-mode: ..) | "slides" | 输出模式,取值为 "slides"、"presentation"、"handout"、"article"。也可以在命令行用 --input export-mode=article 设置。 |
config-common(article-mode: ..) | false | 直接打开 article 模式的开关。一般请改用 export-mode。 |
config-common(article-theme: ..) | auto | article 模式使用的主题,auto 表示 Touying 内置的 themes.article。 |
config-article(..) 用于配置 article 模式下的排版,例如把图片浮动到侧边、指定标题块,以及把配置字段传给 article 主题:
#import "@preview/touying:0.8.0": *
#import themes.simple: *
#import themes.article: article-theme
#show: simple-theme.with(
config-info(title: [Title], author: [Author], date: datetime.today()),
config-common(
export-mode: "article",
article-theme: article-theme.with(numbering: "1.1"),
),
config-article(
wrap: (image: true),
title-block-fn: auto,
available-fields: (title: "info.title"),
),
)
title-block-fn: auto 会使用内置的标题块并读取 document 元数据;当日期仍为 auto 时,会自动使用当天日期。
在正文里,#article-only[..]、#article-text[..]、#slides-only[..] 和 #presentation-only[..] 可以按输出目标切换内容。
前言(Preambles)
config-common(preamble: ...) 选项在整个演示文稿的第一张幻灯片之前执行一次初始化代码。这在集成 codly 等包时非常有用:
#show: simple-theme.with(
config-common(preamble: {
codly(languages: codly-languages)
}),
)
若要在每张幻灯片之前运行代码,请使用 slide-preamble;若要在每个子幻灯片中运行代码或注入内容,请使用 subslide-preamble。这些前言都在对应页面的页眉排版之后、页面的任何正文内容之前运行。
你还可以指定 page-preamble,它在页眉之前、针对每一页运行,包括溢出的幻灯片页等。
全局配置覆盖(Show-Rule)
你可以使用 #show: touying-set-config.with(...) 覆盖当前及其后所有幻灯片的任意配置,用法与普通的 show/set 规则相同:
#import "@preview/touying:0.8.0": *
#import themes.simple: *
#show: simple-theme.with(aspect-ratio: "16-9")
== Normal Slide
This slide uses the default settings.
== Blue Background Slide
#show: touying-set-config.with(config-page(fill: blue.lighten(80%)))
This slide has a blue background applied via `touying-set-config`.
== Red Accent Slide
#show: touying-set-config.with(config-colors(primary: red))
This slide uses a red primary color, e.g. in `#alert` boxes.
#alert[This is an alert box with red accent color.]
== Changed Cover
#show: touying-set-config.with(config-methods(
cover: utils.alpha-changing-cover,
))
Initial Content.
#pause
Content that is hidden by showing with low alpha value.
局部配置覆盖
如果你只想影响某一张幻灯片,可以通过 #slide(config: ...)[...] 局部设置配置:
== Local Config
#slide(config:config-page(fill: purple.lighten(90%)))[
Only this slide has a light purple background, but the next slide goes back being light blue.
]