diff --git a/src/intermediate/mod.typ b/src/intermediate/mod.typ index b32598a..a769d4c 100644 --- a/src/intermediate/mod.typ +++ b/src/intermediate/mod.typ @@ -1,42 +1,4 @@ #import "/src/book.typ" -#import "../mod.typ": code as _code, exec-code as _exec-code, refs, typst-func, pro-tip, todo-box +#import "../mod.typ": code as _code, exec-code as _exec-code, pro-tip, refs, todo-box, typst-func #import "/typ/templates/page.typ": main-color -#import "/typ/embedded-typst/lib.typ": svg-doc, default-fonts, default-cjk-fonts - -#let eval-local(it, scope, res) = if res != none { - res -} else { - eval(it.text, mode: "markup", scope: scope) -} -#let exec-code(it, scope: (:), res: none, ..args) = _exec-code( - it, - res: eval-local(it, scope, res), - ..args, -) -#let code(it, scope: (:), res: none, ..args) = _code( - it, - res: eval-local(it, scope, res), - ..args, -) - -#let frames(code, cjk-fonts: false, code-as: none, prelude: none) = { - if code-as != none { - code-as - } else { - code - } - - if prelude != none { - code-as = if code-as == none { - code - } - code = prelude.text + "\n" + code.text - } - - let fonts = if cjk-fonts { - (..default-cjk-fonts(), ..default-fonts()) - } - - grid(columns: (1fr, 1fr), ..svg-doc(code, fonts: fonts).pages.map(data => image(bytes(data))).map(rect)) -} -#let frames-cjk = frames.with(cjk-fonts: true) +#import "/typ/embedded-typst/lib.typ": default-cjk-fonts, default-fonts, svg-doc diff --git a/src/tutorial/doc-modulize.typ b/src/tutorial/doc-modulize.typ index 6ae4d2d..dd5ea93 100644 --- a/src/tutorial/doc-modulize.typ +++ b/src/tutorial/doc-modulize.typ @@ -2,7 +2,9 @@ #show: book.page.with(title: [模块化(多文件)]) -正如我们在《初识脚本模式》中所说的,Typst提供了脚本语言方便排版。但事实上,写作时若能少写甚至不写脚本,这才算真正的便捷。我们总希望Typst能够允许我们以一种优雅的方式#strike[复制粘贴]引入已有代码。理想情况下,只需两行代码便可引入前辈写好的模板: +我们接下来学习脚本剩余的所有知识。总结而言,每个源文件对应一个模块;每个模块导出多个「变量声明」和一个「文档(内容)树」。回忆编译流程,求值按照「控制流」顺序执行表达式。「排版」(typeset)时,按照「文档树」顺序更新状态和排版结果。迭代排版多次,直到布局不再发生变化。 + +本节首先来讲讲Typst中的模块。正如我们在《教程:脚本模式》中所说的,Typst提供了脚本语言方便排版。但事实上,写作时若能少写甚至不写脚本,这才算真正的便捷。我们总希望Typst能够允许我们以一种优雅的方式#strike[复制粘贴]引入已有代码。理想情况下,只需两行代码便可引入前辈写好的模板: #```typ #import "@preview/senpai-no-awesome-template.typ:0.x.x": * diff --git a/typ/templates/page.typ b/typ/templates/page.typ index a5d4335..51e448c 100644 --- a/typ/templates/page.typ +++ b/typ/templates/page.typ @@ -1,7 +1,7 @@ // This is important for typst-book to produce a responsive layout // and multiple targets. -#import "@preview/shiroa:0.2.3": get-page-width, target, is-web-target, is-pdf-target, plain-text, templates +#import "@preview/shiroa:0.2.3": get-page-width, is-pdf-target, is-web-target, plain-text, target, templates #import templates: * #import "template-link.typ": * #import "/typ/templates/side-notes.typ": side-attrs @@ -254,7 +254,7 @@ if title != none { if is-web-target { - [= #title] + // [= #title] } else { v(0.5em) align(center, [= #title])