typst_reference / chp03.typ
孟祥瑞
上传语料:typst_reference
fdbb2bf verified
Raw History Blame Contribute Delete
152 kB
#let rtext(content)={ text(fill: rgb(139,0,0),content) } = 模型库(Model)<model> 文档结构化。 在此处,你可以找到用于构建文档结构并与该结构交互的各项功能。包括章节标题、图表、参考文献管理、交叉引用等。 == 资源(asset)<asset> 将自定义文件添加到包中。 此函数从#link(<bytes>)[原始字节数据]创建包中的单个文件。与#link(<document>)[文档]不同,资源将按原样发出,而无需进行编译。 asset函数可以与#link(<read>)[读取]相结合,将文件从项目复制到输出包中。asset的第一个参数定义了bundle中资产的输出路径,而传递给read的路径定义了从项目中的何处读取数据。 ```typst // Copy the file `styles.css` into the bundle. #asset("styles.css", read("styles.css")) ``` 也就是说,资源与读无关。您还可以直接生成字节或使用#link(<json_encode>)[json.encode]等函数来发出序列化数据。 ```typst // Emits a JSON file with the number // of headings in the document. #context { let headings = query(heading) let meta = ( count: headings.len(), ) asset("meta.json", json.encode(meta)) } #document("doc.pdf")[ = Introduction = Conclusion ] ``` 这将在生成的包中输出一个包含以下内容的meta.json文件: ```typst { "count": 2 } ``` 此函数仅限在绑定目标中使用。 === 参数(Parameters) ```typc asset( path:str, data:str bytes, ) → content ``` - *path*: str 资源在程序包内的存放路径。 路径中可包含内部斜杠,此时系统会自动创建中间层级目录。 - *data*: str bytes 将写入指定路径文件的原始数据。 如果传入字符串,将使用UTF-8进行编码。 == 参考文献(bibliography)<bibliography> 参考书目/参考文献列表。 您可以通过调用此函数来创建新的参考书目,该函数具有以下两种格式之一的参考书目文件的路径: #set par(hanging-indent: 1.3cm) -- Hayagriva.yaml/.yml文件。Hayagriva是一种新的书目文件格式,专为Typst设计。有关更多详细信息,请访问其文档。 -- BibLaTeX.bib文件。 #set par(hanging-indent: 0cm) 一旦你在文档的某个地方添加了参考书目,你就可以开始引用引用语法(```typc @key```)或对引用函数(```typc #cite(<key>)```)的显式调用。参考书目将仅显示文档中引用的作品条目。 === 示例(Example) #table( columns: (1fr,1fr), align: (left,left), stroke: none, fill: (rgb(250, 250, 250),luma(86.27%)), [ ```typst This was already noted by pirates long ago. @arrgh Multiple sources say ... @arrgh @netwok. #bibliography("works.bib") ``` ],[ #set align(horizon) #image("images/3001.png",width: auto)] ) === 风格(Styles)<bibliography_Styles> Typst提供了多种内置的引文和参考书目样式。除此之外,您还可以添加和使用自定义CSL(引文样式语言)文件。想知道使用哪种风格?以下是一些基于您所从事的学科的良好默认值: #table( columns: (1fr,1fr), stroke: none, table.header[Fields][Typical Styles], table.hline(), [Engineering,IT],[\"ieee\"], [Psychology,Life Sciences],[\"apa\"], [Social sciences],[\"chicago-author-date\"], [Humanities],[\"mla\",\"chicago-notes\",\"harvard-cite-them-right\"], [Economics],[\"harvard-cite-them-right\"], [Physics],[\"american-physics-society\"], ) === 多参考书目(Multiple bibliographies)<bibliography_Multiple> 当Typst文档包含多个参考书目时,每个引用都会分配给其中一个。默认情况下,Typst会自动选择一个合适的参考书目(通常是包含引用关键字的最接近的参考书目)。这涵盖了常见的案例,如按章节或主题参考书目。为了进行更精细的控制,引用可以通过目标选择器由参考书目明确地定位。 === 参数(Parameters)<bibliography_Parameters> ```typc bibliography( sources:str path bytes array, title: none auto content, full: bool, style: str path bytes, target: auto label selector location function, group: none auto str, ) → content ``` - *sources*:str or path or bytes or array Hayagriva.yaml和/或BibLaTeX.bib文件的一个或多个路径或原始字节。 这可以是: -- 加载参考文献目录文件的路径字符串或路径。 -- 应从中解码参考书目的原始字节。 -- 一个数组,其中每个项目都是上述之一。 - *title*: none or auto or content 参考书目的标题。缺省值:#rtext()[auto]。 -- 当设置为#rtext()[auto]时,将使用#link(<text_lang>)[文本语言]的适当标题。这是默认设置。 -- 当设置为#rtext()[none]时,参考书目将没有标题。 -- 可以通过传递内容来设置自定义标题。 默认情况下,参考书目的标题不会编号,但您可以使用show-set规则:```typc show bibliography: set heading(numbering: "1.")``` - *full*: bool 是否包括给定参考书目文件中的所有作品,即使是文档中未引用的作品。缺省值:#rtext()[false]。 要选择性地添加单个引用的作品而不显示它们,您还可以使用表单设置为none的cite函数。 - *style*: str or path or bytes 书目风格。缺省值:#rtext()[ieee]。 这可以是: #set par(hanging-indent: 1.3cm) -- 具有内置样式之一名称的字符串(见下文)。下面列出的一些样式会出现两次,一次是全名,一次则是短别名。 -- #link("https://citationstyles.org/")[CSL文件]的路径字符串或#link(<Path>)[路径]。 -- 应从中解码CSL样式的原始字节。 #set par(hanging-indent: 0cm) 选项列表: #table( columns: (1fr,1fr), stroke: none, table.header[*Variant*][*Details*], table.hline(), [\"alphanumeric\"],[Alphanumeric], [\"american-anthropological-association\"],[American Anthropological Association], [\"american-chemical-society\"],[ACS Guide 2022 revision], [\"american-geophysical-union\"],[American Geophysical Union], [\"american-institute-of-aeronautics-and-astronautics\"],[American Institute of Aeronautics and Astronautics], [\"american-institute-of-physics\"],[AIP Style Manual 4th edition], [\"american-medical-association\"],[AMA Manual of Style 11th edition], [\"american-meteorological-society\"],[American Meteorological Society], [\"american-physics-society\"],[American Physical Society], [\"american-physiological-society\"],[American Physiological Society], [\"american-political-science-association\"],[APSA Style Manual revised 2018 edition], [\"american-psychological-association\"],[APA Style 7th edition], [\"apa\"],[A short alias of american-psychological-association], [\"american-society-for-microbiology\"],[American Society for Microbiology], [\"american-society-of-civil-engineers\"],[American Society of Civil Engineers], [\"american-society-of-mechanical-engineers\"],[American Society of Mechanical Engineers], [\"american-sociological-association\"],[ASA Style Guide 6th/7th edition], [\"angewandte-chemie\"],[Angewandte Chemie International Edition], [\"annual-reviews\"],[Annual Reviews (sorted by order of appearance)], [\"annual-reviews-author-date\"],[Annual Reviews (author-date)], [\"associacao-brasileira-de-normas-tecnicas\"],[Associação Brasileira de Normas Técnicas (Português - Brasil)], [\"association-for-computing-machinery\"],[Association for Computing Machinery], [\"biomed-central\"],[BioMed Central], [\"bristol-university-press\"],[Bristol University Press], [\"british-medical-journal\"],[BMJ], [\"bmj\"],[A short alias of british-medical-journal], [\"cell\"],[Cell], [\"chicago-author-date\"],[Chicago Manual of Style 18th edition (author-date)], [\"chicago-notes\"],[Chicago Manual of Style 18th edition (notes and bibliography)], [\"chicago-fullnotes\"],[A short alias of chicago-notes], [\"chicago-shortened-notes\"],[Chicago Manual of Style 18th edition (shortened notes and bibliography)], [\"copernicus\"],[Copernicus Publications], [\"cse-citation-sequence-brackets-8th-edition\"],[CSE Manual: Scientific Style and Format 8th edition (citation-sequence, brackets)], [\"council-of-science-editors\"],[A short alias of cse-citation-sequence-brackets-8th-edition], [\"cse-name-year\"],[CSE Manual: Scientific Style and Format 9th edition (name-year)], [\"council-of-science-editors-author-date\"],[A short alias of cse-name-year], [\"current-opinion\"],[Current Opinion journals], [\"deutsche-gesellschaft-für-psychologie\"],[Deutsche Gesellschaft für Psychologie 5. Auflage (Deutsch)], [\"deutsche-sprache\"],[Deutsche Sprache (Deutsch)], [\"elsevier-harvard\"],[Elsevier (author-date/Harvard, with titles)], [\"elsevier-vancouver\"],[Elsevier - NLM/Vancouver (citation-sequence)], [\"elsevier-with-titles\"],[Elsevier (numeric, with titles)], [\"frontiers\"],[Frontiers journals], [\"future-medicine\"],[Future Medicine journals], [\"future-science\"],[Future Science Group], [\"gb-7714-2005-numeric\"],[China National Standard GB/T 7714-2005 (numeric, 中文)], [\"gb-7714-2015-author-date\"],[China National Standard GB/T 7714-2015 (author-date, 中文)], [\"gb-7714-2015-note\"],[China National Standard GB/T 7714-2015 (note, 中文)], [\"gb-7714-2015-numeric\"],[China National Standard GB/T 7714-2015 (numeric, 中文)], [\"gost-r-705-2008-numeric\"],[Russian GOST R 7.0.5-2008 (numeric)], [\"harvard-cite-them-right\"],[Cite Them Right 12th edition (author-date/Harvard)], [\"institute-of-electrical-and-electronics-engineers\"],[IEEE Reference Guide version 11.29.2023], [\"ieee\"],[A short alias of institute-of-electrical-and-electronics-engineers], [\"institute-of-physics-numeric\"],[Institute of Physics (numeric)], [\"iso-690-author-date\"],[ISO-690 (author-date, English)], [\"iso-690-numeric\"],[ISO-690 (numeric, English)], [\"karger\"],[Karger journals], [\"mary-ann-liebert-vancouver\"],[Mary Ann Liebert - NLM/Vancouver], [\"modern-humanities-research-association-notes\"],[MHRA Style Guide 4th edition (notes)], [\"modern-humanities-research-association\"],[A short alias of modern-humanities-research-association-notes], [\"modern-language-association\"],[MLA Handbook 9th edition (in-text citations)], [\"mla\"],[A short alias of modern-language-association], [\"modern-language-association-8\"],[A short alias of modern-language-association], [\"mla-8\"],[A short alias of modern-language-association], [\"multidisciplinary-digital-publishing-institute\"],[Multidisciplinary Digital Publishing Institute], [\"nature\"],[Nature], [\"nlm-citation-sequence\"],[NLM/Vancouver: Citing Medicine 2nd edition (citation-sequence)], [\"vancouver\"],[A short alias of nlm-citation-sequence], [\"nlm-citation-sequence-superscript\"],[NLM/Vancouver: Citing Medicine 2nd edition (citation-sequence, superscript)], [\"vancouver-superscript\"],[A short alias of nlm-citation-sequence-superscript], [\"pensoft\"],[Pensoft Journals], [\"public-library-of-science\"],[Public Library of Science], [\"plos\"],[A short alias of public-library-of-science], [\"royal-society-of-chemistry\"],[Royal Society of Chemistry], [\"sage-vancouver\"],[SAGE - NLM/Vancouver], [\"sist02\"],[SIST02 (日本語)], [\"spie\"],[SPIE journals], [\"springer-basic\"],[Springer - Basic (numeric, brackets)], [\"springer-basic-author-date\"],[Springer - Basic (author-date)], [\"springer-fachzeitschriften-medizin-psychologie\"],[Springer - Fachzeitschriften Medizin Psychologie (Deutsch)], [\"springer-humanities-author-date\"],[Springer - Humanities (author-date)], [\"springer-lecture-notes-in-computer-science\"],[Springer - Lecture Notes in Computer Science], [\"springer-mathphys\"],[Springer - MathPhys (numeric, brackets)], [\"springer-socpsych-author-date\"],[Springer - SocPsych (author-date)], [\"springer-vancouver\"],[Springer - NLM/Vancouver (citation-sequence, brackets)], [\"taylor-and-francis-chicago-author-date\"],[Taylor & Francis Journals Standard Reference Style Guide: Chicago author-date version 2.0], [\"taylor-and-francis-national-library-of-medicine\"],[Taylor & Francis - NLM/Vancouver (citation-sequence, brackets)], [\"the-institution-of-engineering-and-technology\"],[The Institution of Engineering and Technology], [\"the-lancet\"],[The Lancet], [\"thieme\"],[Thieme-German (Deutsch)], [\"trends\"],[Trends journals], [\"turabian-author-date\"],[Chicago Manual of Style 17th edition (author-date)], [\"turabian-fullnote-8\"],[Chicago Manual of Style 17th edition (notes and bibliography, subsequent author-title)], ) - *target*:auto or label or selector or location or function 定义要包含在参考书目中的引用。缺省值:#rtext()[auto]。 Typst会自动将文档中的每个引文分配给一个参考书目。具体来说,引文将按优先顺序分配给 #set par(hanging-indent: 1.3cm) -- 第一个将其包含在目标选择器中的参考书目;或者,如果不存在这样的参考书目 -- 与target最接近的以下参考书目:包含其关键字的#rtext()[auto];或者如果没有这样的参考书目 -- 与target: #rtext()[auto]最接近的前一个参考书目,其中包含其关键字。 #set par(hanging-indent: 0cm) #table( columns: 1fr, stroke: none, align: left, [ ```Typst #let info(body) = block( stroke: (left: 1.5pt + blue), fill: aqua.lighten(50%), inset: 1em, context { body show divider: set block(spacing: 1.2em) divider() bibliography( "works.bib", title: none, target: selector(cite).within(here()), style: "mla", ) } ) = On the matter of dumplings In recent years, we can observe an uptick in dumpling consumption across the board. @netwok #info[ Dumplings are particularly enjoyed among pirates. @arrgh ] #bibliography("works.bib") ``` ] , [ #image("images/3002.png") ] ) - *group*: none or auto or str 出于编号目的,从概念上将此参考书目与其他参考书目分组。同一组的参考书目将分配连续的引用号。缺省值:#rtext()[auto]。 这可以是: -- #rtext()[none]:参考书目将单独编号。 -- #rtext()[auto]:参考书目将与auto组中的所有其他参考书目连续编号。 -- 字符串:参考书目将与具有相同组值的所有其他参考书目连续编号。 自动组的工作方式与任何字符串组一样,但它是规范的默认组。 例1:连续引用编号 #table( columns: (1fr,1fr), align: (left,left), stroke: none, fill: (rgb(250, 250, 250),luma(86.27%)), [ ```typst #show bibliography: set heading( offset: 1, ) = First part Starts at one: @netwok @arrgh #bibliography( "works.bib", style: "ieee", ) = Second part Continues with three: @distress #bibliography( "works.bib", style: "nlm-citation-sequence", ) ``` ],[ #set align(horizon) #image("images/3003.png",width: auto)] ) 例2:单独的引用编号 #table( columns: (1fr,1fr), align: (left,left), stroke: none, fill: (rgb(250, 250, 250),luma(86.27%)), [ ```typst #show bibliography: set heading( offset: 1, ) #set bibliography(group: none) = First part Starts at one: @netwok @arrgh #bibliography( "works.bib", style: "ieee", ) = Second part Resets to one: @distress #bibliography( "works.bib", style: "nlm-citation-sequence", ) ``` ],[ #set align(horizon) #image("images/3004.png",width: auto)] ) == 项目符号列表(list)<list> 项目符号列表。 垂直显示一系列项目,每个项目由一个标记引入。 === 示例(Example) #table( columns: (1fr,1fr), align: (left,left), stroke: none, fill: (rgb(250, 250, 250),luma(86.27%)), [ ```typc Normal list. - Text - Math - Layout - ... Multiple lines. - This list item spans multiple lines because it is indented. Function call. #list( [Foundations], [Calculate], [Construct], [Data Loading], ) ``` ],[ #set align(horizon) #image("images/3005.png",width: auto)] ) === 语法(Syntax) 此函数还具有专用语法:用连字符开始一行,后跟空格以创建列表项。列表项可以包含多个段落和其他块级内容。所有缩进超过项目标记的内容都将成为该项目的一部分。 === 参数(Parameters) ```typc list( tight: bool, marker: content array function, indent: length, body-indent: length, spacing: auto length, marker-align: alignment, ..content, ) → content ``` - *tight*: bool<list_tight> 定义列表的默认间距。如果为#rtext()[false],则以段落间距分隔项目。如果是#rtext()[true],他们会使用段落引导。这使得列表更加紧凑,如果项目较短,看起来会更好。缺省值:#rtext()[true]。 在标记模式下,此参数的值取决于项目是否用空行分隔。如果项目直接相互跟随,则设置为true;如果项目之间用空行分隔,则设置为false。标记定义的紧密性不能用设定的规则覆盖。 #table( columns: (1fr,1fr), align: (left,left), stroke: none, fill: (rgb(250, 250, 250),luma(86.27%)), [ ```typst - If a list has a lot of text, and maybe other inline content, it should not be tight anymore. - To make a list wide, simply insert a blank line between the items. ``` ],[ #set align(horizon) #image("images/3006.png",width: auto)] ) - *marker*: content array function<list_marker> 导入每个项目的标记。缺省值:([•], [‣], [–])。 除了纯内容,您还可以传递一个包含多个标记的数组,这些标记应用于嵌套列表。如果列表嵌套深度超过标记数量,则标记将循环。为了实现完全控制,您可以传递一个函数,将列表的嵌套深度(从0开始)映射到所需的标记。 #table( columns: (1fr,1fr), align: (left,left), stroke: none, fill: (rgb(250, 250, 250),luma(86.27%)), [ ```typst #set list(marker: [--]) - A more classic list - With en-dashes #set list(marker: ([•], [--])) - Top-level - Nested - Items - Items ``` ],[ #set align(horizon) #image("images/3007.png",width: auto)] ) - *indent*:length<list_indent> 每个项目的缩进。缺省值:#rtext()[0pt]。 - *body-indent*:length<list_body-indent> 标记和每个项目主体之间的间距。缺省值:#rtext()[0.tem]。 - *spacing*: auto length<list_spacing> 列表中项目之间的间距。缺省值:#rtext()[auto]。 如果设置为自动,则对紧列表使用段落前导,对宽(非紧)列表使用段落间距。 - *marker-align*: alignment<list_marker-align> 用于列表标记的对齐方式。缺省值:end。 垂直对齐总是相对于它们所附加的列表项的高度。默认情况下,它是未指定的,这意味着每个标记将与它所附加的项目的基线垂直对齐(通常是它的第一行文本,否则是它的顶部)。 另一方面,水平对齐是相对于同一列表级别的其他标记的。默认情况下,它设置为end,这意味着标记朝向当前文本方向的末尾排列(LTR为右,RTL为左)。然而,由于每个级别的标记通常是相同的,因此预计水平对齐在大多数情况下没有实际效果。无论如何,在某些情况下,它仍然有可能产生影响,特别是如果标记使用计数器或其他形式的状态来显示每个项目的不同内容。 #table( columns: (1fr,1fr), align: (left,left), stroke: none, fill: (rgb(250, 250, 250),luma(86.27%)), [ ```typst - Baseline \ aligned #set list(marker-align: horizon) - Horizon \ aligned ``` ],[ #set align(horizon) #image("images/3008.png",width: auto)] ) - *children*: content 项目列表的子列表们。 使用列表语法时,即使通过for循环等构造,相邻项也会自动收集到列表中。 === 定义(Definition) - *item*<list_item> 项目列表。 ```typc list.item(body: content) → content ``` -- body: content 列表项。 == 引用(cite)<cite> 从参考书目中引用一部作品。 在开始引用之前,您需要在文档的某个地方添加一个#link(<bibliography>)[参考文献]。 === 示例(Example) #table( columns: (1fr,1fr), align: (left,left), stroke: none, fill: (rgb(250, 250, 250),luma(86.27%)), [ ```typst This was already noted by pirates long ago. @arrgh Multiple sources say ... @arrgh @netwok. You can also call `cite` explicitly. #cite(<arrgh>) #bibliography("works.bib") ``` ],[ #set align(horizon) #image("images/3009.png",width: auto)] ) 如果源名称包含斜杠等不被<>语法识别的特殊字符,您可以显式调用标签代替。 Computer Modern 是现代主义衬线体字体的一个典范。 引用标签(“DBLP:books/lib/Knuth86a”)。 === 语法(Syntax) 该函数间接地具有专用语法。可使用引用功能来标注参考文献中的作品。标签随后将与引用键对应。 === 参数(Parameters) ```typc cite( key:label, supplement: nonecontent, form: none str, style: auto str path bytes, ) → content ``` - *key*: label<cite_key> 用于标识文献引用条目的键值,作为引用标签。 #table( columns: (1fr,1fr), align: (left,left), stroke: none, fill: (rgb(250, 250, 250),luma(86.27%)), [ ```typst // All the same @netwok \ #cite(<netwok>) \ #cite(label("netwok")) ``` ],[ #set align(horizon) #image("images/3010.png",width: auto)] ) - *supplement*: none content<cite_supplement> 引文的补充,如页码或章节号。缺省值:#rtext()[none]。 在参考语法中,可以在方括号中添加补充: #table( columns: (1fr,1fr), align: (left,left), stroke: none, fill: (rgb(250, 250, 250),luma(86.27%)), [ ```typst This has been proven. @distress[p.~7] #bibliography("works.bib") ``` ],[ #set align(horizon) #image("images/3011.png",width: auto)] ) - *form*: none str<cite_form> 要制作的引文类型。不同的形式在不同的情况下是有用的:正常的引用在句末是有用的,而“散文”引用更适合包含在文本流中。缺省值:#rtext()[\"normal\"]。 如果设置为none,引用的作品将包含在参考书目中,但不会显示任何内容。 #table( columns: (0.5fr,2fr), align: left, stroke: none, table.header[*Variant*][*Details*], table.hline(), [\"normal\"],[Display in the standard way for the active style.], [\"prose\"],[Produces a citation that is suitable for inclusion in a sentence.], [\"full\"],[Mimics a bibliography entry, with full information about the cited work.], [\"author\"],[Shows only the cited work’s author(s).], [\"year\"],[Shows only the cited work’s year.], ) #table( columns: (1fr,1fr), align: (left,left), stroke: none, fill: (rgb(250, 250, 250),luma(86.27%)), [ ```typst #cite(<netwok>, form: "prose") show the outsized effects of pirate life on the human psyche. ``` ],[ #set align(horizon) #image("images/3012.png",width: auto)] ) - *style*: auto str path bytes<cite_style> 引用风格。缺省值:#rtext()[auto]。 这可以是: -- auto:自动使用参考书目的引用样式。 -- 具有内置样式之一名称的字符串(见下文)。下面列出的一些样式会出现两次,一次是全名,一次则是短别名。 -- CSL文件的路径字符串或路径。 -- 应从中解码CSL样式的原始字节。 选项列表: #table( columns: (1fr,1.5fr), align: left, stroke: none, table.header[*Variant*][*Details*], table.hline(), [\"alphanumeric\"],[Alphanumeric], [\"american-anthropological-association\"],[American Anthropological Association], [\"american-chemical-society\"],[ACS Guide 2022 revision], [\"american-geophysical-union\"],[American Geophysical Union], [\"american-institute-of-aeronautics-and-astronautics\"],[American Institute of Aeronautics and Astronautics], [\"american-institute-of-physics\"],[AIP Style Manual 4th edition], [\"american-medical-association\"],[AMA Manual of Style 11th edition], [\"american-meteorological-society\"],[American Meteorological Society], [\"american-physics-society\"],[American Physical Society], [\"american-physiological-society\"],[American Physiological Society], [\"american-political-science-association\"],[APSA Style Manual revised 2018 edition], [\"american-psychological-association\"],[APA Style 7th edition], [\"apa\"],[A short alias of american-psychological-association], [\"american-society-for-microbiology\"],[American Society for Microbiology], [\"american-society-of-civil-engineers\"],[American Society of Civil Engineers], [\"american-society-of-mechanical-engineers\"],[American Society of Mechanical Engineers], [\"american-sociological-association\"],[ASA Style Guide 6th/7th edition], [\"angewandte-chemie\"],[Angewandte Chemie International Edition], [\"annual-reviews\"],[Annual Reviews (sorted by order of appearance)], [\"annual-reviews-author-date\"],[Annual Reviews (author-date)], [\"associacao-brasileira-de-normas-tecnicas\"],[Associação Brasileira de Normas Técnicas (Português - Brasil)], [\"association-for-computing-machinery\"],[Association for Computing Machinery], [\"biomed-central\"],[BioMed Central], [\"bristol-university-press\"],[Bristol University Press], [\"british-medical-journal\"],[BMJ], [\"bmj\"],[A short alias of british-medical-journal], [\"cell\"],[Cell], [\"chicago-author-date\"],[Chicago Manual of Style 18th edition (author-date)], [\"chicago-notes\"],[Chicago Manual of Style 18th edition (notes and bibliography)], [\"chicago-fullnotes\"],[A short alias of chicago-notes], [\"chicago-shortened-notes\"],[Chicago Manual of Style 18th edition (shortened notes and bibliography)], [\"copernicus\"],[Copernicus Publications], [\"cse-citation-sequence-brackets-8th-edition\"],[CSE Manual: Scientific Style and Format 8th edition (citation-sequence, brackets)], [\"council-of-science-editors\"],[A short alias of cse-citation-sequence-brackets-8th-edition], [\"cse-name-year\"],[CSE Manual: Scientific Style and Format 9th edition (name-year)], [\"council-of-science-editors-author-date\"],[A short alias of cse-name-year], [\"current-opinion\"],[Current Opinion journals], [\"deutsche-gesellschaft-für-psychologie\"],[Deutsche Gesellschaft für Psychologie 5. Auflage (Deutsch)], [\"deutsche-sprache\"],[Deutsche Sprache (Deutsch)], [\"elsevier-harvard\"],[Elsevier (author-date/Harvard, with titles)], [\"elsevier-vancouver\"],[Elsevier - NLM/Vancouver (citation-sequence)], [\"elsevier-with-titles\"],[Elsevier (numeric, with titles)], [\"frontiers\"],[Frontiers journals], [\"future-medicine\"],[Future Medicine journals], [\"future-science\"],[Future Science Group], [\"gb-7714-2005-numeric\"],[China National Standard GB/T 7714-2005 (numeric, 中文)], [\"gb-7714-2015-author-date\"],[China National Standard GB/T 7714-2015 (author-date, 中文)], [\"gb-7714-2015-note\"],[China National Standard GB/T 7714-2015 (note, 中文)], [\"gb-7714-2015-numeric\"],[China National Standard GB/T 7714-2015 (numeric, 中文)], [\"gost-r-705-2008-numeric\"],[Russian GOST R 7.0.5-2008 (numeric)], [\"harvard-cite-them-right\"],[Cite Them Right 12th edition (author-date/Harvard)], [\"institute-of-electrical-and-electronics-engineers\"],[IEEE Reference Guide version 11.29.2023], [\"ieee\"],[A short alias of institute-of-electrical-and-electronics-engineers], [\"institute-of-physics-numeric\"],[Institute of Physics (numeric)], [\"iso-690-author-date\"],[ISO-690 (author-date, English)], [\"iso-690-numeric\"],[ISO-690 (numeric, English)], [\"karger\"],[Karger journals], [\"mary-ann-liebert-vancouver\"],[Mary Ann Liebert - NLM/Vancouver], [\"modern-humanities-research-association-notes\"],[MHRA Style Guide 4th edition (notes)], [\"modern-humanities-research-association\"],[A short alias of modern-humanities-research-association-notes], [\"modern-language-association\"],[MLA Handbook 9th edition (in-text citations)], [\"mla\"],[A short alias of modern-language-association], [\"modern-language-association-8\"],[A short alias of modern-language-association], [\"mla-8\"],[A short alias of modern-language-association], [\"multidisciplinary-digital-publishing-institute\"],[Multidisciplinary Digital Publishing Institute], [\"nature\"],[Nature], [\"nlm-citation-sequence\"],[NLM/Vancouver: Citing Medicine 2nd edition (citation-sequence)], [\"vancouver\"],[A short alias of nlm-citation-sequence], [\"nlm-citation-sequence-superscript\"],[NLM/Vancouver: Citing Medicine 2nd edition (citation-sequence, superscript)], [\"vancouver-superscript\"],[A short alias of nlm-citation-sequence-superscript], [\"pensoft\"],[Pensoft Journals], [\"public-library-of-science\"],[Public Library of Science], [\"plos\"],[A short alias of public-library-of-science], [\"royal-society-of-chemistry\"],[Royal Society of Chemistry], [\"sage-vancouver\"],[SAGE - NLM/Vancouver], [\"sist02\"],[SIST02 (日本語)], [\"spie\"],[SPIE journals], [\"springer-basic\"],[Springer - Basic (numeric, brackets)], [\"springer-basic-author-date\"],[Springer - Basic (author-date)], [\"springer-fachzeitschriften-medizin-psychologie\"],[Springer - Fachzeitschriften Medizin Psychologie (Deutsch)], [\"springer-humanities-author-date\"],[Springer - Humanities (author-date)], [\"springer-lecture-notes-in-computer-science\"],[Springer - Lecture Notes in Computer Science], [\"springer-mathphys\"],[Springer - MathPhys (numeric, brackets)], [\"springer-socpsych-author-date\"],[Springer - SocPsych (author-date)], [\"springer-vancouver\"],[Springer - NLM/Vancouver (citation-sequence, brackets)], [\"taylor-and-francis-chicago-author-date\"],[Taylor & Francis Journals Standard Reference Style Guide: Chicago author-date version 2.0], [\"taylor-and-francis-national-library-of-medicine\"],[Taylor & Francis - NLM/Vancouver (citation-sequence, brackets)], [\"the-institution-of-engineering-and-technology\"],[The Institution of Engineering and Technology], [\"the-lancet\"],[The Lancet], [\"thieme\"],[Thieme-German (Deutsch)], [\"trends\"],[Trends journals], [\"turabian-author-date\"],[Chicago Manual of Style 17th edition (author-date)], [\"turabian-fullnote-8\"],[Chicago Manual of Style 17th edition (notes and bibliography, subsequent author-title)], ) == 分割线(divider)<divider> 一个主题分隔符,用于将内容部分隔开。 默认情况下,它呈现为一条水平线,但可以通过显示规则进行自定义。 === 示例(Example) #table( columns: (1fr,1fr), align: (left,left), stroke: none, fill: (rgb(250, 250, 250),luma(86.27%)), [ ```typst She left without a word. #divider() Three days later, she returned. ``` ],[ #set align(horizon) #image("images/3013.png",width: auto)] ) === 样式(Styling)<divider_Styling> 可以通过展示规则来设置分隔符的样式。 由于默认情况下分隔符显示为一条线,你可以使用一组规则来调整这条线的描边: #table( columns: 1fr, align: left, stroke: none, fill: luma(86.27%), [ ```typst #show divider: set line(stroke: 2pt + red) First part #divider() Second part ``` ], [ #image("images/3014.png",width: auto) ] ) 你也可以用自定义内容(如花朵或星号)完全替换分隔符,但之后应将其包裹在一个块中以保留间距: #table( columns: (1fr,1fr), align: (left,left), stroke: none, fill: (rgb(250, 250, 250),luma(86.27%)), [ ```typst #show divider: set align(center) #show divider: block[∗ ∗ ∗] Chapter 1 #divider() Chapter 2 ``` ],[ #set align(horizon) #image("images/3015.png",width: auto)] ) === 参数(Parameters)<divider_Parameters> ```typc divider() → content ``` == 文档(document)<document> 管理元数据,并用于将文档文件添加到包中。 === 元数据(Metadata)<document_Metadata> 文档元素是文档元数据的唯一真实来源。通过它,你可以在一个地方指定文档的标题、作者、日期等信息。通常,该元素会与set规则一起使用: #table( columns: (1fr,1fr), align: (left,left), stroke: none, fill: (rgb(250, 250, 250),luma(86.27%)), [ ```typst #show divider: set align(center) #show divider: block[∗ ∗ ∗] #set document(title: [My doc]) Title is _not_ rendered, but embedded in PDF metadata. ``` ],[ #set align(horizon) #image("images/3016.png",width: auto)] ) 默认情况下,元数据会嵌入到输出中,但在文档中不会以可见形式呈现。然而,它会在整个文档中#link(<Context>)[上下文可用],并且可以被元素和模板使用。例如,内置的#link(<title>)[标题]元素会自动获取配置的文档标题: #table( columns: (1fr,1fr), align: (left,left), stroke: none, fill: (rgb(250, 250, 250),luma(86.27%)), [ ```typst #set document(title: [My doc]) #title() Title is now rendered _and_ embedded in PDF metadata. ``` ],[ #set align(horizon) #image("images/3017.png",width: auto)] ) 与title元素类似,您也可以使用#link(<Context>)[上下文表达式]自行访问元数据。 #table( columns: (1fr,1fr), align: (left,left), stroke: none, fill: (rgb(250, 250, 250),luma(86.27%)), [ ```typst // In the document. #set document( keywords: ("Typst", "Metadata") ) // Somewhere in your template. _Keywords:_ #context document.keywords.join(", ") ``` ],[ #set align(horizon) #image("images/3018.png",width: auto)] ) 在单文档导出格式中,此功能仅与#link(<Styling-set>)[set规则]一起使用。此类set规则必须仅出现在顶层,而不能出现在任何布局容器内部。您也可以显式创建一个文档元素,但这仅在#link(<document_bundle-export>)[包导出]中相关。 *特定格式的考虑因素* 元数据在不同程度上被嵌入到输出中: - PDF导出支持全部元数据,并将其纳入PDF文档信息字典以及XMP元数据中。 - HTML导出仅支持标题、描述、作者和关键词属性。由于HTML标准中未提供日期属性,因此不支持该属性。 - SVG和PNG导出格式完全不支持任何元数据。 === 包导出中的文档(Documents in bundle export)<document_bundle-export> 在包导出中,文档元素代表包输出中的一个单个文件,该文件采用Typst的其他导出格式之一。创建文档时,您必须提供输出路径和一些内容。Typst将编译并提供适当格式的内容。默认情况下,格式会根据您指定的路径的文件扩展名进行推断,但您也可以明确配置[格式]。 ```typst #document("index.html", title: [Home])[ #title() View #link(<list>)[my famous list]. ] #document("list.html", title: [My Famous List])[ #title() - My - Famous - List ] <list> ``` - 元数据(Metadata) 文档元素从顶层设置中的文档规则中提取元数据。这意味着,为单文档导出编写的文档可以在保留元数据的同时,与明确的文档元素一起使用。 ```typst // Will pick up the title defined in `paper.typ`. #document("paper.pdf", include "paper.typ") ``` #linebreak() ```typst // paper.typ #set document(title: [My Paper]) ... ``` 请注意,文档中的文档集规则会覆盖传递给文档元素的显式参数。 此外,配置为文档显式参数的属性在上下文中可用: ```typst #document("index.html", title: [My title])[ // Both of these will pick up `[My title]` #title() #context document.title ] ``` === 参数(Parameters)<document_Parameters> ```typc document( path:str, format: auto str, title: none content, author: str array, description: none content, keywords: str array, date: none auto datetime, body:content, ) → content ``` - *path*: str<document_path> 在包中用于放置导出文档的路径。 可能包含内部斜杠,在这种情况下,会自动创建中间目录。 此属性仅在bundle目标中受支持。 - *format*: auto str<document_format> 导出成哪种格式。缺省值:#rtext()[auto]。 如果是自动导出,Typst会尝试根据路径的文件扩展名来推断导出格式。 此属性仅在bundle目标中受支持。 #table( columns: (0.5fr,2fr), stroke: none, align: (left,left), table.header[Variant][Details], table.hline(), [\"pdf\"],[高保真文档和图形格式,注重在打印中的精确再现。], [\"png\"],[用于插图和透明图形的光栅格式。], [\"svg\"],[网页的矢量图形格式。], [\"html\"],[网页的文档格式。] ) - *title*: none content<document_title> 文档标题。缺省值:#rtext()[none]。 这会被呈现为PDF查看器窗口或页面浏览器标签的标题。 默认情况下,配置的标题在文档中不会以可见形式呈现。您可以使用title元素将标题添加到文档内容中。该元素会自动获取此处配置的标题。 添加标题对于可访问性至关重要,因为它有助于用户更轻松地导航到您的文档,并在其他打开的文档中轻松识别它。在导出为PDF/UA格式时,必须提供标题。 虽然这可以是任意内容,但PDF查看器仅支持纯文本标题,因此转换可能会造成信息丢失。 - author:str or array 该文档的作者。 - description:none or content 该文档的描述。 - keywords:str or array 文档的关键词。 - date:none or auto or datetime 该文档的创建日期。 如果设置为auto(默认),Typst将使用当前日期和时间。将其设置为无,则Typst不会将任何创建日期嵌入到PDF元数据中。 年份部分必须至少为零才能嵌入到PDF中。 如果您希望创建逐字节可复现的PDF文件,请将其设置为非auto模式。 - body:content 构成文档的内容。 此属性仅在bundle目标中受支持。 == 强调(emph)<Emphasis> 通过切换斜体来强调内容。 -- 如果当前#link(<text_style>)[文本样式]为```typc "normal"```,则将其更改为```typc "italic"```。 -- 如果它已经是```typc "italic"```或```typc "oblique"```,则将其恢复为```typc "normal"```。 === 示例(Example) #table( columns: (1fr,1fr), align: (left,left), stroke: none, fill: (rgb(250, 250, 250),luma(86.27%)), [ ```typst This is _emphasized._ \ This is #emph[too.] #show emph: it => { text(blue, it.body) } This is _emphasized_ differently. ``` ],[ #set align(horizon) #image("images/3019.png",width: auto)] ) === 语法(Syntax) 此函数也有专门的语法:要强调内容,只需将其用下划线(\_)括起来。请注意,这仅在单词边界处有效。要强调单词的一部分,则必须使用该函数。 === 参数(Parameters) ```typc emph(body:content) → content ``` == 图形(figure)<figure> 一个带有可选说明文字的图形。 自动检测其类型以选择正确的计数轨迹。例如,包含图像的图表将与包含表格的图表分开编号。 === 示例(Examples) #table( columns: (1fr,1fr), align: (left,left), stroke: none, fill: (rgb(250, 250, 250),luma(86.27%)), [ ```typst @glacier shows a glacier. Glaciers are complex systems. #figure( image("glacier.jpg", width: 80%), caption: [A curious figure.], ) <glacier> ``` ],[ #set align(horizon) #image("images/3020.png",width: auto)] ) 您还可以在图表中插入#link(<table>)[表格],并为它们添加标题。图表将检测到这一操作,并自动使用单独的计数器。 #table( columns: (1fr,1fr), align: (left,left), stroke: none, fill: (rgb(250, 250, 250),luma(86.27%)), [ ```typst #figure( table( columns: 4, [t], [1], [2], [3], [y], [0.3s], [0.4s], [0.8s], ), caption: [Timing results], ) ``` ],[ #set align(horizon) #image("images/3021.png",width: auto)] ) 通过明确指定图形的种类,可以覆盖此行为。所有同类图形共享一个公共计数器。 === 图形行为(Figure behaviour)<Figure_behaviour> 默认情况下,图表会置于内容流中。若要使其浮动到页面顶部或底部,可以使用#link(<Figure_placement>)[placement]参数。 如果您的图表过大,且其内容(如包含大表格)容易跨页,那么您可以通过以下show规则,使图表本身也能跨页: ```typst #show figure: set block(breakable: true) ``` 有关可破坏块和不可破坏块的更多信息,请参阅块文档。 === 标题自定义(Caption customization)<figure_Caption_customization> 你可以使用与图相关的#link(<title>)[标题]函数来修改图标题的外观。在下面的示例中,我们强调了所有标题: #table( columns: (1fr,1fr), align: (left,left), stroke: none, fill: (rgb(250, 250, 250),luma(86.27%)), [ ```typst #show figure.caption: emph #figure( rect[Hello], caption: [I am emphasized!], ) ``` ],[ #set align(horizon) #image("images/3022.png",width: auto)] ) 通过使用#link(<Function_where>)[where]选择器,我们可以将这些规则限定在特定类型的图表上。例如,要将表格上方的标题定位,但将其保持在所有其他类型图表下方,我们可以编写以下展示集规则: #table( columns: (1fr,1fr), align: (left,left), stroke: none, fill: (rgb(250, 250, 250),luma(86.27%)), [ ```typst #show figure.where( kind: table ): set figure.caption(position: top) #figure( table(columns: 2)[A][B][C][D], caption: [I'm up here], ) ``` ],[ #set align(horizon) #image("images/3023.png",width: auto)] ) === 无障碍(Accessibility)<Figure_Accessibility> 您可以使用#link(<figure_alt>)[alt]参数为屏幕阅读器和其他辅助技术(AT)提供图形的替代描述。请#link(<figure_alt>)[参阅其文档]以了解更多信息。 您可以使用图形为没有自身alt参数的路径、形状或可视化效果添加替代描述。如果您的图形纯属装饰性,且没有语义含义,请考虑将其封装在pdf.artifact中,这样在导出为PDF时,AT将无法识别它。 无论图表在文档中的位置如何,AT(自动表格识别)总是会读取它在文档中出现的那个#link(<Figure_placement>)[位置]的图表。请将它的标记放在阅读顺序中最合理的地方。 === 参数(Parameters)<Figure_Parameters> ```typc figure( body:content, alt: none str, placement: none auto alignment, scope: str, caption: none content, kind: auto str function, supplement: none auto content function, numbering: none str function, gap: length, outlined: bool, ) → content ``` - *body*: content<figure_body> 插图的内容。通常是一幅图像。 - *alt*: none str<figure_alt> 该图的一个替代描述。缺省值:#rtext()[none]。 当你添加一个备选描述时,AT会同时读取该描述和图注(如果有的话)。但是,图表本身的内容将被跳过。 当您的插图主体是一个已设置替代文本的图像时,不应在此插图元素上使用此参数。同样,当插图包含表格、代码或其他已可访问的内容时,也不应使用此参数。在这种情况下,AT会读取插图的内容,而添加替代描述会导致信息丢失。 你可以在《无障碍指南》中学习如何撰写优秀的替代描述。 - *placement*:none auto alignment<Figure_placement> 图形在页面上的位置。缺省值:#rtext()[none]。 -- none:该图形会像其他内容一样,精确地保持在指定的流入位置。 -- auto:该图形根据哪个更近来选择顶部或底部。 -- top: 该图形浮于页面顶部。 -- bottom: 该图形浮于页面底部。 主流程内容与浮动图形之间的间距是通过place函数中的#link(<place_clearance>)[clearance]参数来控制的。 #table( columns: (1fr,1fr), align: (left,left), stroke: none, fill: (rgb(250, 250, 250),luma(86.27%)), [ ```typst #set page(height: 200pt) #show figure: set place( clearance: 1em, ) = Introduction #figure( placement: bottom, caption: [A glacier], image("glacier.jpg", width: 60%), ) #lorem(60) ``` ],[ #set align(horizon) #image("images/3024.png",width: auto) #image("images/3025.png",width: auto)] ) - *scope*: str 相对于图形所在的包含范围。缺省值:```typc "column"```。 将其设置为```typc "parent"```可在两栏文档中创建全宽插图。 如果未进行放置,则无效果。 #table( columns: (0.5fr,2fr), stroke: none, align: (left,left), table.header[Variant][Details], table.hline(), [```typc "column"```],[放入当前列。], [```typc "parent"```],[相对于父元素放置,让内容跨过所有列。], ) #table( columns: (1fr,1fr), align: (left,left), stroke: none, fill: (rgb(250, 250, 250),luma(86.27%)), [ ```typst #set page(height: 250pt, columns: 2) = Introduction #figure( placement: bottom, scope: "parent", caption: [A glacier], image("glacier.jpg", width: 60%), ) #lorem(60) ``` ],[ #set align(horizon) #image("images/3026.png",width: auto) #image("images/3027.png",width: auto)] ) - *caption*: none content 图表的说明文字。缺省值:#rtext()[none]。 - *kind*: auto str function<figure_kind> 图形是什么类型。缺省值:#rtext()[auto]。 同类图形共享一个计数器。 如果设置为#rtext()[auto],该图形将尝试根据其主体的类型自动确定其类型。自动检测到的类型是#link(<table>)[表格]和#link(<raw>)[代码]。在其他情况下,推断出的类型是图像。 将其设置为非“自动”选项将覆盖自动检测。这在某些情况下可能很有用 -- 你想创建一个自定义图形类型,它既不是#link(<image>)[图像],也不是#link(<table>)[表格]或#link(<raw>)[代码], -- 你想强制图形使用特定的计数器,而不管其内容如何。 你可以将类型设置为元素函数或字符串。如果将其设置为除#link(<table>)[table]、#link(<raw>)[raw]或#link(<image>)[image]以外的元素函数,则需要手动指定图形的补充信息。 #table( columns: (1fr,1fr), align: (left,left), stroke: none, fill: (rgb(250, 250, 250),luma(86.27%)), [ ```typst #figure( circle(radius: 10pt), caption: [A curious atom.], kind: "atom", supplement: [Atom], ) ``` ],[ #set align(horizon) #image("images/3028.png",width: auto)] ) 如果你想修改计数器以跳过某个数字或重置计数器,可以使用where选择器访问每种图形的计数器: -- 对于表格:```typc counter(figure.where(kind: table))``` -- 对于图像:```typc counter(figure.where(kind: image))``` --对于自定义类型:```typc counter(figure.where(kind: kind))``` #table( columns: (1fr,1fr), align: (left,left), stroke: none, fill: (rgb(250, 250, 250),luma(86.27%)), [ ```typst #figure( table(columns: 2, $n$, $1$), caption: [The first table.], ) #counter( figure.where(kind: table) ).update(41) #figure( table(columns: 2, $n$, $42$), caption: [The 42nd table], ) #figure( rect[Image], caption: [Does not affect images], ) ``` ],[ #set align(horizon) #image("images/3029.png",width: auto)] ) 为了在show规则中方便地使用正确的计数器,您可以访问计数器字段。figure.caption元素的body#link(<figure_Definitions_caption>)[字段的文档中有一个相关示例]。 - *supplement*: none auto content function<figure_supplement> 该图形的补充。缺省值:#rtext()[auto]。 如果设置为自动,图表将尝试根据种类和活动文本语言自动确定正确的补充内容。如果您使用的是自定义图表类型,则需要手动指定补充内容。 如果指定了函数,则将指定种类的第一个后代(通常是图形的主体)传递给该函数,该函数应返回内容。 #table( columns: (1fr,1fr), align: (left,left), stroke: none, fill: (rgb(250, 250, 250),luma(86.27%)), [ ```typst #figure( [The contents of my figure!], caption: [My custom figure], supplement: [Bar], kind: "foo", ) ``` ],[ #set align(horizon) #image("images/3030.png",width: auto)] ) - *numbering*: none str function 如何为图表编号。接受一个编号模式或接受单个数字的函数。缺省值:```typc "1"```。 - *gap*: length 正文与标题之间的垂直间距。缺省值:#rtext()[0.68em]。 - *outlined*: bool 该图形是否应出现在图形目录中。缺省值:#rtext()[true]。 === 定义(Definitions)<figure_Definitions> - *caption*<figure_Definitions_caption> 图表的标题。此元素可用于设置和显示规则中,以自定义所有图表或特定类型图表的标题外观。 除了位置和主体外,标题还提供了图表的类型、补充信息、计数器和编号作为字段。这些部分可用于#link(<Function_where>)[where]选择器和显示规则,以构建一个完全自定义的标题。 #table( columns: (1fr,1fr), align: (left,left), stroke: none, fill: (rgb(250, 250, 250),luma(86.27%)), [ ```typst #show figure.caption: emph #figure( rect[Hello], caption: [A rectangle], ) ``` ],[ #set align(horizon) #image("images/3031.png",width: auto)] ) ```typst figure.caption( position: alignment, separator: auto content, body:content, ) → content ``` -- *position*: alignment 标题在图中的位置。可以是顶部或底部。 #table( columns: (1fr,1fr), align: (left,left), stroke: none, fill: (rgb(250, 250, 250),luma(86.27%)), [ ```typst #show figure.where( kind: table ): set figure.caption(position: top) #figure( table(columns: 2)[A][B], caption: [I'm up here], ) #figure( rect[Hi], caption: [I'm down here], ) #figure( table(columns: 2)[A][B], caption: figure.caption( position: bottom, [I'm down here too!] ) ) ``` ],[ #set align(horizon) #image("images/3032.png",width: auto)] ) -- *separator*: auto content 数字和正文之间将出现的分隔符。 如果设置为#rtext()[auto],分隔符将根据当前的#link(<text_lang>)[语言]和#link(<text_region>)[地区]进行调整。 #table( columns: 1, align: left, stroke: none, fill: rgb(250, 250, 250), [ ```typst #set figure.caption(separator: [ --- ]) #figure( rect[Hello], caption: [A rectangle], ) ``` ],[ #image("images/3033.png",width: auto)] ) -- *body*: content 标题的正文。 可与种类、补充、计数器、编号和位置一起使用,以完全自定义标题。 #table( columns: 1, align: left, stroke: none, fill: rgb(250, 250, 250), [ ```typst #show figure.caption: it => [ #underline(it.body) | #it.supplement #context it.counter.display(it.numbering) ] #figure( rect[Hello], caption: [A rectangle], ) ``` ],[ #image("images/3034.png",width: auto)] ) == 脚注(footnote)<footnote> 一个脚注。 在同一页上包含额外的备注和参考文献,并带有脚注。脚注会插入一个上标数字,该数字会链接到页面底部的备注。备注在整篇文档中按顺序编号,并可以跨页。 要自定义脚注列表中条目的外观,请参阅#link(<footnote_entry>)[footnote.entry]。脚注本身以普通上标的形式呈现,因此您可以在super函数上使用set规则来对其进行自定义。您还可以应用一个show规则,仅自定义正文中脚注标记(上标数字)。 === 示例(Example) #table( columns: (1fr,1fr), align: (left,left), stroke: none, fill: (rgb(250, 250, 250),luma(86.27%)), [ ```typst Check the docs for more details. #footnote[https://typst.app/docs] ``` ],[ #set align(horizon) #image("images/3035.png",width: auto)] ) 脚注会自动附加到前一个单词上,即使标记中它前面有空格。若要强制添加空格,可以使用字符串 ```typc #" "``` 或显式的#link(<spacing_h>)[水平间距]。 通过给脚注添加标签,你可以多次引用它。 #table( columns: (1fr,1fr), align: (left,left), stroke: none, fill: (rgb(250, 250, 250),luma(86.27%)), [ ```typst You can edit Typst documents online. #footnote[https://typst.app/app] <fn> Checkout Typst's website. @fn And the online app. #footnote(<fn>) ``` ],[ #set align(horizon) #image("images/3036.png",width: auto)] ) 注意:在调用脚注的范围内set和show规则可能不适用于脚注的内容。更多信息请见#link("https://github.com/typst/typst/issues/1467#issuecomment-1588799440")[此处]。 === 无障碍(Accessibility) 脚注将在文本中引用它们的位置之后立即通过辅助技术(AT)进行朗读,就像它们在标记中所呈现的那样。 === 参数(Parameters)<footnote_Parameters> ```typc footnote( numbering: str function, body:label content, ) → content ``` - *numbering*: str function<footnote_numbering> 如何为脚注编号。接受一个编号模式或接受单个数字的函数。缺省值:```typc "1"```。 默认情况下,脚注编号会在整个文档中连续。如果您更喜欢每页单独编号,可以在页眉中重置脚注计数器。将来可能会有更简单的方法来实现这一点。 #table( columns: (1fr,1fr), align: left, stroke: none, [ ```typc #set footnote(numbering: "*") Footnotes: #footnote[Star], #footnote[Dagger] ``` ], [ #set align(horizon) #image("images/3118.png",width: 100%) ] ) - *body*: label content 要放入脚注中的内容。也可以是本脚注需要指向的另一个脚注的标记。 === 定义(Definitions)<footnote_Definitions> - *entry*<footnote_entry> 脚注列表中的一条条目。 该函数不建议直接调用。它用于set和show规则中,实现脚注列表的自定义。 #table( columns: (1fr,1fr), align: (left,left), stroke: none, fill: (rgb(250, 250, 250),luma(86.27%)), [ ```typst #show footnote.entry: set text(red) My footnote listing #footnote[It's down here] has red text! ``` ],[ #set align(horizon) #image("images/3037.png",width: auto)] ) 注意:脚注条目的属性在每个页面序列(页面序列是指中间没有明确分页符的一系列页面)中必须保持一致。因此,应在任何页面内容之前,通常在文档的最开始,定义脚注条目的set和show规则。 ```typc footnote.entry( note:content, separator: content, clearance: length, gap: length, indent: length, ) → content ``` -- *note*: content 该条目的脚注。可通过其位置确定脚注计数器的状态。 #table( columns: 1, align: left, stroke: none, fill: rgb(250, 250, 250), [ ```typst #show footnote.entry: it => { let loc = it.note.location() counter(footnote).display(at: loc, "1: ") it.note.body } Customized #footnote[Hello] listing #footnote[World! 🌏] ``` ],[ #image("images/3038.png",width: auto)] ) -- *separator*: content 文档正文与脚注列表之间的分隔符。 #table( columns: (1fr,1fr), align: (left,left), stroke: none, fill: (rgb(250, 250, 250),luma(86.27%)), [ ```typst #set footnote.entry( separator: repeat[.] ) Testing a different separator. #footnote[ Unconventional, but maybe not that bad? ] ``` ],[ #set align(horizon) #image("images/3039.png",width: auto)] ) -- *clearance*: length 文档主体与分隔件之间的间隙量 #table( columns: (1fr,1fr), align: (left,left), stroke: none, fill: (rgb(250, 250, 250),luma(86.27%)), [ ```typst #set footnote.entry(clearance: 3em) Footnotes also need ... #footnote[ ... some space to breathe. ] ``` ],[ #set align(horizon) #image("images/3040.png",width: auto)] ) -- *gap*: length 脚注条目之间的间距。 #table( columns: (1fr,1fr), align: (left,left), stroke: none, fill: (rgb(250, 250, 250),luma(86.27%)), [ ```typst #set footnote.entry(gap: 0.8em) Footnotes: #footnote[Spaced], #footnote[Apart] ``` ],[ #set align(horizon) #image("images/3041.png",width: auto)] ) -- *indent*: length 每条脚注条目的缩进。 #table( columns: (1fr,1fr), align: (left,left), stroke: none, fill: (rgb(250, 250, 250),luma(86.27%)), [ ```typst #set footnote.entry(indent: 0em) Footnotes: #footnote[No], #footnote[Indent] ``` ],[ #set align(horizon) #image("images/3042.png",width: auto)] ) == 标题(heading)<heading> 一个章节标题。 使用标题,你可以将文档结构化为多个部分。每个标题都有一个级别,级别从1开始,并且级别没有上限。这个级别表示以下内容(节、小节等)的逻辑角色。顶级标题表示文档的顶级部分(不是文档的标题)。要插入标题,请使用#link(<title>)[title]元素。 Typst可以自动为您的标题编号。要启用编号功能,请指定您希望标题使用哪种#link(<numbering>)[编号模式或函数]进行编号。 Typst不仅能根据编号自动生成大纲,还能为您生成所有标题的目录。若要从此目录中排除一个或多个标题,您可以将outlined参数设置为false。 在编写一个#link(<Styling-show>)[show规则]以访问#link(<heading_Parameters>)[body类型]来为标题创建完全自定义的外观时,请确保将内容包裹在一个块中(通过内置的展示集规则,该块对标题具有隐式粘性)。这样可以防止标题变成“孤岛”,即标题留在页面末尾,而后续内容出现在下一页。 === 示例(Example) #table( columns: (1fr,1fr), align: (left,left), stroke: none, fill: (rgb(250, 250, 250),luma(86.27%)), [ ```typst #set heading(numbering: "1.a)") = Introduction In recent years, ... == Preliminaries To start, ... ``` ],[ #set align(horizon) #image("images/3043.png",width: auto)] ) === 语法(Syntax) 标题有专门的语法规则:可以通过在行首添加一个或多个等号,后跟一个空格来创建。等号的数量决定了标题的逻辑嵌套深度。可以设置偏移字段来配置起始深度。 === 无障碍(Accessibility) 标题对于可访问性至关重要,因为它们有助于使用辅助技术(AT)的用户(如屏幕阅读器)在文档中导航。屏幕阅读器用户可以跳过标题直接跳到下一个标题,或者获取文档中所有标题的概览。 为了使标题易于访问,您不应跳过标题级别。这意味着您应该从一级标题开始。此外,当前一个标题为三级时,下一个标题应为三级(保持相同深度)、四级(恰好深一级)或一级或二级(新的层次更高的标题)。 === HTML导出(HTML export) 如上所述,顶级标题表示文档的顶级部分,而非其标题。这与HTML中的\<h1\>元素形成对比,每个文档中\<h1\>元素应仅有一个。 因此,在HTML导出中,title元素将转换为\<h1\>,标题将转换为\<h2\>及更低层级(即一级标题转换为\<h2\>,二级标题转换为\<h3\>,以此类推)。 === 参数(Parameters)<heading_Parameters> ```typc heading( level: auto int, depth: int, offset: int, numbering: none str function, supplement: none auto content function, outlined: bool, bookmarked: auto bool, hanging-indent: auto length, body:content, ) → content ``` - *level*: auto int<heading_level> 标题的绝对嵌套深度,从1开始计数。如果设置为#rtext()[auto],则由偏移量+深度计算得出。缺省值:#rtext()[auto]。 这主要适用于在#link(<Styling-show>)[show规则]中使用(可通过 #link(<Function_where>)[where] 选择器使用,或直接在显示的标题上访问层级)。 #table( columns: 1, align: left, stroke: none, fill: rgb(250, 250, 250), [ ```typst #show heading.where(level: 2): set text(red) = Level 1 == Level 2 #set heading(offset: 1) = Also level 2 == Level 3 ``` ],[ #image("images/3044.png",width: auto)] ) - *depth*: int<heading_depth> 标题的相对嵌套深度,从1开始计数。该值会与偏移量结合,用于计算实际层级。缺省值:#rtext()[1]。 该参数由标题语法设定,例如 ```typc == Heading``` 会生成逻辑深度为2的标题,其实际层级为偏移量#rtext()[+2]。如果手动构建标题,通常建议使用该方式,而非直接设置绝对层级。 - offset:int 每个标题层级的起始偏移量,用于将其相对深度转换为绝对层级。缺省值:#rtext()[0]。 #table( columns: 1, align: left, stroke: none, fill: rgb(250, 250, 250), [ ```typst = Level 1 #set heading(offset: 1, numbering: "1.1") = Level 2 #heading(offset: 2, depth: 2)[ I'm level 4 ] ``` ],[ #image("images/3045.png",width: auto)] ) - *numbering*: none str function<heading_numbering> 如何为标题编号。可接收编号样式或可传入多个数字的函数。缺省值:#rtext()[none]。 #table( columns: (1fr,1fr), align: (left,left), stroke: none, fill: (rgb(250, 250, 250),luma(86.27%)), [ ```typst #set heading(numbering: "1.a.") = A section == A subsection === A sub-subsection ``` ],[ #set align(horizon) #image("images/3046.png",width: auto)] ) - *supplement*: none auto content function<heading_supplement> 标题的补充内容。缺省值:#rtext()[auto]。 在引用标题时,该内容会添加到引用编号之前。 如果指定了函数,该函数会接收被引用的标题,并应当返回内容。 #table( columns: 1, align: left, stroke: none, fill: rgb(250, 250, 250), [ ```typst #set heading(numbering: "1.", supplement: [Chapter]) = Introduction <intro> In @intro, we see how to turn Sections into Chapters. And in @intro[Part], it is done manually. ``` ],[ #image("images/3047.png",width: auto)] ) - *outlined*: bool<heading_outlined> 标题是否应显示在目录中。缺省值:#rtext()[true]。 请注意:如果将此属性设为true,可确保该标题在导出PDF时,同时作为书签显示在PDF的目录里。若要更改该效果,请使用bookmarked属性。 #table( columns: (1fr,1fr), align: (left,left), stroke: none, fill: (rgb(250, 250, 250),luma(86.27%)), [ ```typst #outline() #heading[Normal] This is a normal heading. #heading(outlined: false)[Hidden] This heading does not appear in the outline. ``` ],[ #set align(horizon) #image("images/3048.png",width: auto)] ) - *bookmarked*: auto bool<heading_bookmarked> 标题是否在导出PDF的目录中显示为书签。该设置不影响PNG等其他导出格式。缺省值:#rtext()[auto]。 默认值#rtext()[auto]表示:仅当标题的大纲属性设置为#rtext()[true](即该标题也会在Typst目录中列出)时,它才会出现在导出PDF的#link(<outline>)[目录]书签里。将此属性设置为#rtext()[true](添加书签)或#rtext()[false](不添加书签),将覆盖上述默认逻辑。 #table( columns: 1, align: left, stroke: none, fill: rgb(250, 250, 250), [ ```typst #heading[Normal heading] This heading will be shown in the PDF's bookmark outline. #heading(bookmarked: false)[Not bookmarked] This heading won't be bookmarked in the resulting PDF. ``` ],[ #image("images/3049.png",width: 80%)] ) - *hanging-indent*: auto length<heading_hanging-indent> 标题除首行外所有行应设置的缩进。缺省值:#rtext()[auto]。 自动的默认值规则:如果标题沿文本方向起始端对齐,则使用编号的宽度作为缩进;对于居中以及其他对齐方式,则不设置缩进。 #table( columns: 1, align: left, stroke: none, fill: rgb(250, 250, 250), [ ```typst #set heading(numbering: "1.") = A very, very, very, very, very, very long heading #show heading: set align(center) == A very long heading\ with center alignment ``` ],[ #image("images/3050.png",width: 80%)] ) - *body*: content 标题的内容。 == 链接(link)<link> 指向统一资源定位符(URL)或文档内位置的链接。 默认情况下,链接和普通文本在外观上没有区别。不过,你可以通过显示规则轻松应用自选样式。 === 示例(Example) #table( columns: (1fr,1fr), align: (left,left), stroke: none, fill: (rgb(250, 250, 250),luma(86.27%)), [ ```typst #show link: underline https://example.com \ #link("https://example.com") \ #link("https://example.com")[ See example.com ] ``` ],[ #set align(horizon) #image("images/3051.png",width: auto)] ) === 语法(Syntax) 该函数还有专用语法:以 http:// 或 https:// 开头的文本会自动转换为链接。 === 断字(Hyphenation) 如果启用断字或对齐功能,默认情况下,它不会应用于链接,以防止在网址中出现不必要的断字。您可以通过```typc show link: set text(hyphenate: true)```来选择退出此默认设置。 === 无障碍(Accessibility) 链接的目的地应能从链接文本本身,或至少能从其紧邻的文本中清晰看出。在PDF导出时,Typst会根据链接的目的地自动为链接生成一个工具提示描述。对于指向URL的链接,URL本身将用作工具提示。 === HTML导出中的链接(Links in HTML export) 在HTML导出中,指向#link(<label>)[标签]或#link(<location>)[位置]的链接将被转换为指向命名锚点的片段链接。为了支持这一点,没有现有ID的目标将在DOM中自动获得一个ID。具体实现方式因链接目标转换为哪种HTML节点而异: #set par(hanging-indent: 1.3cm) -- 如果链接目标变为一个单独的HTML元素,那么该元素将获得ID。例如,当链接到顶级标题时(该标题将变为一个单独的\<h2\>元素),通常就会出现这种情况。 -- 如果链接目标变为单个文本节点,该节点将被包裹在一个\<span\>中,该\<span\>随后将获得ID。 -- 如果链接目标变为多个节点,则第一个节点将接收ID。 -- 如果链接目标变为没有任何节点,则会生成一个空跨度作为链接目标。 #set par(hanging-indent: 0cm) 如果你依赖于特定的DOM结构,那么你应该确保链接目标会转化为一个或多个元素,因为编译器并不保证能将文本精确分割成文本节点。 如果存在,自动ID生成会尝试重用链接目标的标签来创建人类可读的ID。在以下情况下,标签可以被重用: -- 根据Unicode标准,所有字符均为字母、数字、连字符或下划线。 -- 标签不是以数字或连字符开头。 这些规则确保标签既是有效的CSS标识符,又是用于链接的有效URL片段。 由于在DOM中ID必须是唯一的,因此在将重复的标签作为ID重新使用时,可能需要对其进行消歧处理。具体规则如下: #set par(hanging-indent: 1.3cm) -- 如果一个标签可以重复使用并且在文档中是唯一的,那么它将被直接用作ID。 -- 如果它是可重复使用的,但不是唯一的,则会添加一个由连字符和整数组成的后缀。例如,如果标签\<mylabel\>出现了两次,它就会变成mylabel-1和mylabel-2。 -- 否则,将生成一个格式为“loc-”后跟一个整数的唯一ID。 #set par(hanging-indent: 0cm) === 包导出中的链接(Links in bundle export) 在包导出中,链接功能仍能正常使用。例如,如果你在一个文档中的某个元素上附加了一个标签,其他文档中的链接就可以引用该标签。此外,文档和资源也可以直接链接。要链接到完整的文档或资源,你可以为其附加一个标签,或者通过#link(<query>)[查询]找到并提取其#link(<location>)[位置]。 ```typst #document("index.html")[ // Link to document. #link(<appendix>)[To appendix] // Link into document. See the #link(<glossary>)[Glossary] for more information. ] #document("appendix.html")[ = Definitions ... = Glossary <glossary> ... ] <appendix> ``` 跨文档链接以相对路径(可能包含片段)的形式生成。Typst会根据与HTML导出相同的规则为每个文档自动分配锚点名称。在HTML和SVG文档中,这些锚点名称会作为元素的id属性生成。在PDF文档中,它们会作为命名目标生成。PNG文档不支持链接。 请注意,链接总是使用完整的相对路径。在某些场景下(主要是对于多页面网站),这可能并不理想。例如,您可能希望生成一个 /blog/index.html 文档,但只想用 /blog 作为链接。此外,您的网络服务器可能会将 /blog 和 /blog/ 视为可互换的,并为两者都提供 /blog/index.html。如果用户随后导航到 /blog,则 Typst 生成的其他页面的相对链接将不再有效。目前,Typst 无法直接挂接到内置的链接处理机制上。尽管如此,在 HTML 导出中,根据您的使用场景,可以通过在 html.elem.where(tag: "a") 上使用 show 规则来调整内置的链接处理。 === 参数(Parameters) ```typc link( dest:str label location dictionary, body:content, ) → content ``` - *dest*: str label location dictionary\ 链接指向的目的地。 - 要链接到网页,dest 应为有效的 URL 字符串。如果 URL 采用 mailto: 或 tel: 方案且省略了 body 参数,则电子邮件地址或电话号码将成为链接的正文,且不包含方案。 - 要链接到文档的其他部分,dest可以采用以下三种形式之一: - 附加到某个元素上的#link(<label>)[标签]。如果你还希望根据该元素为链接自动生成文本,可以考虑使用#link(<ref>)[引用]。 - 一个#link(<location>)[位置](通常从#link(<here>)[here]、#link(<locate>)[locate]或#link(<query>)[query]中检索得到)。 - 一个字典,其页面键为#link(<Integer>)[整数]类型,x和y坐标为长度类型。页面从1开始计数,坐标相对于页面的左上角。 #table( columns: (1fr,1fr), align: (left,left), stroke: none, fill: (rgb(250, 250, 250),luma(86.27%)), [ ```typst = Introduction <intro> #link("mailto:hello@typst.app") \ #link(<intro>)[Go to intro] \ #link((page: 1, x: 0pt, y: 0pt))[ Go to top ] ``` ],[ #set align(horizon) #image("images/3052.png",width: auto)] ) - *body*: content 应成为链接的内容。 如果dest是一个URL字符串,则可以省略该参数。在这种情况下,URL将作为链接显示。 == 编号列表(enum)<enum> 一个编号列表。 垂直展示一系列项目,并对其连续编号。 === 示例(Example) #table( columns: (1fr,1fr), align: (left,left), stroke: none, fill: (rgb(250, 250, 250),luma(86.27%)), [ ```typst Automatically numbered: + Preparations + Analysis + Conclusions Manually numbered: 2. What is the first step? 5. I am confused. + Moving on ... Multiple lines: + This enum item has multiple lines because the next line is indented. Function call. #enum[First][Second] ``` ],[ #set align(horizon) #image("images/3053.png",width: auto)] ) 借助一条set规则,你可以轻松将所有编号项目切换为另一种编号样式。 #table( columns: (1fr,1fr), align: (left,left), stroke: none, fill: (rgb(250, 250, 250),luma(86.27%)), [ ```typst #set enum(numbering: "a)") + Starting off ... + Don't forget step two ``` ],[ #set align(horizon) #image("images/3054.png",width: auto)] ) 你也可以使用#link(<enum_item>)[enum.item],通过编程方式自定义枚举中每个项的编号: #table( columns: (1fr,1fr), align: (left,left), stroke: none, fill: (rgb(250, 250, 250),luma(86.27%)), [ ```typst #enum( enum.item(1)[First step], enum.item(5)[Fifth step], enum.item(10)[Tenth step] ) ``` ],[ #set align(horizon) #image("images/3055.png",width: auto)] ) === 语法(Syntax) 该函数还有专门的语法: -- 行首使用加号,可创建自动编号的列表项。 -- 行首使用数字加句点,可创建显式编号的列表项。 列表项可包含多个段落以及其他块级内容。所有缩进程度大于列表项标记的内容,都属于该列表项的一部分。 === 参数(Parameters) ```typc enum( tight: bool, numbering: str function, start: auto int, full: bool, reversed: bool, indent: length, body-indent: length, spacing: auto length, number-align: alignment, children:content array, ) → content ``` - *tight*: bool 定义枚举列表的默认#link(<enum>)[间距]。若该值为#rtext()[false],列表项使用#link(<Paragraph_spacing>)[段落间距]分隔。若该值为#rtext()[true],则改用#link(<Paragraph_leading>)[段落行间距]。这会让列表更紧凑,当列表项内容较短时,视觉效果更佳。 在标记模式下,该参数的值由条目之间是否以空行分隔决定。如果条目直接相连,该值设为#rtext()[true];如果条目之间用空行分隔,该值设为#rtext()[false]。标记定义的紧凑性无法通过set规则覆盖。 #table( columns: (1fr,1fr), align: (left,left), stroke: none, fill: (rgb(250, 250, 250),luma(86.27%)), [ ```typst + If an enum has a lot of text, and maybe other inline content, it should not be tight anymore. + To make an enum wide, simply insert a blank line between the items. ``` ],[ #set align(horizon) #image("images/3056.png",width: auto)] ) - *numbering*: str function 如何对枚举项编号。可接收#link(<numbering>)[编号模式或函数]。缺省值:```typc "1"```。 若编号模式包含多个计数符号,它们将作用于嵌套枚举。如果传入函数,当full为#rtext()[false]时该函数接收一个参数;当full为#rtext()[true]时则接收多个参数。 #table( columns: (1fr,1fr), align: (left,left), stroke: none, fill: (rgb(250, 250, 250),luma(86.27%)), [ ```typst #set enum(numbering: "1.a)") + Different + Numbering + Nested + Items + Style #set enum(numbering: n => super[#n]) + Superscript + Numbering! ``` ],[ #set align(horizon) #image("images/3057.png",width: auto)] ) - *start*: auto int 列表项从哪个数字开始。缺省值:#rtext()[auto]。 #table( columns: (1fr,1fr), align: (left,left), stroke: none, fill: (rgb(250, 250, 250),luma(86.27%)), [ ```typst #enum( start: 3, [Skipping], [Ahead], ) ``` ],[ #set align(horizon) #image("images/3058.png",width: auto)] ) - *full*: bool 是否显示完整编号,包含所有上级枚举项的编号。缺省值:#rtext()[false]。 #table( columns: 1, align: left, stroke: none, fill: rgb(250, 250, 250), [ ```typst #set enum(numbering: "1.a)", full: true) + Cook + Heat water + Add ingredients + Eat ``` ],[ #image("images/3059.png",width: 80%)] ) - *reversed*: bool 是否要对该编号列表反向编号。缺省值:#rtext()[false]。 #table( columns: (1fr,1fr), align: (left,left), stroke: none, fill: (rgb(250, 250, 250),luma(86.27%)), [ ```typst #set enum(reversed: true) + Coffee + Tea + Milk ``` ],[ #set align(horizon) #image("images/3060.png",width: auto)] ) - *indent*: length 每个条目的缩进。缺省值:#rtext()[0pt]。 - *body-indent*: length 编号与每个条目正文之间的间距。缺省值:#rtext()[0.5em]。 - *spacing*: auto length 列表项之间的间距。缺省值:#rtext()[auto]。 若设置为#rtext()[auto],紧凑枚举将使用#link(<Paragraph_leading>)[段落行距],宽松(非紧凑)枚举使用#link(<Paragraph_spacing>)[段落间距]。 - *number-align*: alignment 列表编号应采用的对齐方式。缺省值:end。 默认情况下,该值设为 end,会将列表编号沿当前文本方向水平向末端对齐(例如,在从左到右的文字排版中,等同于右对齐)。此外,由于未设置垂直对齐,每个编号在垂直方向上刚好位于项目基线之上,如同属于该行文本的首行内容。 列表编号的水平对齐一般优先选择 end,因为这样编号会向远离文本的方向延伸,而非朝向文本。不过,你可以通过该选项更改这一默认行为。 至于垂直对齐方式,如果不需要基线对齐,可以对其进行覆盖。例如,采用末端+顶部的对齐方式会始终将标记垂直放置在项目靠近顶部的位置,而末端+底部则会将其移至靠近底部的位置。 另外需要注意,#link(<list>)[无序列表]有一个类似的选项,名为marker-align,它同样可以控制标记在两个轴向上的对齐,工作方式与列表数值完全相同。 #table( columns: 1, align: left, stroke: none, fill: rgb(250, 250, 250), [ ```typst #set enum(number-align: start + bottom) Here are some powers of two: 1. One 2. Two 4. Four 8. Eight 16. Sixteen 32. Thirty two ``` ],[ #image("images/3061.png",width: 80%)] ) - *children*: content array 编号列表的条目。 使用枚举语法时,相邻条目会自动归集为枚举项,即便在for循环这类结构中也是如此。 #table( columns: (1fr,1fr), align: (left,left), stroke: none, fill: (rgb(250, 250, 250),luma(86.27%)), [ ```typst #for phase in ( "Launch", "Orbit", "Descent", ) [+ #phase] ``` ],[ #set align(horizon) #image("images/3062.png",width: auto)] ) === 定义(Definitions) - item<enum_item> 列表项。 ```typc enum.item( number:auto int, body:content, ) → content ``` -- *number*: auto int 项编号。 -- *body*: content 项内容。 == 编号规则(numbering)<numbering> 对数字序列应用编号规则。 编号规则定义了数字序列该如何作为内容展示。它可以通过模式字符串或者自定义函数来定义。 编号模式由计数符号(会替换为实际数字)、计数符号的前缀以及一个后缀组成。前缀和后缀将按原样显示。 === 示例(Example) #table( columns: (1fr,1fr), align: (left,left), stroke: none, fill: (rgb(250, 250, 250),luma(86.27%)), [ ```typst #numbering("1.1)", 1, 2, 3) \ #numbering("1.a.i", 1, 2) \ #numbering("I – 1", 12, 2) \ #numbering( (..nums) => nums .pos() .map(str) .join(".") + ")", 1, 2, 3, ) ``` ],[ #set align(horizon) #image("images/3063.png",width: auto)] ) === 编号模式与编号函数(Numbering patterns and numbering functions) 在Typst中,有多处地方可以设置编号样式或编号函数。例如,定义#link(<heading>)[标题]或#link(<figure>)[图表]的编号规则时。无论哪种场景,所要求的格式都与下文针对#link(<numbering_numbering>)[编号参数]所描述的格式一致。 下面这个示例说明:编号函数只是一个普通函数,接收数字并返回内容。 #table( columns: (1fr,1fr), align: (left,left), stroke: none, fill: (rgb(250, 250, 250),luma(86.27%)), [ ```typst #let unary(.., last) = "|" * last #set heading(numbering: unary) = First heading = Second heading = Third heading ``` ],[ #set align(horizon) #image("images/3064.png",width: auto)] ) === 参数(Parameters) ```typc numbering( numbering:str function, numbers:int, ) → any ``` - *numbering*: str function<numbering_numbering> 定义编号的工作方式。 计数符号包括1、a、A、i、I、α、Α、一、壹、あ、い、ア、イ、א、가、ㄱ、\*、١、۱、१、১、ক、①和⓵。它们被替换为序列中的数字,同时保留原始大小写。 \*符号表示应使用符号进行计数,顺序为\*、†、‡、§、¶、‖。如果项目超过六个,则使用重复符号表示数字。 后缀是最后一个计数符号之后的所有字符。它们会原样显示在任意渲染数字的末尾。 前缀指所有既非计数符号、也非后缀的字符。它们会原样显示在对应计数符号渲染结果的前方。 该参数也可以是一个任意函数,它将每个数字作为独立参数传入。当传入一个函数时,编号函数仅会把参数转发给该函数。虽然这一点本身并没有太大用处,但这意味着你可以直接向编号函数传入任意编号形式,而无需关心这些编号是定义为模式还是函数。 - *numbers*: int 需要进行编号的数字,必须为非负数。 一般来说,数字从1开始计数。数字0代表首个元素尚未出现。 如果编号采用模式形式,且给出的数字数量多于计数符号,则重复使用带有前缀的最后一个计数符号。 == 目录(outline)<outline> 内容、图表或其他元素的列表。 该功能会生成文档内某类元素所有实例的列表,最大层级可自定义。在目录中,这类元素的编号与页码会连同其标题或图注一同显示。 === 示例(Example) #table( columns: (1fr,1fr), align: (left,left), stroke: none, fill: (rgb(250, 250, 250),luma(86.27%)), [ ```typst #set heading(numbering: "1.") #outline() = Introduction #lorem(5) = Methods == Setup #lorem(10) ``` ],[ #set align(horizon) #image("images/3065.png",width: auto)] ) === 替代目录(Alternative outlines)<Alternative_outlines> 在默认配置下,该函数会生成目录。通过设置目标参数,可使用该目录生成标题以外其他类型元素的列表。 在下面的示例中,我们将目标设置为```typc figure.where(kind: image)```,以此列出所有包含图片的图。同理,我们也可以将其设置为 ```typc figure.where(kind: table)``` 来生成表格列表。 我们也可以直接将其设置为 figure,不使用 #link(<Function_where>)[where] 选择器,但这样列表会包含所有图,无论是包含图片、表格还是其他内容的图。 #table( columns: (1fr,1fr), align: (left,left), stroke: none, fill: (rgb(250, 250, 250),luma(86.27%)), [ ```typst #outline( title: [List of Figures], target: figure.where(kind: image), ) #figure( image("tiger.jpg"), caption: [A nice figure!], ) ``` ],[ #set align(horizon) #image("images/3066.png",width: auto)] ) === 排版目录(Styling the outline)<Styling_the_outline> 在最基础的层面,你可以通过设置目录及其条目的属性来设置目录样式。通过这种方式,你可以自定义目录#link(<outline_title>)[标题]、目录条目的#link(<outline_indent>)[缩进]方式,以及条目文本与其页码之间空白的填充形式。 通过配置目录#link(<outline_entry>)[条目],还可以实现更丰富的自定义效果。目录会为每一个被标记进目录的元素生成一个条目。 - 条目间距调整 目录条目属于#link(<block>)[块元素],因此你可以使用常规的块间距规则调整它们之间的间距: #table( columns: (1fr,1fr), align: (left,left), stroke: none, fill: (rgb(250, 250, 250),luma(86.27%)), [ ```typst #show outline.entry.where( level: 1 ): set block(above: 1.2em) #outline() = About ACME Corp. == History === Origins = Products == ACME Tools ``` ],[ #set align(horizon) #image("images/3067.png",width: auto)] ) - *由各组成部分构建目录条目(Building an outline entry from its parts)* 如需完全自主控制,你也可以为 outline.entry 编写转换show规则。不过,对目录条目进行正确格式化与缩进的逻辑相当复杂,且目录条目本身仅包含两个字段:层级与被目录标记的元素。 为此,系统提供了各类辅助函数。你可以自由组合这些函数,仅选取所需部分来构建条目。 目录条目的默认显示规则如下#footnote[方程目录是该规则的例外情况,因为它没有主体部分,因此不使用缩进布局。]: ```typst #show outline.entry: it => link( it.element.location(), it.indented(it.prefix(), it.inner()), ) ``` -- 缩进函数可选地接收前缀和内部内容,并自动为其应用适当的缩进,使不同条目对齐整齐,长标题正确换行。 -- 前缀函数用于格式化元素的编号(如果存在)。它还会为某些元素附加补充内容。 -- 内部函数将元素的主体、填充符和页码组合在一起。 您可以使用这些独立功能以不同方式格式化目录条目。例如,如果您想完全删除占位符和页码,可以编写如下显示规则来实现这一点: #table( columns: 1, align: left, stroke: none, fill: rgb(250, 250, 250), [ ```typst #show outline.entry: it => link( it.element.location(), // Keep just the body, dropping // the fill and the page. it.indented(it.prefix(), it.body()), ) #outline() = About ACME Corp. == History ``` ],[ #image("images/3068.png",width: 80%)] ) === 参数(Parameters) ```typc outline( title: none auto content, target: label selector location function, depth: none int, indent: auto relative function, ) → content ``` - *title*: none auto content<outline_title> 目录的标题。缺省值:#rtext()[auto]。 -- 设置为自动时,将使用适配文本语言的标题。 -- 设置为无时,大纲不会显示标题。 -- 可通过传入内容来设置自定义标题。 目录标题默认不会编号,但你可以通过show-set规则强制开启编号:```typc show outline: set heading(numbering: "1.")``` - *target*:label selector location function<outline_target> 要包含在大纲中的元素类型。缺省值:heading。 若要列出包含特定类型元素(例如图片或表格)的图,可以在#link(<Function_where>)[where选择器]中指定所需元素类型。更多详情请参阅#link(<Alternative_outlines>)[替代目录]相关章节。 #table( columns: (1fr,1fr), align: (left,left), stroke: none, fill: (rgb(250, 250, 250),luma(86.27%)), [ ```typst #outline( title: [List of Tables], target: figure.where(kind: table), ) #figure( table( columns: 4, [t], [1], [2], [3], [y], [0.3], [0.7], [0.5], ), caption: [Experiment results], ) ``` ],[ #set align(horizon) #image("images/3069.png",width: auto)] ) - *depth*: none int<outline_depth> 目录中包含元素的最高层级。当该参数为#rtext()[none]时,将包含所有元素。缺省值:#rtext()[none]。 #table( columns: (1fr,1fr), align: (left,left), stroke: none, fill: (rgb(250, 250, 250),luma(86.27%)), [ ```typst #set heading(numbering: "1.") #outline(depth: 2) = Yes Top-level section. == Still Subsection. === Nope Not included. ``` ],[ #set align(horizon) #image("images/3070.png",width: auto)] ) - *indent*:auto relative function<outline_indent> 如何为目录条目设置缩进。缺省值:#rtext()[auto]。 #set par(hanging-indent: 1.3cm) -- #rtext()[auto]:嵌套条目的编号/前缀会跟随其父条目的标题进行缩进。如果条目没有编号(例如通过#link(<heading_numbering>)[标题编号]功能设置),则会在每一级直接固定增加#rtext()[1.2em]的缩进量。 -- #rtext()[Relative length]:按指定长度为每一层嵌套级别设置条目缩进。例如设置为#rtext()[2em]时,一级标题缩进#rtext()[0em](无嵌套),二级标题缩进#rtext()[2em](嵌套1层),三级标题缩进#rtext()[4em](嵌套2层),以此类推。 -- #rtext()[Function]:你可以使用函数对该设置进行更多自定义。该函数接收嵌套层级作为参数(一级标题/元素从0开始计数),并需要返回一个(相对)长度值。例如,```typc n => n * 2em``` 的效果等同于直接设置#rtext()[2em]。 #set par(hanging-indent: 0cm) #table( columns: (1fr,1fr), align: (left,left), stroke: none, fill: (rgb(250, 250, 250),luma(86.27%)), [ ```typst #set heading(numbering: "I-I.") #set outline(title: none) #outline() #line(length: 100%) #outline(indent: 3em) = Software engineering technologies == Requirements == Tools and technologies === Code editors == Analyzing alternatives = Designing software components = Testing and integration ``` ],[ #set align(horizon) #image("images/3071.png",width: auto)] ) === 定义(Definitions) - *entry*<outline_entry> 表示目录中的一行条目。 借助目录条目的显示集与显示规则,你可以对目录外观进行丰富的自定义。有关详情,请参阅#link(<Styling_the_outline>)[目录样式设置章节]。 ```typc outline.entry( level:int, element:content, fill: none content, ) → content ``` #set par(hanging-indent: 1.3cm) -- *level*: int\ 该目录条目的嵌套层级。顶级条目从1开始。 -- *element*: content\ 该条目所指向的元素。可通过内容上的#link(<Context_Location>)[定位方法]获取其位置,并可建立#link(<link>)[链接]。 -- *fill*: none content\ 用于填充标题与页码之间空白区域的内容。可设置为none以关闭填充效果。 填充内容会放置在一个自适应尺寸的容器内,该容器占据条目正文与页码之间的全部空间。当使用显示规则修改目录条目时,建议将填充内容置于自适应宽度容器中,即 box(width: 1fr, it.fill)。 使用repeat时,可借助间距属性调整填充内容的视觉占比。 #set par(hanging-indent: 0cm) #table( columns: 1, align: left, stroke: none, fill: rgb(250, 250, 250), [ ```typst #set outline.entry(fill: line(length: 100%)) #outline() = A New Beginning ``` ],[ #image("images/3072.png",width: 80%)] ) *基于entry的定义* #set par(hanging-indent: 1.3cm) -- indented\ 用于生成带缩进条目布局的辅助函数:以适配缩进的方式布置前缀与条目其余内容。\ 如果父级目录的#link(<outline_indent>)[缩进]设为#rtext()[auto],则所有N级条目的内部内容将与N+1级条目的前缀对齐,同时在前缀和内部内容之间保留至少一段间隔。此外,同一层级所有条目的内部内容保持对齐。\ 如果目录的缩进为固定值或函数,则前缀会进行缩进,但内部内容仅按照指定间隔相对前缀偏移,不会在整个大纲范围内对齐。可视化说明请参见#link(<outline_indent>)[outline.indent]。 ```typc self.indented( prefix:none content, inner:content, gap: length, ) → content ``` -- *prefix*(上下文) 设置元素的编号格式(如有编号)。 如果是图表或公式,这一操作还会追加元素的补充标识。例如,标题会输出1.1,而图表则输出图1,这也是目录中的常规写法。 ```typc self.prefix() → none content ``` -- *inner*(上下文) 创建条目的默认内部内容。 其中包含正文、填充内容以及页码。 ```typc self.inner() → content ``` -- *body* 在目录条目中替代被引用元素所显示的内容。对于标题,该内容为[标题正文];对于图片,该内容为图注;对于公式,则为空。 ```typc self.body() → content ``` -- *page* 该条目元素的页码,按照引用页面设定的编号格式显示。 ```typc self.page() → content ``` #set par(hanging-indent: 0cm) == 段落(par)<Paragraph> 文本内容的逻辑细分单元。 Typst 会自动将行内元素归集到段落中。行内元素包含#link(<text>)[文本]、#link(<spacing_h>)[水平间距]、#link(<box>)[盒子]以及#link(<equation>)[行内公式]。 如需分隔段落,请使用空行(或者显式段落分隔符 #link(<parbreak>)[parbreak])。任何块级元素(例如 #link(<block>)[block]、#link(<place>)[place],或是所有表现为块级的元素)也会自动截断当前段落。 par元素主要用于set规则中设置段落属性,也可用于将其参数显式单独展示为一个段落。此时,该段落的主体不能包含任何块级内容。 === 盒子与块(Boxes and blocks)<Paragraph_Boxes_and_blocks> 如上所述,段落通常仅包含行内级内容。不过,你可以将任意类型的块级内容放置在一个#link(<box>)[盒子容器]内,以此嵌入到段落中。 与之相反,你可以把行内级内容放置在一个#link(<block>)[块容器]内,使其从段落中分离。这种情况下,该内容将完全不属于任何段落。请阅读下一节,了解该操作的意义,以及它和直接在内容前后添加段落分隔符有何区别。 === 什么构成一个段落?(What becomes a paragraph?)<Paragraph_What-becomes-a-paragraph> 当你向文档中添加行内内容时,Typst 会自动将其包裹在段落中。不过,一份常规文档里也会存在一些在语义上不属于段落的文本,例如标题或图注中的文字。 Typst 将内联级内容包裹在段落中的规则如下: - 文档根部的所有文本都会被包裹在段落中。 - 容器(如块级元素)中的文本仅在容器包含任何块级内容时才会被包裹在段落中。如果所有内容均为内联级,则不会创建段落。 在排版完成的文档中,无法一眼看出文本是否已经属于某个段落。但区分这一点依然十分重要,原因有多种: - 首行缩进这类段落样式,仅能作用于规范段落,而不会应用到任意文本。与之类似,段落显示规则当然也只在段落上生效。 - 清晰区分段落与其他文本,能够帮助使用辅助技术(AT)(例如屏幕阅读器)的用户正常浏览和理解文档。 - 导出PDF时,仅会为段落生成P标签。 - 导出HTML时,仅会为段落生成 \<p\> 标签。 在创建自定义可复用组件时,你可以且应当控制 Typst 是否生成段落。将文本包裹在#link(<block>)[块]内,而非仅在文本两侧添加段落分隔符,就能强制不生成段落。与之相反,在容器内的某些内容后添加#link(<parbreak>)[段落分隔符],即便内容只有一个单词,也可强制将其转为段落。例如,#link(<list_tight>)[非紧凑]列表就是通过这种方式,强制列表项成为段落。 === 示例(Example) #table( columns: (1fr,1fr), align: (left,left), stroke: none, fill: (rgb(250, 250, 250),luma(86.27%)), [ ```typst #set par( first-line-indent: 1em, spacing: 0.65em, justify: true, ) We proceed by contradiction. Suppose that there exists a set of positive integers $a$, $b$, and $c$ that satisfies the equation $a^n + b^n = c^n$ for some integer value of $n > 2$. Without loss of generality, let $a$ be the smallest of the three integers. Then, we ... ``` ],[ #set align(horizon) #image("images/3073.png",width: auto)] ) === 参数(Parameters) ```typc par( leading: length, spacing: length, justify: bool, justification-limits: dictionary, linebreaks: auto str, first-line-indent: length dictionary, hanging-indent: length, body: content, ) → content ``` - *leading*: length<Paragraph_leading> 行间距。默认值:#rtext()[0.65em]。 行距(Leading)定义的是一行文字的#link(<text_bottom-edge>)[下边缘]与下一行文字的#link(<text_top-edge>)[上边缘]之间的距离。默认情况下,这两项属性由字体决定,但也可以通过文本设置规则手动配置。 通过设置上边缘、下边缘和行距,你还可以设定统一的基线到基线的距离。例如,你可以将行距设为#rtext()[1em],上边缘设为#rtext()[0.8em],下边缘设为#rtext()[-0.2em],从而得到恰好#rtext()[2em]的基线间距。上边缘和下边缘数值的具体分配会影响首行和末行的边界范围。 #table( columns: 1fr, align: center, stroke: none, fill: rgb(250, 250, 250), image("images/3074.png",width: 95%) ) - *spacing*: length<Paragraph_spacing> 段落间距。默认值:#rtext()[1.2em]。 和行间距一样,该属性用于定义一个段落最后一行的底边与下一个段落第一行的顶边之间的距离。间距同时作用于段落的上方和下方,相邻段落的间距会合并,取两者中较大的值。 当段落与一个块元素相邻时,该块元素的上边距或下边距属性优先级高于段落间距。例如,标题默认会减小其下方的间距,以获得更好的视觉效果。 - *justify*: bool<Paragraph_justify> 是否对文本行进行两端对齐。默认值:#rtext()[false]。 如果文本功能的连字符属性设置为“自动”且当前语言已知,两端对齐的段落将启用连字符。 请注意,当前的对齐方式仍会影响最后一行的位置,除非该行以两端对齐的换行符结束。 默认情况下,Typst 仅通过调整单词之间的间距来实现对齐。不过,您也可以使用#link(<Paragraph_justification_limits>)[“对齐限制”]属性允许其调整单个字符之间的间距。 - *justification-limits*: dictionary<Paragraph_justification_limits> 两端对齐时,单词与字符间的间距可调整的幅度。 默认值:```typc ( spacing: (min: 66.67% + 0pt, max: 150% + 0pt), tracking: (min: 0pt, max: 0pt), )``` 在对文本进行两端对齐时,Typst 需要将一行文字拉伸或收缩至版心的完整宽度。为实现该效果,默认情况下它会调整单词之间的间距。此外,它也可以调整单个字符之间的间距。该属性可用于设置这些间距调整的下限与上限。 该属性接收一个包含两项的字典:spacing(词间距)和 tracking(字间距),每项又都是带有 min 和 max 键的字典。min 键规定间距可收缩到的最小值,max 键规定间距可拉伸到的最大值。 #set par(hanging-indent: 1.3cm) -- 间距设置定义了单词之间空格宽度可调整的范围。它与#link(<text_spacing>)[文本间距]密切相关,其最小值和最大值键接受#link(<relative>)[相对长度],就像间距属性一样。\ 最小值为#rtext()[100%]意味着空格应保持正常大小(即不缩小),而#rtext()[90% - 0.01em]的值则表示空格可缩小到其正常宽度的90%减去当前字体大小的0.01倍。同样,最大值为#rtext()[100% + 0.02em]意味着空格宽度可增加当前字体大小的0.02倍。比例部分必须始终为正数。同时,最小值的长度部分不得为正数,最大值的长度部分不得为负数。\ 请注意,如果无法通过其他方式对齐行,空格仍可能扩展到超出最大值。然而,其他对齐方式(例如,若已配置跟踪条目,则字符间距)会首先被最大限度地使用。 -- 字间距设置项定义了字母间距可调整的幅度。它与文本的字间距(#link(<text_tracking>)[text.tracking])密切相关,其最小值(min)和最大值(max)键接受#link(<length>)[长度值],这一点与字间距属性类似。与普通间距不同,它不接受相对长度值,因为相对长度的基准会因每个字符而异,这会导致视觉效果不均匀。与普通间距相比,其行为相当于基准为#rtext()[100%]。\ 否则,最小值和最大值的作用方式与普通间距相同。最大值为#rtext()[0.01em]意味着可以在每对字符之间插入额外的间距,该间距量为当前字体大小的0.01倍。请注意,这也包括空格与字符之间的间隙,因此对于空格,字间距设置值会在普通间距设置值的基础上额外生效。 #set par(hanging-indent: 0cm) 如果仅指定间距或字距追踪中的一个,另一个将保留其先前设置的值(若未先前设置则使用默认值)。若要启用字符级对齐,min和max键的良好取值范围约为0.01em至0.02em(min为负值)。 为两个键使用相同值可获得良好基准,但单独调整两个值可能产生更均衡的效果,如下例所示。注意不要将范围设置得太宽,否则会很快显得不自然。 字符级对齐是一种具有影响力的微排版技术,可改善对齐文本的外观,尤其适用于窄列。但请注意,字符级对齐并非适用于所有字体或语言。例如,连笔字体的字母会相互连接,使用字符级对齐会导致连接处出现锯齿状。 #table( columns: 1fr, align: left, stroke: none, [ ```typst #let example(name) = columns(2, gutter: 10pt)[ #place(top, float: true, scope: "parent", strong(name)) /* Text from https://en.wikipedia.org/wiki/Anne_Bayley */ ] #set page(width: 440pt, height: 21em, margin: 15pt) #set par(justify: true) #set text(size: 0.8em) #grid( columns: (1fr, 1fr), gutter: 20pt, { // These are Typst's default limits. set par(justification-limits: ( spacing: (min: 100% * 2 / 3, max: 150%), tracking: (min: 0em, max: 0em), )) example[Word-level justification] }, { // These are our custom character-level limits. set par(justification-limits: ( tracking: (min: -0.01em, max: 0.02em), )) example[Character-level justification] }, ) ``` ], [ #rect( fill: luma(240), width: 100%, height: auto, image("images/3075.png",width: 100%) ) ] ) - *linebreaks*: auto str<Paragraph_linebreaks> 如何确定换行。默认值:#rtext()[auto]。 当此属性设置为默认值#rtext()[auto]时,会对对齐段落使用优化的换行。为改善文本外观,对非对齐段落启用优化换行也可能很有价值。 #table( columns: (0.5fr,2fr), stroke: none, align: (left,left), table.header[Variant][Details], table.hline(), [\"simple\"],[以简单的一次适应方式确定换行符。 优化整个段落的换行。], [\"optimized\"],[Typst 在计算换行时会考虑整个段落,以生成填充更均匀的文本行。] ) #table( columns: (1fr,1fr), align: (left,left), stroke: none, fill: (rgb(250, 250, 250),luma(86.27%)), [ ```typst #set page(width: 207pt) #set par(linebreaks: "simple") Some texts feature many longer words. Those are often exceedingly challenging to break in a visually pleasing way. #set par(linebreaks: "optimized") Some texts feature many longer words. Those are often exceedingly challenging to break in a visually pleasing way. ``` ],[ #set align(horizon) #image("images/3076.png",width: auto)] ) - *first-line-indent*: length dictionary<Paragraph_first-line-indent> 段落首行应当设置的缩进。默认值:```typc (amount:0pt,all:false)```。 默认情况下,只有连续段落的首行会缩进(文档或容器中的第一段不缩进,紧跟在其他块级元素后的段落也不缩进)。 如果你希望所有段落都缩进,可以传入一个字典,其中包含缩进长度,同时设置```typc all: true```。如果字典中省略 all 参数,则默认为 #rtext()[false]。 按照排版规范,段落分隔可以采用段间留白,或是首行缩进的方式。请注意 -- 通过```typc set par(spacing: 0.65em)``` 将#link(<Paragraph_spacing>)[段落间距]缩减为#link(<Paragraph_leading>)[行间距] --通过```typc set block(spacing: 1.2em)``` 将#link(<block_spacing>)[块间距](默认继承段落间距)增大至原始段落间距 #table( columns: (1fr,1fr), align: (left,left), stroke: none, fill: (rgb(250, 250, 250),luma(86.27%)), [ ```typst #set block(spacing: 1.2em) #set par( first-line-indent: 1.5em, spacing: 0.65em, ) The first paragraph is not affected by the indent. But the second paragraph is. #line(length: 100%) #set par(first-line-indent: ( amount: 1.5em, all: true, )) Now all paragraphs are affected by the first line indent. Even the first one. ``` ],[ #set align(horizon) #image("images/3077.png",width: auto)] ) - *hanging-indent*: length<Paragraph_hanging-indent> 段落中除首行外其余各行应设置的缩进。默认值:#rtext()[0pt]。 #table( columns: (1fr,1fr), align: (left,left), stroke: none, fill: (rgb(250, 250, 250),luma(86.27%)), [ ```typst #set par(hanging-indent: 1em) #lorem(15) ``` ],[ #set align(horizon) #image("images/3078.png",width: auto)] ) - body: content 该段落的内容。 === 定义(Definitions) - *line*<Paragraph_line> 一段段落行。 该元素仅用于通过设置规则进行行号配置,不可放置。 编号选项用于通过指定编号格式来启用行号。 #table( columns: (1fr,1fr), align: (left,left), stroke: none, fill: (rgb(250, 250, 250),luma(86.27%)), [ ```typst #set par.line(numbering: "1") Roses are red. \ Violets are blue. \ Typst is there for you. ``` ],[ #set align(horizon) #image("images/3079.png",width: auto)] ) 编号选项可以采用预定义的编号样式,或是返回带样式内容的函数。你可以通过 show-set 规则将编号设置为 none,以此对特定元素内的文本关闭行号显示。 #table( columns: (1fr,1fr), align: (left,left), stroke: none, fill: (rgb(250, 250, 250),luma(86.27%)), [ ```typst // Styled red line numbers. #set par.line( numbering: n => text(red)[#n] ) // Disable numbers inside figures. #show figure: set par.line( numbering: none ) Roses are red. \ Violets are blue. #figure( caption: [Without line numbers.] )[ Lorem ipsum \ dolor sit amet ] The text above is a sample \ originating from distant times. ``` ],[ #set align(horizon) #image("images/3080.png",width: auto)] ) 该元素提供更多选项,可用于控制行号的其他属性,例如行号的对齐方式或边距。此外,你可以通过编号范围选项设置是否在每一页重新开始编号。 ```typc par.line( numbering: none str function, number-align: auto alignment, number-margin: alignment, number-clearance: auto length, numbering-scope: str, ) → content ``` -- *numbering*: none str function<Paragraph_numbering> 如何为每一行编号。默认值:#rtext()[none]。 支持#link(<numbering>)[编号样式],或是接收单个数字参数的函数。 #table( columns: (1fr,1fr), align: (left,left), stroke: none, fill: (rgb(250, 250, 250),luma(86.27%)), [ ```typst #set par.line(numbering: "I") Roses are red. \ Violets are blue. \ Typst is there for you. ``` ],[ #set align(horizon) #image("images/3081.png",width: auto)] ) #table( columns: 1fr, align: left, stroke: none, [ ```typst #set par.line( numbering: i => if calc.rem(i, 5) == 0 or i == 1 { i }, ) #lorem(60) ``` ], [ #rect( fill: luma(240), width: 100%, height: auto, image("images/3082.png",width: 80%) ) ] ) -- *number-align*: auto alignment<Paragraph_number-align> 与每一行相关联的行号的对齐方式。默认值:#rtext()[auto]。 #rtext()[auto] 默认值代表智能默认模式,在此模式下,行号沿着远离文本的水平方向递增,同时会考虑其所在边距以及当前文本方向。 #table( columns: (1fr,1fr), align: (left,left), stroke: none, fill: (rgb(250, 250, 250),luma(86.27%)), [ ```typst #set par.line( numbering: "I", number-align: left, ) Hello world! \ Today is a beautiful day \ For exploring the world. ``` ],[ #set align(horizon) #image("images/3083.png",width: auto)] ) -- *number-margin*: alignment 行号显示的边距。默认值:start。 注:在多栏文档中,最后一栏内段落的行号将始终显示在末端边距(从左到右文本为右边距,从右到左文本为左边距),不受此项设置影响。该行为目前无法更改。 #table( columns: (1fr,1fr), align: (left,left), stroke: none, fill: (rgb(250, 250, 250),luma(86.27%)), [ ```typst #set par.line( numbering: "1", number-margin: right, ) = Report - Brightness: Dark, yet darker - Readings: Negative ``` ],[ #set align(horizon) #image("images/3084.png",width: auto)] ) -- *number-clearance*: auto length 行号与文本之间的距离。默认值:#rtext()[auto]。 #rtext()[auto]的默认值会生成适配页面宽度的间距,在大多数场景下效果良好。 #table( columns: (1fr,1fr), align: (left,left), stroke: none, fill: (rgb(250, 250, 250),luma(86.27%)), [ ```typst #set par.line( numbering: "1", number-clearance: 4pt, ) Typesetting \ Styling \ Layout ``` ],[ #set align(horizon) #image("images/3085.png",width: auto)] ) -- *numbering-scope*: str 控制何时重置行号。默认值:```typc "document"```。 注:行号的作用范围在每一组连续页面内必须保持一致(一组连续页面指中间没有显式分页符的一系列页面)。因此,相关设置规则应在任何页面内容之前定义,通常放在文档的最开头。 #table( columns: (0.5fr,1.5fr), stroke: none, align: (left,left), table.header[Variant][Details], table.hline(), [\"document\"],[表示行号计数器作用于整个文档,即不会自动重置。], [\"page\"],[表示行号计数器应在每一新页面的起始位置重置。] ) #table( columns: (1fr,1fr), align: (left,left), stroke: none, fill: (rgb(250, 250, 250),luma(86.27%)), [ ```typst #set par.line( numbering: "1", numbering-scope: "page", ) First line \ Second line #pagebreak() First line again \ Second line again ``` ],[ #set align(horizon) #image("images/3086.png",width: auto)\ #image("images/3086.png",width: auto)] ) == 段落分隔(parbreak)<parbreak> 分隔段落。 这会开启一个新段落。在循环这类代码中使用时尤为实用。多个连续的段落换行将合并为一个。 === 示例(Example) #table( columns: (1fr,1fr), align: (left,left), stroke: none, fill: (rgb(250, 250, 250),luma(86.27%)), [ ```typst #for i in range(3) { [Blind text #i: ] lorem(5) parbreak() } ``` ],[ #set align(horizon) #image("images/3088.png",width: auto)] ) === 语法(Syntax) 你可以在标记语言中插入空行来实现段落分隔,而不必调用此函数。 === 参数(Parameters) ```typc parbreak() → content ``` == 引述(quote)<quote> 显示一段引语,同时可附带可选的出处说明。 === 示例(Example) #table( columns: 1fr, align: left, stroke: none, [ ```typst Plato is often misquoted as the author of #quote[I know that I know nothing], however, this is a derivation form his original quote: #set quote(block: true) #quote(attribution: [Plato])[ ... ἔοικα γοῦν τούτου γε σμικρῷ τινι αὐτῷ τούτῳ σοφώτερος εἶναι, ὅτι ἃ μὴ οἶδα οὐδὲ οἴομαι εἰδέναι. ] #quote(attribution: [from the Henry Cary literal translation of 1897])[ ... I seem, then, in just this little thing to be wiser than this man at any rate, that what I do not know I do not think I know either. ] ``` ], [ #set quote(block: true) #show quote: set align(center) #rect( fill: luma(240), width: 100%, height: auto, quote[ #image("images/3089.png",width: 80%) ] ) ] ) 默认情况下,块引用左右两侧有1em的内边距,对齐方式与内边距可通过显示规则进行控制: #table( columns: 1fr, align: left, stroke: none, [ ```typst #set quote(block: true) #show quote: set align(center) #show quote: set pad(x: 5em) #quote[ You cannot pass... I am a servant of the Secret Fire, wielder of the flame of Anor. You cannot pass. The dark fire will not avail you, flame of Udûn. Go back to the Shadow! You cannot pass. ] ``` ], [ #set quote(block: true) #show quote: set align(center) #rect( fill: luma(240), width: 100%, height: auto, quote[ #image("images/3090.png",width: 80%) ] ) ] ) === 参数(Parameters) ```typc quote( block: bool, quotes: auto bool, attribution: none label content, body:content, ) → content ``` - *block*: bool 这是否是块引用。默认值:#rtext()[false]。 #table( columns: (1fr,1fr), align: (left,left), stroke: none, fill: (rgb(250, 250, 250),luma(86.27%)), [ ```typst An inline citation would look like this: #quote( attribution: [René Descartes] )[ cogito, ergo sum ], and a block equation like this: #quote( block: true, attribution: [JFK] )[ Ich bin ein Berliner. ] ``` ],[ #set align(horizon) #image("images/3091.png",width: auto)] ) - *quotes*: auto bool 是否需要在这段引文两侧添加双引号。默认值:#rtext()[auto]。 所使用的双引号由 smartquote 的 quotes 属性推断得出,该属性会受到文本上 lang 属性的影响。 #set par(hanging-indent: 1.3cm) -- #rtext()[true]:用双引号包裹这段引文。 -- #rtext()[false]:不用双引号包裹这段引文。 -- #rtext()[auto]:根据 block 属性推断是否用双引号包裹这段引文。若 block 为 false,则自动添加双引号。 #set par(hanging-indent: 0cm) #table( columns: (1fr,1fr), align: (left,left), stroke: none, fill: (rgb(250, 250, 250),luma(86.27%)), [ ```typst #set text(lang: "de") Ein deutsch-sprechender Author zitiert unter umständen JFK: #quote[Ich bin ein Berliner.] #set text(lang: "en") And an english speaking one may translate the quote: #quote[I am a Berliner.] ``` ],[ #set align(horizon) #image("images/3092.png",width: auto)] ) - *attribution*: none label content 该引文的出处标注,通常指作者或来源。可以是指向参考文献条目的标记,或是任意内容。默认仅在块引用中显示,但可通过show规则修改。默认值:#rtext()[none]。 #table( columns: 1fr, align: left, stroke: none, [ ```typst #quote(attribution: [René Descartes])[ cogito, ergo sum ] #show quote.where(block: false): it => { ["] + h(0pt, weak: true) + it.body + h(0pt, weak: true) + ["] if it.attribution != none [ (#it.attribution)] } #quote( attribution: link("https://typst.app/home")[typst.app] )[ Compose papers faster ] #set quote(block: true) #quote(attribution: <tolkien54>)[ You cannot pass... I am a servant of the Secret Fire, wielder of the flame of Anor. You cannot pass. The dark fire will not avail you, flame of Udûn. Go back to the Shadow! You cannot pass. ] #bibliography("works.bib", style: "apa") ``` ], [ #set quote(block: true) #show quote: set align(center) #rect( fill: luma(240), width: 100%, height: auto, quote[ #image("images/3093.png",width: 80%) ] ) ] ) - *body*: content 引语。 == 引用(ref)<ref> 对标签或参考文献的引用。 接收一个标签并对其进行交叉引用。引用分为两种类型,由其形式决定:```typc "normal"```引用和```typc "page"```引用。 默认的```typc "normal"```引用会生成指向标签的文本引用。例如,对标题的引用会生成合适的字符串,比如引用第一个标题时会显示“第1节”。“节”这个词由#link(<text_lang>)[语言]设置决定,并会做相应本地化处理。这些引用同时也是指向对应元素的链接。引用语法也可以用于参考文献的引用。 由于默认形式需要补充内容与编号,标签必须附加在可引用元素上。可引用元素包括#link(<heading>)[标题]、#link(<figure>)[图片]、#link(<equation>)[公式]和#link(<footnote>)[脚注]。如果想要创建定理这类自定义可引用元素,可以创建#link(<figure_kind>)[自定义类型的图片]并为其编写show规则。未来或许会有更直接的方式来定义自定义可引用元素。 如果你仅希望链接到带标签的元素,而不需要自动生成文本引用,可以改用#link(<link>)[链接]函数。 ```typc "page"```引用会生成指向标签的页面引用,在对应位置显示页码。你可以使用#link(<page_supplement>)[页面补充项]修改页码前的文本。与```typc "normal"```引用不同,只要对应#link(<page_numbering>)[页面的编号]已设置,该标签可以附加到任意元素上。 === 示例(Example) #table( columns: (1fr,1fr), align: (left,left), stroke: none, fill: (rgb(250, 250, 250),luma(86.27%)), [ ```typst #set page(numbering: "1") #set heading(numbering: "1.") #set math.equation(numbering: "(1)") = Introduction <intro> Recent developments in typesetting software have rekindled hope in previously frustrated researchers. @distress As shown in @results (see #ref(<results>, form: "page")), we ... = Results <results> We discuss our approach in comparison with others. == Performance <perf> @slow demonstrates what slow software looks like. $ T(n) = O(2^n) $ <slow> #bibliography("works.bib") ``` ],[ #set align(horizon) #image("images/3094.png",width: auto)] ) === 语法(Syntax) 该功能还有专用语法:输入\@加上标签名称,即可创建标签的 默认的```typc "normal"```引用(例如 = Introduction <intro> 可以通过输入\@intro来引用)。 若要自定义补充文本,在引用后面的方括号内添加内容即可:\@intro[章节]。 === 个性化(Customization) 当你只需要引用文档中的图表、表格、标题等内容所在页码时,可以通过set规则,将默认表单字段值修改为```typc "page"```。如果你不想使用```typc"page"```,而希望用简短的“p.”作为补充标识,可以使用 #link(<page_supplement>)[page.supplement] 字段来完成修改: #table( columns: (1fr,1fr), align: (left,left), stroke: none, fill: (rgb(250, 250, 250),luma(86.27%)), [ ```typst #set page( numbering: "1", supplement: "p.", ) #set ref(form: "page") #figure( stack( dir: ltr, spacing: 1em, circle(), square(), ), caption: [Shapes], ) <shapes> #pagebreak() See @shapes for examples of different shapes. ``` ],[ #set align(horizon) #image("images/3095.png",width: auto)\ #image("images/3096.png",width: auto) ] ) 如果你为引用编写show规则,可以通过引用的 element 类型访问被引用的元素。即便该元素实际存在,若 Typst 尚未检索到它,element 的值也可能为 #rtext()[none],因此你始终需要在代码中处理这种情况。 #table( columns: 1fr, align: left, stroke: none, [ ```typst #set heading(numbering: "1.") #set math.equation(numbering: "(1)") #show ref: it => { let eq = math.equation let el = it.element // Skip all other references. if el == none or el.func() != eq { return it } // Override equation references. link(el.location(), counter(eq).display(at: el.location())) } = Beginnings <beginning> In @beginning we prove @pythagoras. $ a^2 + b^2 = c^2 $ <pythagoras> ``` ], [ #set quote(block: true) #show quote: set align(center) #rect( fill: luma(240), width: 100%, height: auto, quote[ #image("images/3097.png",width: 80%) ] ) ] ) === 参数(Parameters) ```typc ref( target:label, supplement: none auto content function, form: str, ) → content ``` - *target*: label<ref_target> 应引用的目标标签。 该标签可以是文档中定义的标签;若表单设置为“普通”,则可以是#link(<bibliography>)[参考文献]列表中的条目。 - *supplement*: none auto content function<ref_supplement> 供参考的补充说明。默认值:#rtext()[auto]。 若#link(<ref_form>)[格式]设置为"```typc "normal"```: -- 对于标题或图表的引用,该内容会添加在引用编号之前。 -- 对于文献引用,可使用它来添加页码。 若#link(<ref_form>)[格式]设置为```typc "page"```,则该内容会添加在所引用标签的页码之前。 如果指定了函数,该函数会接收被引用元素,并应当返回内容。 #table( columns: (1fr,1fr), align: (left,left), stroke: none, fill: (rgb(250, 250, 250),luma(86.27%)), [ ```typst #set heading(numbering: "1.") #show ref.where( form: "normal" ): set ref(supplement: it => { if it.func() == heading { "Chapter" } else { "Thing" } }) = Introduction <intro> In @intro, we see how to turn Sections into Chapters. And in @intro[Part], it is done manually. ``` ],[ #set align(horizon) #image("images/3098.png",width: auto) ] ) - *form*: str<ref_form> 要生成的参考文献类型。默认值:```typc "normal"``` #table( columns: (0.5fr,1.5fr), stroke: none, align: (left,left), table.header[Variant][Details], table.hline(), [```typc "normal"```],[生成对标签的文本引用。], [```typc "page"```],[生成指向标签的页码引用。] ) #table( columns: (1fr,1fr), align: (left,left), stroke: none, fill: (rgb(250, 250, 250),luma(86.27%)), [ ```typst #set page(numbering: "1") Here <here> we are on #ref(<here>, form: "page"). ``` ],[ #set align(horizon) #image("images/3099.png",width: auto) ] ) == 强调(strong)<strong> 通过增加字体粗细来着重强调内容。 按照给定的增量值增加当前字体粗细。 === 示例(Example) #table( columns: (1fr,1fr), align: (left,left), stroke: none, fill: (rgb(250, 250, 250),luma(86.27%)), [ ```typst This is *strong.* \ This is #strong[too.] \ #show strong: set text(red) And this is *evermore.* ``` ],[ #set align(horizon) #image("images/3100.png",width: auto) ] ) === 语法(Syntax) 该函数还有专用语法:若要对内容进行着重强调,只需将内容放在星号(\*)之间。请注意,该语法仅在单词边界处生效。如果需要强调一个单词的局部内容,则必须使用该函数。 === 参数(Parameters) ```typc strong( delta: int, body: content, ) → content ``` - *delta*: int 要应用在字体粗细上的差值。默认值:#rtext()[300]。 #table( columns: (1fr,1fr), align: (left,left), stroke: none, fill: (rgb(250, 250, 250),luma(86.27%)), [ ```typst #set strong(delta: 0) No *effect!* ``` ],[ #set align(horizon) #image("images/3101.png",width: auto) ] ) - *body*: content 需要重点强调的内容。 == 表格(table)<table> 项目表格。 表格用于在单元格内排布内容。单元格可容纳任意内容,包括多个段落,单元格按行优先顺序定义。如果你想实操了解在 Typst 中使用和自定义表格的全部方式,可以查阅《表格指南》。 表格本质上就是网格,只是部分单元格属性(尤其是描边和内边距)的默认值不同。如需了解如何设置表格轨道尺寸以及指定单元格外观属性,请参考#link(<grid>)[网格]相关文档。 如果你不确定应该使用表格还是网格,可以这样判断:你要排布的内容在语义上是否属于一组相关数据点或同类信息,还是仅仅想通过网格排布互不相关的内容来优化展示效果。若是前者,表格是合适的选择;若是后者,网格会更加适用。此外,屏幕阅读器这类辅助技术(AT)会将表格内容识别为表格形式播报,而网格里的内容则和文档流中的多个内容块播报方式无异。辅助技术用户可以按单元格对表格进行二维导航。 请注意,若要覆盖特定单元格的属性或为表格单元格应用显示规则,你可以使用 #link(<table_cell>)[table.cell] 元素。更多信息请参阅其文档。 虽然表格(table)与网格(grid)共享大部分属性,但在其中一方上的set规则和show规则不会影响另一方。建议将大部分样式放在set规则和show规则中,这样能保持表格实际使用代码整洁易读,还支持在一处统一修改所有表格的外观。 如需为表格添加标题并使其#link(<ref>)[可被引用],可将表格放入图块(#link(<figure>)[figure])内。 === 示例(Example) 下面这个示例展示了部分最常用的表格选项。 #table( columns: (1fr,1fr), align: (left,left), stroke: none, fill: (rgb(250, 250, 250),luma(86.27%)), [ ```typst #table( columns: (1fr, auto, auto), inset: 10pt, align: horizon, table.header( [], [*Volume*], [*Parameters*], ), image("cylinder.svg"), $ pi h (D^2 - d^2) / 4 $, [ $h$: height \ $D$: outer radius \ $d$: inner radius ], image("tetrahedron.svg"), $ sqrt(2) / 12 a^3 $, [$a$: edge length] ) ``` ],[ #set align(horizon) #image("images/3102.png",width: auto) ] ) 和网格用法十分相似,你可以使用 #link(<table_cell>)[table.cell] 来自定义每个单元格的外观和位置。 #table( columns: (1fr,1fr), align: (left,left), stroke: none, fill: (rgb(250, 250, 250),luma(86.27%)), [ ```typst #set table( stroke: none, gutter: 0.2em, fill: (x, y) => if x == 0 or y == 0 { gray }, inset: (right: 1.5em), ) #show table.cell: it => { if it.x == 0 or it.y == 0 { set text(white) strong(it) } else if it.body == [] { // Replace empty cells with 'N/A' pad(..it.inset)[_N/A_] } else { it } } #let a = table.cell( fill: green.lighten(60%), )[A] #let b = table.cell( fill: aqua.lighten(60%), )[B] #table( columns: 4, [], [Exam 1], [Exam 2], [Exam 3], [John], [], a, [], [Mary], [], a, a, [Robert], b, a, b, ) ``` ],[ #set align(horizon) #image("images/3103.png",width: auto) ] ) === 无障碍性(Accessibility)<table_Accessibility> 对于使用辅助技术(AT)的用户来说,表格难以阅读。为方便辅助技术用户,我们强烈建议使用 #link(<table_header>)[table.header] 和 #link(<table_footer>)[table.footer] 标记表格的表头和表尾区域。这样辅助技术就可以播报每个单元格对应的列标签。 由于通过单元格浏览表格比视觉阅读更为繁琐,你还应当考虑将表格中的核心信息以文本形式同步呈现。实现方式是将表格置于图形容器内,并使用图形容器的标题来概括表格内容。 === 参数(Parameters) ```typc table( columns: auto int relative fraction array, rows: auto int relative fraction array, gutter: auto int relative fraction array, column-gutter: auto int relative fraction array, row-gutter: auto int relative fraction array, inset: relative array dictionary function, align: auto array function alignment, fill: none color gradient tiling array function, stroke: none length color gradient stroke tiling array dictionary function, children: ..content, ) → content ``` - *columns*: auto int relative fraction array<table_columns> 列尺寸。有关轨道尺寸的更多信息,请参阅#link(<grid_columns>)[网格文档]。 - *rows*: auto int relative fraction array 行尺寸。关于轨道尺寸的更多信息,请参阅#link(<grid_rows>)[网格文档]。 - *gutter*: auto int relative fraction array<table_gutter> 行与列之间的间距。这是将列间距和行间距设置为相同值的简写方式。有关间距的更多信息,请参阅#link(<grid_gutter>)[网格文档]。 - *column-gutter*: auto int relative fraction array<table_column-gutter> 列之间的间距。优先级高于槽距。有关槽距的更多信息,请参阅#link(<grid_column-gutter>)[网格文档]。 - *row-gutter*: auto int relative fraction array<table_row-gutter> 行间距。优先级高于槽距。关于槽距的更多信息,请参阅#link(<grid_row-gutter>)[网格文档]。 - *inset*: relative array dictionary function<table_inset> 单元格内容的内边距大小。默认值:#rtext()[0%+5pt]。 如需为所有单元格设置相同的内边距,可使用单个长度值统一设置四边,也可使用长度字典分别设置各边。更多详情请参阅#link(<box_inset>)[盒子相关文档]。 如需为不同单元格设置不同内边距,你可以:\ -- 为所有单元格使用统一的内边距\ -- 为每一列使用一组内边距数组\ -- 使用函数,将单元格的横纵坐标(均从0开始)映射为对应的内边距 更多详情请查阅#link(<grid_Styling-the-grid>)[网格文档]。 #table( columns: (1fr,1fr), align: (left,left), stroke: none, fill: (rgb(250, 250, 250),luma(86.27%)), [ ```typst #table( columns: 2, inset: 10pt, [Hello], [World], ) #table( columns: 2, inset: (x: 20pt, y: 10pt), [Hello], [World], ) ``` ],[ #set align(horizon) #image("images/3104.png",width: auto) ] ) - *align*: auto array function alignment<table_align> 如何对齐单元格内容。默认值:#rtext()[auto]。 如果设置为auto,则使用外部对齐方式。 你可以通过以下任意一种方式指定对齐方式: #set par(hanging-indent: 1.3cm) -- 为所有单元格设置统一的对齐方式 -- 使用与每一列对应的对齐方式数组 -- 使用函数,将单元格的X/Y坐标(均从0开始)映射为对应对齐方式 #set par(hanging-indent: 0cm) 详细信息请参阅#link(<table_guide-align-the-contents-of-the-cells>)[表格指南]。 #table( columns: (1fr,1fr), align: (left,left), stroke: none, fill: (rgb(250, 250, 250),luma(86.27%)), [ ```typst #table( columns: 3, align: (left, center, right), [Hello], [Hello], [Hello], [A], [B], [C], ) ``` ],[ #set align(horizon) #image("images/3105.png",width: auto) ] ) - *fill*:none color gradient tiling array function 如何填充单元格。默认值:#rtext()[none]。 填充方式可以是:\ -- 适用于所有单元格的单一填充样式\ -- 与每一列对应的填充样式数组\ -- 可根据单元格位置确定填充样式的函数 值得注意的是,数组和函数非常适合用来创建条纹表格。更多信息请参阅#link(<table_guide-get-a-striped-table>)[表格指南]。 #table( columns: 1fr, align: left, stroke: none, [ ```typst #table( fill: (x, _) => if calc.odd(x) { luma(240) } else { white }, align: (x, y) => if y == 0 { center } else if x == 0 { left } else { right }, columns: 4, [], [*Q1*], [*Q2*], [*Q3*], [Revenue:], [1000 €], [2000 €], [3000 €], [Expenses:], [500 €], [1000 €], [1500 €], [Profit:], [500 €], [1000 €], [1500 €], ) ``` ], [ #set quote(block: true) #show quote: set align(center) #rect( fill: luma(240), width: 100%, height: auto, quote[ #image("images/3106.png",width: 80%) ] ) ] ) - *stroke*: none length color gradient stroke tiling array dictionary function<table_stroke> 如何#link(<stroke>)[绘制]单元格描边。默认值:#rtext()[1pt+]black。 将此项设置为#rtext()[none]可以关闭描边。 如果需要绘制线条,使其能够跨越由边距选项产生的单元格#link(<table_guide>)[间距],或是覆盖多个特定单元格之间的描边,可以考虑在表格单元格配置之外,设置#link(<table_hline>)[table.hline]和#link(<table_vline>)[table.vline]中的一项或多项。 如需为所有单元格设置相同描边,可以使用单条#link(<stroke>)[描边]作用于全部边,或是使用描边字典分别定义各个边。更多详情请参阅#link(<rect_stroke>)[矩形相关文档]。 如需为不同单元格设置不同描边,可采用以下方式:\ -- 使用单条描边应用于全部单元格\ -- 使用描边数组,每一项对应一列\ -- 使用函数,根据单元格位置返回对应的描边 更多详情请查阅#link(<table_guide-document-wide-stroke-functions>)[表格指南]。 - *children*: content 表格单元格内的内容,以及通过 table.hline 和 table.vline 元素指定的所有额外表格线条。 === 定义(Definitions) - *cell*<table_cell> 表格中的单元格。可使用它手动定位单元格,或是设置样式。后者有两种实现方式:调用该函数覆盖特定单元格的属性,或是在显示规则中使用它,一次性为多个单元格应用指定样式。 table.cell 最重要的用途,或许就是通过 colspan(列合并)与 rowspan(行合并)字段,让一个单元格跨越多列和/或多行。 #table( columns: (1fr,1fr), align: (left,left), stroke: none, fill: (rgb(250, 250, 250),luma(86.27%)), [ ```typst #show table.cell.where(y: 0): strong #set table( stroke: (x, y) => if y == 0 { (bottom: 0.7pt + black) }, align: (x, y) => ( if x > 0 { center } else { left } ) ) #table( columns: 3, table.header( [Substance], [Subcritical °C], [Supercritical °C], ), [Hydrochloric Acid], [12.0], [92.1], [Sodium Myreth Sulfate], [16.6], [104], [Potassium Hydroxide], table.cell(colspan: 2)[24.7], ) ``` ],[ #set align(horizon) #image("images/3107.png",width: auto) ] ) 你也可以对 table.cell 应用show规则,一次性为所有单元格设置样式。搭配选择器,你可以根据单元格的位置来应用样式: #table( columns: (1fr,1fr), align: (left,left), stroke: none, fill: (rgb(250, 250, 250),luma(86.27%)), [ ```typst #show table.cell.where(x: 0): strong #table( columns: 3, gutter: 3pt, [Name], [Age], [Strength], [Hannes], [36], [Grace], [Irma], [50], [Resourcefulness], [Vikram], [49], [Perseverance], ) ``` ],[ #set align(horizon) #image("images/3108.png",width: auto) ] ) ```typc table.cell( body:content, x: auto int, y: auto int, colspan: int, rowspan: int, inset: auto relative dictionary, align: auto alignment, fill: none auto color gradient tiling, stroke: none length color gradients troke tiling dictionary, breakable: auto bool, ) → content ``` -- *body*: content 单元格本体。 -- *x*: auto int 单元格所在列(从零开始索引)。功能与 #link(<grid_cell>)[grid.cell] 中的 x 字段完全一致。默认值:#rtext()[auto]。 -- *y*: auto int 单元格所在的行(从零开始索引)。其功能与 #link(<grid_cell>)[grid.cell] 中的 y 字段完全相同。默认值:#rtext()[auto]。 -- *colspan*: int 此单元格跨越的列数。默认值:#rtext()[1]。 -- *rowspan*: int 此单元格所跨的行数。默认值:#rtext()[1]。 -- *inset*: auto relative dictionary 单元格的#link(<table_inset>)[内嵌]覆盖设置。默认值:#rtext()[auto]。 -- *align*: auto alignment 单元格的对齐方式覆盖设置默认值:#rtext()[auto]。 -- *fill*: none auto color gradient tiling 单元格的填充覆盖。默认值:#rtext()[auto]。 -- *stroke*: none length color gradient stroke tiling dictionary<table_cell-stroke> 单元格笔画覆盖。默认值:(:)。 -- *breakable*: auto bool<table_breakable> 该单元格所跨的行是否可以分布在不同页面。当取值为auto时,仅跨固定高度行的单元格不可分页,而至少跨一行自动高度行的单元格支持分页。默认值:#rtext()[auto]。 - *hline*<table_hline> 表格中的水平线。 它会覆盖所有单元格描边,包括通过表格描边字段设置的描边。该线条可以穿过由#link(<table_column-gutter>)[表格列间距]选项产生的单元格间隙。 如果你需要在单个表格内的指定位置手动添加水平线,请使用该功能,而不是表格描边字段。如果需要添加的线条属于所有表格统一的设计样式,则建议改用#link(<table_stroke>)[表格描边]字段或#link(<table_cell-stroke>)[单元格描边字段]。 #table( columns: (1fr,1fr), align: (left,left), stroke: none, fill: (rgb(250, 250, 250),luma(86.27%)), [ ```typst #set table.hline(stroke: .6pt) #table( stroke: none, columns: (auto, 1fr), [09:00], [Badge pick up], [09:45], [Opening Keynote], [10:30], [Talk: Typst's Future], [11:15], [Session: Good PRs], table.hline(start: 1), [Noon], [_Lunch break_], table.hline(start: 1), [14:00], [Talk: Tracked Layout], [15:00], [Talk: Automations], [16:00], [Workshop: Tables], table.hline(), [19:00], [Day 1 Attendee Mixer], ) ``` ],[ #set align(horizon) #image("images/3109.png",width: auto) ] ) ```typc table.hline( y: autoint, start: int, end: none int, stroke: none length color gradient stroke tiling dictionary, position: alignment, ) → content ``` -- *y*: auto int 放置水平线的上方行(从零开始索引)。功能与 grid.hline 中的 y 字段完全相同。默认值:#rtext()[auto]。 -- *start*: int 水平线起始所在的列(从零开始索引,包含该列)。默认值:#rtext()[0]。 -- *end*: none int 水平线终止位置之前的列(从零开始索引,不包含该列)。默认值:#rtext()[none]。 -- *stroke*: none length color gradient stroke tiling dictionary 线条的描边。默认值:#rtext()[1pt+]black。 指定为无,会移除此前在该线条范围内绘制的所有线条,包括水平线或单元格下方的描边。 -- *position*: alignment 给定线条所在行(y轴),可设置线条的放置位置:选择顶部,线条绘制在该行上方;选择底部,线条绘制在该行下方。默认值:top。 该设置仅在启用行间距时生效(其他场景下不建议使用,可直接将y值加1来实现需求)。因为启用行间距后,某一行下方的位置与下一行上方的位置会因两者间的间隔而不再相同。 - *vline*<table_vline> 表格中的竖线。有关如何使用该元素字段的更多信息,请参阅 #link(<grid_vline>)[grid.vline] 的文档。 它会覆盖任何单元格描边,包括通过表格的描边字段设置的描边。该竖线可以穿过由表格#link(<table_row-gutter>)[行间距]选项产生的单元格间隙。 该功能与 #link(<table_hline>)[table.hline] 类似。如果你需要在单个表格的指定位置手动放置竖线,请使用此函数;如果想要添加的线条是所有表格设计的通用部分,则改用#link(<table_stroke>)[表格描边字段]或#link(<table_cell-stroke>)[单元格描边字段]。 ```typc table.vline( x: auto int, start: int, end: none int, stroke: none length color gradient stroke tiling dictionary, position: alignment, ) → content ``` -- *x*: auto int 放置竖线之前的列(从零开始索引)。功能与 #link(<grid_vline>)[grid.vline] 中的 x 字段完全相同。默认值:#rtext()[auto]。 -- *start*: int 竖线起始所在行(从零开始索引,包含该行)。默认值:#rtext()[0]。 -- *end*: none int 垂直线结束的顶部行(从零开始索引,不包含该行)默认值:#rtext()[none]。 -- *stroke*: none length color gradient stroke tiling dictionary 线条的描边。默认值:#rtext()[1pt+]black。 指定为无,会清除此前在该线条范围内绘制的所有线条,包括垂直线条或其下方按单元格设置的描边。 -- *position*: alignment 线条的放置位置,由其所在列(x)决定:start表示在该列之前绘制线条,end表示在该列之后绘制线条。默认值:start。 也可使用left和right作为取值,但不推荐,因为会导致文档在从左到右和从右到左的排版模式下表单样式不一致。 该设置仅在启用列间距时生效(其他场景不建议使用,优先选择直接将x字段加1)。因为启用列间距后,某一列的结束位置和下一列的起始位置会因中间间隔而不同。 - *header*<table_header> 可重复的表格表头。 即使你不打算将表格分页,也应该用该函数包裹表格的标题行,因为 Typst 会通过此函数为表格附加无障碍元数据,保障文档的通用可访问性。 你可以使用 #link(<repeat>)[repeat] 参数控制表格表头是否在多页上重复显示。 目前,该函数不适合用于创建首列表头或独立的表头单元格。你可以使用普通单元格;如果导出PDF,也可以使用 pdf.header-cell 函数将单元格标记为表头单元格。同样,你可以使用 pdf.data-cell 将此函数内的单元格标记为数据单元格。请注意:这些函数尚不稳定,仅在开启 a11y-extras 特性后可用(详情参见PDF模块文档)。 #table( columns: (1fr,1fr), align: (left,left), stroke: none, fill: (rgb(250, 250, 250),luma(86.27%)), [ ```typst #set page(height: 11.5em) #set table( fill: (x, y) => if x == 0 or y == 0 { gray.lighten(40%) }, align: right, ) #show table.cell.where(x: 0): strong #show table.cell.where(y: 0): strong #table( columns: 4, table.header( [], [Blue chip], [Fresh IPO], [Penny st'k], ), table.cell( rowspan: 6, align: horizon, rotate(-90deg, reflow: true)[ *USD / day* ], ), [0.20], [104], [5], [3.17], [108], [4], [1.59], [84], [1], [0.26], [98], [15], [0.01], [195], [4], [7.34], [57], [2], ) ``` ],[ #set align(horizon) #image("images/3110.png",width: auto)\ #image("images/3111.png",width: auto) ] ) ```typc table.header( repeat: bool, level: int, children:..content, ) → content ``` -- *repeat*: bool 此表头是否需要在各页面重复显示。默认值:#rtext()[true]。 -- *level*: int 标题的层级,不能为0。默认值:#rtext()[1]。 该设置支持一次性重复多个标题。不同层级的标题可以一同重复,前提是层级按升序排列。 值得注意的是,当一个较低层级的标题开始重复时,所有更高层级或同等层级的标题将停止重复(它们会被新标题“替换”)。 -- *children*: content 表头内的单元格和线条。 - *footer*<table_footer> 可重复的表格页脚。 与 table.header 元素类似,页脚可以在表格的每一页重复显示。在大型表格的表头和页脚同时添加列标签、汇总数据或其他需要在每页都可见的信息,能够提升可读性,该特性在此类场景下十分有用。 页脚之后不能放置任何其他表格单元格。 ```typc table.footer( repeat: bool, children:..content, ) → content ``` -- *repeat*: bool 此页脚是否需要在所有页面重复显示。默认值:#rtext()[true]。 -- *children*: content 页脚内的单元格与线条。 == 术语表(terms)<terms> 术语及其说明的列表。 以垂直方式展示一系列术语及其说明。当说明文字跨多行时,会使用悬挂缩进,以此体现视觉层级。 === 示例(Example) #table( columns: (1fr,1fr), align: (left,left), stroke: none, fill: (rgb(250, 250, 250),luma(86.27%)), [ ```typst / Ligature: A merged glyph. / Kerning: A spacing adjustment between two adjacent letters. ``` ],[ #set align(horizon) #image("images/3112.png",width: auto) ] ) === 语法(Syntax) 该功能还有专用语法:以斜杠开头,后面依次接术语、冒号和描述,即可创建术语列表项。 === 参数(Parameters) ```typc terms( tight: bool, separator: content, indent: length, hanging-indent: length, spacing: auto length, children:..content array, ) → content ``` - *tight*: bool<terms_tight> 定义术语列表的默认#link(<terms_spacing>)[间距]。若为 #rtext()[false],条目之间使用段落间距分隔。若为 #rtext()[true],则改用#link(<Paragraph_spacing>)[段落行间距]。这会让列表更加紧凑,当条目内容较短时视觉效果更好。默认值:#rtext()[true]。 在标记模式下,该参数的值由条目之间是否存在空行决定。条目直接相连时,该参数设为 #rtext()[true];条目之间用空行分隔时,该参数设为 #rtext()[false]。标记所定义的紧凑设置无法通过集合规则覆盖。 #table( columns: (1fr,1fr), align: (left,left), stroke: none, fill: (rgb(250, 250, 250),luma(86.27%)), [ ```typst / Fact: If a term list has a lot of text, and maybe other inline content, it should not be tight anymore. / Tip: To make it wide, simply insert a blank line between the items. ``` ],[ #set align(horizon) #image("images/3113.png",width: auto) ] ) - *separator*: content 项目与描述之间的分隔符。默认值:```typc h(amount: 0.6em, weak: true)```。 如果你只想用一定宽度的空白进行分隔,可以使用 ```typc h(2cm, weak: true)``` 作为分隔符,并将 #rtext()[2cm] 替换为你想要的空白宽度。 #table( columns: (1fr,1fr), align: (left,left), stroke: none, fill: (rgb(250, 250, 250),luma(86.27%)), [ ```typst #set terms(separator: [: ]) / Colon: A nice separator symbol. ``` ],[ #set align(horizon) #image("images/3114.png",width: auto) ] ) - *indent*: length 每一项的缩进。默认值:#rtext()[0pt]。 - *hanging-indent*: length<terms_hanging-indent> 描述文本的悬挂缩进。默认值:#rtext()[2em]。 这是在整个项目缩进之外额外设置的。 #table( columns: (1fr,1fr), align: (left,left), stroke: none, fill: (rgb(250, 250, 250),luma(86.27%)), [ ```typst #set terms(hanging-indent: 0pt) / Term: This term list does not make use of hanging indents. ``` ],[ #set align(horizon) #image("images/3115.png",width: auto) ] ) - *spacing*: auto length<terms_spacing> 术语列表各项之间的间距。默认值:#rtext()[auto]。 若设置为自动,紧凑术语列表将使用#link(<Paragraph_leading>)[段落行距],宽松(非紧凑)术语列表则使用#link(<Paragraph_spacing>)[段落间距]。 - *children*: content array 术语列表的子项。 使用术语列表语法时,相邻的条目会自动归入术语列表,即便是通过for循环这类结构生成的条目也一样。 #table( columns: (1fr,1fr), align: (left,left), stroke: none, fill: (rgb(250, 250, 250),luma(86.27%)), [ ```typst #for (year, product) in ( "1978": "TeX", "1984": "LaTeX", "2019": "Typst", ) [/ #product: Born in #year.] ``` ],[ #set align(horizon) #image("images/3116.png",width: auto) ] ) === 定义(Definitions) - *item*<terms_item> 术语列表项。 ```typc terms.item( term: content, description: content, ) → content ``` -- *term*: content 列表项所描述的术语。 -- *description*: content 该术语的描述。 == 题名(title)<title> 文档题名。 该部分用于展示整篇文档的主标题,一篇文档中仅可出现一次。与之不同,一级#link(<heading>)[标题]用于文档的顶层章节。 请注意,与标题一同展示的额外前置元信息(例如作者列表)不属于题名正文内容。 导出为HTML格式时,该主标题会渲染为h1元素,而一级标题则渲染为h2元素。 === 示例(Example) #table( columns: 1fr, align: left, stroke: none, [ ```typst #set document( title: [Interstellar Mail Delivery] ) #title() = Introduction In recent years, ... ``` ], [ #set quote(block: true) #show quote: set align(center) #rect( fill: luma(240), width: 100%, height: auto, quote[ #image("images/3119.png",width: 80%) ] ) ] ) === 参数(Parameters) ```typc title(body: auto content) → content ``` - *body*: auto content 标题的内容。默认值:#rtext()[auto]。 当该项省略(或设为#rtext()[auto])时,默认使用#link(<document_title>)[document.title]。这种情况下,必须预先通过```typc set document(title: [..])```设置文档标题。 #table( columns: 1fr, align: left, stroke: none, [ ```typst #set document(title: [Course ABC, Homework 1]) #title[Homework 1] ... ``` ], [ #set quote(block: true) #show quote: set align(center) #rect( fill: luma(240), width: 100%, height: auto, quote[ #image("images/3117.png",width: 80%) ] ) ] )
#let rtext(content)={
text(fill: rgb(139,0,0),content)
}
= 模型库(Model)<model>
文档结构化。
在此处,你可以找到用于构建文档结构并与该结构交互的各项功能。包括章节标题、图表、参考文献管理、交叉引用等。
== 资源(asset)<asset>
将自定义文件添加到包中。
此函数从#link(<bytes>)[原始字节数据]创建包中的单个文件。与#link(<document>)[文档]不同,资源将按原样发出,而无需进行编译。
asset函数可以与#link(<read>)[读取]相结合,将文件从项目复制到输出包中。asset的第一个参数定义了bundle中资产的输出路径,而传递给read的路径定义了从项目中的何处读取数据。
```typst
// Copy the file `styles.css` into the bundle.
#asset("styles.css", read("styles.css"))
```
也就是说,资源与读无关。您还可以直接生成字节或使用#link(<json_encode>)[json.encode]等函数来发出序列化数据。
```typst
// Emits a JSON file with the number
// of headings in the document.
#context {
let headings = query(heading)
let meta = (
count: headings.len(),
)
asset("meta.json", json.encode(meta))
}
#document("doc.pdf")[
= Introduction
= Conclusion
]
```
这将在生成的包中输出一个包含以下内容的meta.json文件:
```typst
{
"count": 2
}
```
此函数仅限在绑定目标中使用。
=== 参数(Parameters)
```typc
asset(
path:str,
data:str bytes,
) → content
```
- *path*: str
资源在程序包内的存放路径。
路径中可包含内部斜杠,此时系统会自动创建中间层级目录。
- *data*: str bytes
将写入指定路径文件的原始数据。
如果传入字符串,将使用UTF-8进行编码。
== 参考文献(bibliography)<bibliography>
参考书目/参考文献列表。
您可以通过调用此函数来创建新的参考书目,该函数具有以下两种格式之一的参考书目文件的路径:
#set par(hanging-indent: 1.3cm)
-- Hayagriva.yaml/.yml文件。Hayagriva是一种新的书目文件格式,专为Typst设计。有关更多详细信息,请访问其文档。
-- BibLaTeX.bib文件。
#set par(hanging-indent: 0cm)
一旦你在文档的某个地方添加了参考书目,你就可以开始引用引用语法(```typc @key```)或对引用函数(```typc #cite(<key>)```)的显式调用。参考书目将仅显示文档中引用的作品条目。
=== 示例(Example)
#table(
columns: (1fr,1fr),
align: (left,left),
stroke: none,
fill: (rgb(250, 250, 250),luma(86.27%)),
[
```typst
This was already noted by
pirates long ago. @arrgh
Multiple sources say ...
@arrgh @netwok.
#bibliography("works.bib")
```
],[
#set align(horizon)
#image("images/3001.png",width: auto)]
)
=== 风格(Styles)<bibliography_Styles>
Typst提供了多种内置的引文和参考书目样式。除此之外,您还可以添加和使用自定义CSL(引文样式语言)文件。想知道使用哪种风格?以下是一些基于您所从事的学科的良好默认值:
#table(
columns: (1fr,1fr),
stroke: none,
table.header[Fields][Typical Styles],
table.hline(),
[Engineering,IT],[\"ieee\"],
[Psychology,Life Sciences],[\"apa\"],
[Social sciences],[\"chicago-author-date\"],
[Humanities],[\"mla\",\"chicago-notes\",\"harvard-cite-them-right\"],
[Economics],[\"harvard-cite-them-right\"],