这是用户在 2024-3-26 16:31 为 https://typst.app/universe/package/outrageous/ 保存的双语快照页面,由 沉浸式翻译 提供双语支持。了解如何保存?
TypstUniverse

Easier customization of outline entries.
更方便地定制大纲条目。

Examples 实例

For the full source see examples/basic.typ and for more examples see the examples directory.
完整源代码请参见 examples/basic.typ ,更多示例请参见 examples 目录。

Default Style 默认风格

Example: default style

#import "@preview/outrageous:0.1.0"
#show outline.entry: outrageous.show-entry

Custom Settings 自定义设置

Example: custom settings

#import "@preview/outrageous:0.1.0"
#show outline.entry: outrageous.show-entry.with(
  // the typst preset retains the normal Typst appearance
  ..outrageous.presets.typst,
  // we only override a few things:
  // level-1 entries are italic, all others keep their font style
  font-style: ("italic", auto),
  // no fill for level-1 entries, a thin gray line for all deeper levels
  fill: (none, line(length: 100%, stroke: gray + .5pt)),
)

Usage 使用方法

show-entry

Show the given outline entry with the provided styling. Should be used in a show rule like #show outline.entry: outrageous.show-entry.
用提供的样式显示给定的大纲条目。应在显示规则中使用,如 #show outline.entry: outrageous.show-entry .

#let show-entry(
  entry,
  font-weight: presets.outrageous-toc.font-weight,
  font-style: presets.outrageous-toc.font-style,
  vspace: presets.outrageous-toc.vspace,
  font: presets.outrageous-toc.font,
  fill: presets.outrageous-toc.fill,
  fill-right-pad: presets.outrageous-toc.fill-right-pad,
  fill-align: presets.outrageous-toc.fill-align,
  body-transform: presets.outrageous-toc.body-transform,
  label: <outrageous-modified-entry>,
  state-key: "outline-page-number-max-width",
) = { .. }

Arguments: 论据:

For all the arguments that take arrays, the array’s first item specifies the value for all level-one entries, the second item for level-two, and so on. The array’s last item will be used for all deeper/following levels as well.
对于所有使用数组的参数,数组的第一项指定所有一级条目的值,第二项指定二级条目的值,以此类推。数组的最后一项也将用于所有更深/更下面的层级。

  • entry: content — The outline.entry element from the show rule.
    entry : content - 显示规则中的 outline.entry 元素。
  • font-weight: array of (str or int or auto or none) — The entry’s font weight. Setting to auto or none keeps the context’s current style.
    font-weight : array of ( strintautonone ) - 词条的字体权重。设置为 autonone 则保持上下文的当前样式。
  • font-style: array of (str or auto or none) — The entry’s font style. Setting to auto or none keeps the context’s current style.
    font-style : array of ( strautonone ) - 词条的字体样式。设置为 autonone 则保持上下文的当前样式。
  • vspace: array of (relative or fraction or none) — Vertical spacing to add above the entry. Setting to none adds no space.
    vspace : array of ( relativefractionnone ) - 在条目上方添加的垂直间距。设置为 none 时不添加间距。
  • font: array of (str or array or auto or none) — The entry’s font. Setting to auto or none keeps the context’s current font.
    font : array of ( strarrayautonone ) - 条目字体。设置为 autonone 则保持上下文的当前字体。
  • fill: array of (content or auto or none) — The entry’s fill. Setting to auto keeps the context’s current setting.
    fill : array of ( contentautonone } ) - 条目填充。设置为 auto 则保持上下文的当前设置。
  • fill-right-pad: relative or none — Horizontal space to put between the fill and page number.
    fill-right-pad : relativenone - 填充和页码之间的水平空格。
  • fill-align: bool — Whether fill-right-pad should be relative to the current page number or the widest page number. Setting this to true has the effect of all fills ending on the same vertical line.
    fill-align : bool - fill-right-pad 是否应相对于当前页码或最宽页码。将其设置为 true 后,所有填充都会以同一垂直线结束。
  • body-transform: function or none — Callback for custom edits to the entry’s body. It gets passed the entry’s level (int) and body (content) and should return content or none. If none is returned, no modifications are made.
    body-transform : functionnone - 用于对条目正文进行自定义编辑的回调。该回调传递条目的级别( int )和正文( content ),并返回 contentnone 。.如果返回 none ,则不做任何修改。
  • page-transform: function or none — Callback for custom edits to the entry’s page number. It gets passed the entry’s level (int) and page number (content) and should return content or none. If none is returned, no modifications are made.
    page-transform : functionnone - 用于自定义编辑条目页码的回调。该回调传递条目的级别( int )和页码( content ),并返回 contentnone 。.如果返回 none ,则不做任何修改。
  • label: label — The label to internally use for tracking recursion. This should not need to be modified.
    label : label - 内部用于跟踪递归的标签。无需修改。
  • state-key: str — The key to use for the internal state which tracks the maximum page number width. The state is global for the entire document and thus applies to all outlines. If you wish to re-calculate the max page number width for fill-align, then you must provide a different key for each outline.
    state-key : str - 用于跟踪最大页码宽度的内部状态的键值。该状态是整个文档的全局状态,因此适用于所有大纲。如果要重新计算 fill-align 的最大页码宽度,则必须提供不同的键值。的最大页码宽度,则必须为每个大纲提供不同的密钥。

Returns: content 返回: content

presets

Presets for the arguments for show-entry(). You can use them in your show rule with #show outline.entry: outrageous.show-entry.with(..outrageous.presets.outrageous-figures).
show-entry() 的参数预设.您可以在使用 #show outline.entry: outrageous.show-entry.with(..outrageous.presets.outrageous-figures) 的显示规则中使用它们。.

#let presets = (
  // outrageous preset for a Table of Contents
  outrageous-toc: (
    // ...
  ),
  // outrageous preset for List of Figures/Tables/Listings
  outrageous-figures: (
    // ...
  ),
  // preset without any style changes
  typst: (
    // ...
  ),
)

align-helper

Utility function to help with aligning multiple items.
帮助对齐多个项目的实用功能。

#let align-helper(state-key, what-to-measure, display) = { .. }

Arguments: 论据:

  • state-key: str — The key to use for the state that keeps track of the maximum encountered width.
    state-key : str - 用于 state 的键值,该键值用于记录遇到的最大宽度。
  • what-to-measure: content — The content to measure at this call.
    what-to-measure : content - 本次调用要测量的内容。
  • display: function — A callback which gets passed the maximum encountered width and the width of the current item (what was given to what-to-measure), both as length, and should return content which can make use of these widths for alignment.
    display : function - 一个回调函数,它传入最大相遇宽度和当前项目的宽度( what-to-measure 中给出的宽度),两者均为 length ,并应返回 content ,它可以使用这些宽度进行对齐。并返回contentcontent可以使用这些宽度进行对齐。

Returns: content 返回: content