Doc links for function scopes

This commit is contained in:
Laurenz 2023-05-19 11:04:20 +02:00
parent 551ea99d05
commit 56a96881a5
8 changed files with 97 additions and 80 deletions

View File

@ -9,21 +9,21 @@ description: |
- **Breaking changes:** - **Breaking changes:**
- Renamed a few symbols: What was previous `dot.op` is now just `dot` and the - Renamed a few symbols: What was previous `dot.op` is now just `dot` and the
basic dot is `dot.basic`. The same applies to `ast` and `tilde`. basic dot is `dot.basic`. The same applies to `ast` and `tilde`.
- Renamed `mod` to [`rem`]($category/calculate/rem) to more accurately reflect - Renamed `mod` to [`rem`]($func/calc.rem) to more accurately reflect
the behaviour. It will remain available as `mod` until the next update as a the behaviour. It will remain available as `mod` until the next update as a
grace period. grace period.
- A lone underscore is not a valid identifier anymore, it can now only be used - A lone underscore is not a valid identifier anymore, it can now only be used
in patterns in patterns
- Removed `before` and `after` arguments from [`query`]($func/query). This is - Removed `before` and `after` arguments from [`query`]($func/query). This is
now handled through flexible [selectors]($type/selector) combinator methods now handled through flexible [selectors]($type/selector) combinator methods
- Added support for [attachments]($func/attach) (sub-, superscripts) that - Added support for [attachments]($func/math.attach) (sub-, superscripts) that
precede the base symbol. The `top` and `bottom` arguments have been renamed precede the base symbol. The `top` and `bottom` arguments have been renamed
to `t` and `b`. to `t` and `b`.
- New features - New features
- Added support for more complex [strokes]($func/line.stroke) - Added support for more complex [strokes]($func/line.stroke)
(configurable caps, joins, and dash patterns) (configurable caps, joins, and dash patterns)
- Added [`cancel`]($func/cancel) function for equations - Added [`cancel`]($func/math.cancel) function for equations
- Added support for [destructuring]($scripting/#bindings) in argument lists - Added support for [destructuring]($scripting/#bindings) in argument lists
and assignments and assignments
- Added [`alt`]($func/image.alt) text argument to image function - Added [`alt`]($func/image.alt) text argument to image function
@ -106,11 +106,12 @@ description: |
- Added basic i18n for a few more languages - Added basic i18n for a few more languages
(AR, NB, CS, NN, PL, SL, ES, UA, VI) (AR, NB, CS, NN, PL, SL, ES, UA, VI)
- Added a few numbering patterns (Ihora, Chinese) - Added a few numbering patterns (Ihora, Chinese)
- Added `sinc` [operator]($func/op) - Added `sinc` [operator]($func/math.op)
- Fixed bug where math could not be hidden with [`hide`]($func/hide) - Fixed bug where math could not be hidden with [`hide`]($func/hide)
- Fixed sizing issues with box, block, and shapes - Fixed sizing issues with box, block, and shapes
- Fixed some translations - Fixed some translations
- Fixed inversion of "R" in [`cal`]($func/cal) and [`frak`]($func/frak) styles - Fixed inversion of "R" in [`cal`]($func/math.cal) and
[`frak`]($func/math.frak) styles
- Fixed some styling issues in math - Fixed some styling issues in math
- Fixed supplements of references to headings - Fixed supplements of references to headings
- Fixed syntax highlighting of identifiers in certain scenarios - Fixed syntax highlighting of identifiers in certain scenarios
@ -202,11 +203,12 @@ description: |
- Fixed build of CLI if `git` is not installed - Fixed build of CLI if `git` is not installed
- Miscellaneous improvements - Miscellaneous improvements
- Added support for disabling [matrix]($func/mat) and [vector]($func/vec) - Added support for disabling [matrix]($func/math.mat) and
delimiters. Generally with `[#set math.mat(delim: none)]` or one-off with [vector]($func/math.vec) delimiters. Generally with
`[#set math.mat(delim: none)]` or one-off with
`[$mat(delim: #none, 1, 2; 3, 4)$]`. `[$mat(delim: #none, 1, 2; 3, 4)$]`.
- Added [`separator`]($func/terms.separator) argument to term lists - Added [`separator`]($func/terms.separator) argument to term lists
- Added [`round`]($func/round) function for equations - Added [`round`]($func/math.round) function for equations
- Numberings now allow zeros. To reset a counter, you can write - Numberings now allow zeros. To reset a counter, you can write
`[#counter(..).update(0)]` `[#counter(..).update(0)]`
- Added documentation for `{page()}` and `{position()}` methods on - Added documentation for `{page()}` and `{position()}` methods on
@ -221,7 +223,7 @@ description: |
- Fixed combination of page fill and header - Fixed combination of page fill and header
- Fixed compiler crash if [`repeat`]($func/repeat) is used in page with - Fixed compiler crash if [`repeat`]($func/repeat) is used in page with
automatic width automatic width
- Fixed [matrices]($func/mat) with explicit delimiter - Fixed [matrices]($func/math.mat) with explicit delimiter
- Fixed [`indent`]($func/terms.indent) property of term lists - Fixed [`indent`]($func/terms.indent) property of term lists
- Numerous documentation fixes - Numerous documentation fixes
- Links in bibliographies are now affected by link styling - Links in bibliographies are now affected by link styling
@ -284,7 +286,7 @@ description: |
- Further improvements - Further improvements
- Added [`figure`]($func/figure) function - Added [`figure`]($func/figure) function
- Added [`numbering`]($func/equation.numbering) parameter on equation function - Added [`numbering`]($func/math.equation.numbering) parameter on equation function
- Added [`numbering`]($func/page.numbering) and - Added [`numbering`]($func/page.numbering) and
[`number-align`]($func/page.number-align) parameters on page function [`number-align`]($func/page.number-align) parameters on page function
- The page function's [`header`]($func/page.header) and - The page function's [`header`]($func/page.header) and
@ -297,11 +299,12 @@ description: |
- Better default alignment in header and footer - Better default alignment in header and footer
- Fixed Arabic vowel placement - Fixed Arabic vowel placement
- Fixed PDF font embedding issues - Fixed PDF font embedding issues
- Renamed `math.formula` to [`math.equation`]($func/equation) - Renamed `math.formula` to [`math.equation`]($func/math.equation)
- Font family must be a named argument now: `[#set text(font: "..")]` - Font family must be a named argument now: `[#set text(font: "..")]`
- Added support for [hanging indent]($func/par.hanging-indent) - Added support for [hanging indent]($func/par.hanging-indent)
- Renamed paragraph `indent` to [`first-line-indent`]($func/par.first-line-indent) - Renamed paragraph `indent` to
- More accurate [logarithm]($category/calculate/log) when base is `2` or `10` [`first-line-indent`]($func/par.first-line-indent)
- More accurate [logarithm]($func/calc.log) when base is `2` or `10`
- Improved some error messages - Improved some error messages
- Fixed layout of [`terms`]($func/terms) list - Fixed layout of [`terms`]($func/terms) list
@ -333,7 +336,8 @@ description: |
the corresponding main font and the [`smallcaps`]($func/smallcaps) function the corresponding main font and the [`smallcaps`]($func/smallcaps) function
- Improved default spacing for headings - Improved default spacing for headings
- Added [`panic`]($func/panic) function - Added [`panic`]($func/panic) function
- Added [`clusters`]($type/string.clusters) and [`codepoints`]($type/string.codepoints) - Added [`clusters`]($type/string.clusters) and
[`codepoints`]($type/string.codepoints)
methods for strings methods for strings
- Support for multiple authors in [`set document`]($func/document.author) - Support for multiple authors in [`set document`]($func/document.author)
- Fixed crash when string is accessed at a position that is not a char boundary - Fixed crash when string is accessed at a position that is not a char boundary
@ -384,8 +388,8 @@ description: |
- Fixed bug where a heading show rule may not contain a pagebreak when an - Fixed bug where a heading show rule may not contain a pagebreak when an
outline is present outline is present
- Added [`baseline`]($func/box.baseline) property on [`box`]($func/box) - Added [`baseline`]($func/box.baseline) property on [`box`]($func/box)
- Added [`tg`]($func/op) and [`ctg`]($func/op) operators in math - Added [`tg`]($func/math.op) and [`ctg`]($func/math.op) operators in math
- Added delimiter setting for [`cases`]($func/cases) function - Added delimiter setting for [`cases`]($func/math.cases) function
- Parentheses are now included when accepting a function autocompletion - Parentheses are now included when accepting a function autocompletion
## February 2, 2023 ## February 2, 2023

View File

@ -74,7 +74,7 @@ You can also check out the [full syntax cheat sheet]($syntax).
| Term list | `description` environment | `[/ Term: List]` | [`terms`]($func/terms) | | Term list | `description` environment | `[/ Term: List]` | [`terms`]($func/terms) |
| Figure | `figure` environment | `figure` function | [`figure`]($func/figure) | | Figure | `figure` environment | `figure` function | [`figure`]($func/figure) |
| Table | `table` environment | `table` function | [`table`]($func/table) | | Table | `table` environment | `table` function | [`table`]($func/table) |
| Equation | `$x$`, `align` / `equation` environments | `[$x$]`, `[$ x = y $]` | [`equation`]($func/equation) | | Equation | `$x$`, `align` / `equation` environments | `[$x$]`, `[$ x = y $]` | [`equation`]($func/math.equation) |
[Lists]($func/list) do not rely on environments in Typst. Instead, they have [Lists]($func/list) do not rely on environments in Typst. Instead, they have
lightweight syntax like headings. To create an unordered list (`itemize`), lightweight syntax like headings. To create an unordered list (`itemize`),
@ -144,7 +144,7 @@ And finally a little loop:
``` ```
A function call always involves the name of the function ([`rect`]($func/rect), A function call always involves the name of the function ([`rect`]($func/rect),
[`underline`]($func/underline), [`calc.max`]($category/calc/max), [`underline`]($func/underline), [`calc.max`]($func/calc.max),
[`range`]($func/range)) and then an argument list, even if it is empty. The [`range`]($func/range)) and then an argument list, even if it is empty. The
argument list is enclosed in parentheses. argument list is enclosed in parentheses.
@ -450,7 +450,7 @@ $ delta "if" x <= 5 $
You can type many symbols with shorthands like `<=`, `>=`, and `->`. Similarly, You can type many symbols with shorthands like `<=`, `>=`, and `->`. Similarly,
delimiters will scale automatically for their expressions, just as if `\left` delimiters will scale automatically for their expressions, just as if `\left`
and `\right` commands were implicitly inserted in LaTeX. You can customize and `\right` commands were implicitly inserted in LaTeX. You can customize
delimiter behavior using the [`lr` function]($func/lr). delimiter behavior using the [`lr` function]($func/math.lr).
Typst will automatically set terms around a slash `/` as a fraction while Typst will automatically set terms around a slash `/` as a fraction while
honoring operator precedence. All round parentheses not made redundant by the honoring operator precedence. All round parentheses not made redundant by the
@ -460,7 +460,7 @@ fraction will appear in the output.
$ f(x) = (x + 1) / x $ $ f(x) = (x + 1) / x $
``` ```
[Sub- and superscripts]($func/attach) work similarly in Typst and LaTeX. Typing [Sub- and superscripts]($func/math.attach) work similarly in Typst and LaTeX. Typing
`{$x^2$}` will produce a superscript, `{$x_2$}` yields a subscript. If you want `{$x^2$}` will produce a superscript, `{$x_2$}` yields a subscript. If you want
to include more than one value in a sub- or superscript, enclose their contents to include more than one value in a sub- or superscript, enclose their contents
in parentheses: `{$x_(a -> epsilon)$}`. in parentheses: `{$x_(a -> epsilon)$}`.
@ -477,7 +477,7 @@ $ f(x, y) := cases(
) $ ) $
``` ```
The above example uses the [`cases` function]($func/cases) to describe f. Within The above example uses the [`cases` function]($func/math.cases) to describe f. Within
the cases function, arguments are delimited using commas and the arguments are the cases function, arguments are delimited using commas and the arguments are
also interpreted as math. If you would need to interpret arguments as Typst also interpreted as math. If you would need to interpret arguments as Typst
values instead, prefix them with a `#`: values instead, prefix them with a `#`:
@ -504,7 +504,7 @@ If you'd like to enter your mathematical symbols directly as Unicode, that is
possible, too! possible, too!
Math calls can have two-dimensional argument lists using `;` as a delimiter. The Math calls can have two-dimensional argument lists using `;` as a delimiter. The
most common use for this is the [`mat` function]($func/mat) that creates most common use for this is the [`mat` function]($func/math.mat) that creates
matrices: matrices:
```example ```example

