常见问题
本页收集了 Touying 使用中的常见问题与解决方案。
主题与配置
如何选择和切换主题?
Touying 提供多个内置主题,通过导入并应用主题函数即可切换:
#import "@preview/touying:0.8.0": *
#import themes.simple: *
#show: simple-theme
= Section
== Slide
Using the simple theme.
其他内置主题包括 themes.default、themes.metropolis、themes.aqua、themes.dewdrop、themes.stargazer、themes.university 等。
如何自定义主题颜色?
使用 config-colors(primary: ...) 自定义主题的主色调:
#import "@preview/touying:0.8.0": *
#import themes.metropolis: *
#show: metropolis-theme.with(
aspect-ratio: "16-9",
config-colors(primary: rgb("#d94f00")),
config-info(title: [Custom Color], author: [Author]),
)
= Section
== Slide
The header now uses the custom primary color.
如何在正文中访问当前主题颜色?
主题颜色保存在 self.colors 中。在普通幻灯片正文里,可以用 touying-fn-wrapper-raw 包裹一个函数,让 Touying 把当前幻灯片上下文作为 self 传入:
#import "@preview/touying:0.8.0": *
#import themes.simple: *
#show: simple-theme.with(aspect-ratio: "16-9")
= Section
== Slide
#touying-fn-wrapper-raw((self: none) => text(fill: self.colors.primary)[
This text uses the current theme's primary color.
])
#touying-fn-wrapper-raw((self: none) => rect(
fill: self.colors.secondary,
width: 4em,
height: 1em,
))
如果你正在编写已经接收 self 的主题方法或回调函数,则可以直接使用 self.colors.primary、self.colors.neutral-lightest 等颜色。
你仍然可以使用 touying-fn-wrapper,但 raw 变体不会脱离 pause 流程,并且可以嵌套在所有动画方法以及它自身之中,参见这里。
布局与分栏
如何创建两栏布局?
使用带 composer 参数的 slide 将内容分成多列:
#import "@preview/touying:0.8.0": *
#import themes.simple: *
#show: simple-theme
#slide(composer: (1fr, 1fr))[
== Left Column
Some text on the left side.
][
== Right Column
Some text on the right side.
]
若各列等宽,也可以省略 composer 参数。
如需不等宽的列,可调整分数比例,例如 (2fr, 1fr)。
如何将内容放置在绝对位置?
使用 Typst 的 place 函数进行绝对定位:
#import "@preview/touying:0.8.0": *
#import themes.simple: *
#show: simple-theme
#slide[
Main slide content here.
#place(bottom + right, dx: -1em, dy: -1em)[
#rect(fill: blue.lighten(80%), inset: 0.5em)[Note]
]
]
如何让内容填满幻灯片的剩余高度或宽度?
使用 utils.fit-to-height 或 utils.fit-to-width:
#import "@preview/touying:0.8.0": *
#import themes.simple: *
#show: simple-theme
#slide[
#utils.fit-to-width(1fr)[
== This heading fills the slide width
]
Some content below.
]
目录
如何显示目录?
用 components.adaptive-columns 包裹 Typst 内置的 outline:
#import "@preview/touying:0.8.0": *
#import themes.simple: *
#show: simple-theme.with(aspect-ratio: "16-9")
== Outline <touying:hidden>
#components.adaptive-columns(outline(title: none, indent: 1em))
= First Section
== Introduction
Hello, Touying!
= Second Section
== Details
More content here.
<touying:hidden> 标签可将目录幻灯片本身从目录中隐藏。
如何只保留主目录并禁用自动章节页?
有些主题在遇到新的一级章节(=)时,会自动生成章节页(通常是目录或章节概览)。可以用 config-common(new-section-slide-fn: none) 关闭这些自动章节页,然后只保 留你手动编写的主目录页:
#import "@preview/touying:0.8.0": *
#import themes.metropolis: *
#show: metropolis-theme.with(
aspect-ratio: "16-9",
config-common(new-section-slide-fn: none),
)
== Outline <touying:hidden>
#components.adaptive-columns(outline(title: none, indent: 1em))
= First Section
== First Slide
= Second Section
== Second Slide
如何为目录中的章节添加编号?
结合 numbly 包和 #set heading(numbering: ...):
#import "@preview/touying:0.8.0": *
#import themes.simple: *
#import "@preview/numbly:0.1.0": numbly
#set heading(numbering: numbly("{1}.", default: "1.1"))
#show: simple-theme.with(aspect-ratio: "16-9")
== Outline <touying:hidden>
#components.adaptive-columns(outline(title: none, indent: 1em))
= First Section
== First Slide
= Second Section
== Second Slide
如何显示带进度高亮的目录?
使用 components.progressive-outline 高亮当前章节:
#import "@preview/touying:0.8.0": *
#import themes.dewdrop: *
#show: dewdrop-theme.with(aspect-ratio: "16-9")
= First Section
== Outline
#components.progressive-outline()
= Second Section
== Slide
参考文献与引用
如何将引用显示为脚注?
设置 config-common(show-bibliography-as-footnote: true),并在幻灯片放映的末尾自行调用 #bibliography(..)。如果你使用的参考文献样式(例如 "chicago-notes")本身就会把引用排成脚注,则不要把这一项设为 true。
#import "@preview/touying:0.8.0": *
#import themes.simple: *
#let bib = bytes(
"@book{knuth,
title={The Art of Computer Programming},
author={Donald E. Knuth},
year={1968},
publisher={Addison-Wesley},
}",
)
#show: simple-theme.with(
aspect-ratio: "16-9",
config-common(show-bibliography-as-footnote: true),
)
= Citations
== Footnote Example
This is a famous book. @knuth
== Bibliography
#bibliography(bib)
参考文献必须出现在文档中,脚注引用才能解析。如果完全不想显示参考文献列表,请改用 hide(bibliography(bib))。
如果要在还有其他内容的幻灯片上调用参考文献,必须注意不要多次调用它。
当放置参考文献的那张幻灯片包含多个子幻灯片时,就会自动发生这种重复调用。此时请用 only("h", bibliography(bib)) 包裹它,这样它只会在调用处发出一次。
演讲者备注
如何为幻灯片添加演讲者备注?
在幻灯片的任意位置使用 #speaker-note[...] 函数:
#import "@preview/touying:0.8.0": *
#import themes.simple: *
#show: simple-theme
#slide[
== My Slide
Visible content here.
#speaker-note[
- Remind the audience of the previous topic.
- Emphasize the key takeaway.
- Time check: should be at 10 min mark.
]
]
演讲者备注默认不会出现在幻灯片输出中。
如何在第二屏幕上显示演讲者备注?
使用 config-common(show-notes-on-second-screen: right) 在幻灯片旁边显示备注:
#show: simple-theme.with(
aspect-ratio: "16-9",
config-common(show-notes-on-second-screen: right),
)
top、bottom、left、right 均可使用(默认为 none)。页面会沿相应的方向加倍,多出的那一半
被放进页边距,因此幻灯片本身的尺寸保持不变。
备注面板由 config-common(notes-fn: ..) 渲染,内置实现是 touying-notes,所有自带主题都会设置它,因此备注的外观会与主题保持一致。
另外请注意,config-page(background: ..) 属于幻灯片本身,只覆盖幻灯片所在的那一半;备注的那一半需要通过 notes-fn 单独设置样式。
此功能与 pdfpc 和 pympress 等演示工具兼容。
更多内容参见演讲者备注教程。