View File

@ -301,11 +301,16 @@ impl<'a> Handler<'a> {
route.push_str("/#methods-"); route.push_str("/#methods-");
route.push_str(method); route.push_str(method);
} else if root == "$func" { } else if root == "$func" {
let mut parts = rest.split('.'); let mut parts = rest.split('.').peekable();
let mut focus = &LIBRARY.global;
while let Some(m) = parts.peek().and_then(|name| module(focus, name).ok()) {
focus = m;
parts.next();
}
let name = parts.next()?; let name = parts.next()?;
let param = parts.next();
let value = let value = focus.get(name).ok()?;
LIBRARY.global.get(name).or_else(|_| LIBRARY.math.get(name)).ok()?;
let Value::Func(func) = value else { return None }; let Value::Func(func) = value else { return None };
let info = func.info()?; let info = func.info()?;
route.push_str(info.category); route.push_str(info.category);
@ -318,18 +323,25 @@ impl<'a> Handler<'a> {
route.push_str(&group.name); route.push_str(&group.name);
route.push_str("/#"); route.push_str("/#");
route.push_str(info.name); route.push_str(info.name);
if let Some(param) = param { if let Some(param) = parts.next() {
route.push_str("-parameters-"); route.push_str("-parameters-");
route.push_str(param); route.push_str(param);
} else {
route.push_str("-summary");
} }
} else { } else {
route.push_str(name); route.push_str(name);
route.push('/'); route.push('/');
if let Some(param) = param { if let Some(next) = parts.next() {
if info.params.iter().any(|param| param.name == next) {
route.push_str("#parameters-"); route.push_str("#parameters-");
route.push_str(param); route.push_str(next);
} else if info.scope.iter().any(|(name, _)| name == next) {
route.push('#');
route.push_str(info.name);
route.push('-');
route.push_str(next);
} else {
return None;
}
} }
} }
} else { } else {

View File

@ -213,7 +213,7 @@ fn category_page(resolver: &dyn Resolver, category: &str) -> PageModel {
let focus = match category { let focus = match category {
"math" => &LIBRARY.math, "math" => &LIBRARY.math,
"calculate" => module(&LIBRARY.global, "calc"), "calculate" => module(&LIBRARY.global, "calc").unwrap(),
_ => &LIBRARY.global, _ => &LIBRARY.global,
}; };
@ -807,7 +807,7 @@ pub struct SymbolModel {
/// Create a page for symbols. /// Create a page for symbols.
fn symbol_page(resolver: &dyn Resolver, parent: &str, name: &str) -> PageModel { fn symbol_page(resolver: &dyn Resolver, parent: &str, name: &str) -> PageModel {
let module = &module(&LIBRARY.global, name); let module = module(&LIBRARY.global, name).unwrap();
let mut list = vec![]; let mut list = vec![];
for (name, value) in module.scope().iter() { for (name, value) in module.scope().iter() {
@ -873,10 +873,10 @@ struct GroupData {
/// Extract a module from another module. /// Extract a module from another module.
#[track_caller] #[track_caller]
fn module<'a>(parent: &'a Module, name: &str) -> &'a Module { fn module<'a>(parent: &'a Module, name: &str) -> Result<&'a Module, String> {
match parent.scope().get(name) { match parent.scope().get(name) {
Some(Value::Module(module)) => module, Some(Value::Module(module)) => Ok(module),
_ => panic!("module doesn't contain module `{name}`"), _ => Err(format!("module doesn't contain module `{name}`")),
} }
} }

View File

@ -17,7 +17,7 @@ as a [function call]($type/function) to an
keyword (or `[#set]` in markup). Only optional parameters of that function can keyword (or `[#set]` in markup). Only optional parameters of that function can
be provided to the set rule. Refer to each function's documentation to see which be provided to the set rule. Refer to each function's documentation to see which
parameters are optional. In the example below, we use two set rules to change parameters are optional. In the example below, we use two set rules to change
the [font family]($func/text.family) and the [font family]($func/text.font) and
[heading numbering]($func/heading.numbering). [heading numbering]($func/heading.numbering).
```example ```example

View File

@ -52,7 +52,7 @@ follows:
| Block-level math | `[$ x^2 $]` | [Math]($category/math) | | Block-level math | `[$ x^2 $]` | [Math]($category/math) |
| Bottom attachment | `[$x_1$]` | [`attach`]($category/math/attach) | | Bottom attachment | `[$x_1$]` | [`attach`]($category/math/attach) |
| Top attachment | `[$x^2$]` | [`attach`]($category/math/attach) | | Top attachment | `[$x^2$]` | [`attach`]($category/math/attach) |
| Fraction | `[$1 + (a+b)/5$]` | [`frac`]($func/frac) | | Fraction | `[$1 + (a+b)/5$]` | [`frac`]($func/math.frac) |
| Line break | `[$x \ y$]` | [`linebreak`]($func/linebreak) | | Line break | `[$x \ y$]` | [`linebreak`]($func/linebreak) |
| Alignment point | `[$x &= 2 \ &= 3$]` | [Math]($category/math) | | Alignment point | `[$x &= 2 \ &= 3$]` | [Math]($category/math) |
| Variable access | `[$#x$, $pi$]` | [Math]($category/math) | | Variable access | `[$#x$, $pi$]` | [Math]($category/math) |
@ -71,7 +71,7 @@ Within code blocks and expressions, new expressions can start without a leading
a table listing all syntax that is available in code mode: a table listing all syntax that is available in code mode:
| Name | Example | See | | Name | Example | See |
| ------------------------ | ----------------------------- | ---------------------------------------------------- | | ------------------------ | ----------------------------- | ---------------------------------- |
| Variable access | `{x}` | [Scripting]($scripting/#blocks) | | Variable access | `{x}` | [Scripting]($scripting/#blocks) |
| Any literal | `{1pt, "hey"}` | [Types]($types) | | Any literal | `{1pt, "hey"}` | [Types]($types) |
| Code block | `{{ let x = 1; x + 2 }}` | [Scripting]($scripting/#blocks) | | Code block | `{{ let x = 1; x + 2 }}` | [Scripting]($scripting/#blocks) |

View File

@ -269,17 +269,17 @@ $ 7.32 beta +
Not all math constructs have special syntax. Instead, we use functions, just Not all math constructs have special syntax. Instead, we use functions, just
like the `image` function we have seen before. For example, to insert a column like the `image` function we have seen before. For example, to insert a column
vector, we can use the [`vec`]($func/vec) function. Within math mode, function vector, we can use the [`vec`]($func/math.vec) function. Within math mode,
calls don't need to start with the `#` character. function calls don't need to start with the `#` character.
```example ```example
$ v := vec(x_1, x_2, x_3) $ $ v := vec(x_1, x_2, x_3) $
``` ```
Some functions are only available within math mode. For example, the Some functions are only available within math mode. For example, the
[`cal`]($func/cal) function is used to typeset calligraphic letters commonly [`cal`]($func/math.cal) function is used to typeset calligraphic letters
used for sets. The [math section of the reference]($category/math) provides a commonly used for sets. The [math section of the reference]($category/math)
complete list of all functions that math mode makes available. provides a complete list of all functions that math mode makes available.
One more thing: Many symbols, such as the arrow, have a lot of variants. You can One more thing: Many symbols, such as the arrow, have a lot of variants. You can
select among these variants by appending a dot and a modifier name to a symbol's select among these variants by appending a dot and a modifier name to a symbol's

View File

@ -11,10 +11,11 @@ use crate::text::TextElem;
/// [cite]($func/cite) from a bibliography. /// [cite]($func/cite) from a bibliography.
/// ///
/// Referenceable elements include [headings]($func/heading), /// Referenceable elements include [headings]($func/heading),
/// [figures]($func/figure), and [equations]($func/equation). To create a custom /// [figures]($func/figure), and [equations]($func/math.equation). To create a
/// referenceable element like a theorem, you can create a figure of a custom /// custom referenceable element like a theorem, you can create a figure of a
/// [`kind`]($func/figure.kind) and write a show rule for it. In the future, /// custom [`kind`]($func/figure.kind) and write a show rule for it. In the
/// there might be a more direct way to define a custom referenceable element. /// future, there might be a more direct way to define a custom referenceable
/// element.
/// ///
/// If you just want to link to a labelled element and not get an automatic /// If you just want to link to a labelled element and not get an automatic
/// textual reference, consider using the [`link`]($func/link) function instead. /// textual reference, consider using the [`link`]($func/link) function instead.