mirror of
https://github.com/typst/typst
synced 2025-07-27 22:37:54 +08:00
Compare commits
7 Commits
b6bb74187e
...
3ee83fa3c1
Author | SHA1 | Date | |
---|---|---|---|
|
3ee83fa3c1 | ||
|
b1c79b50d4 | ||
|
4629ede020 | ||
|
25ad4f7d41 | ||
|
c4d7faf527 | ||
|
ec3c058220 | ||
|
a3c2489eb6 |
@ -173,8 +173,11 @@ typst help
|
|||||||
typst help watch
|
typst help watch
|
||||||
```
|
```
|
||||||
|
|
||||||
If you prefer an integrated IDE-like experience with autocompletion and instant
|
If you prefer an integrated IDE-like experience with autocompletion and instant
|
||||||
preview, you can also check out [Typst's free web app][app].
|
preview, you can also check out our [free web app][app]. Alternatively, there is
|
||||||
|
a community-created language server called
|
||||||
|
[Tinymist](https://myriad-dreamin.github.io/tinymist/) which is integrated into
|
||||||
|
various editor extensions.
|
||||||
|
|
||||||
## Community
|
## Community
|
||||||
The main places where the community gathers are our [Forum][forum] and our
|
The main places where the community gathers are our [Forum][forum] and our
|
||||||
|
@ -31,6 +31,12 @@ use crate::World;
|
|||||||
/// Displays the text verbatim and in a monospace font. This is typically used
|
/// Displays the text verbatim and in a monospace font. This is typically used
|
||||||
/// to embed computer code into your document.
|
/// to embed computer code into your document.
|
||||||
///
|
///
|
||||||
|
/// Note that text given to this element cannot contain arbitrary formatting,
|
||||||
|
/// such as `[*strong*]` or `[_emphasis_]`, as it is displayed verbatim. If
|
||||||
|
/// you'd like to display any kind of content with a monospace font, instead of
|
||||||
|
/// using [`raw`], you should change its font to a monospace font using the
|
||||||
|
/// [`text`]($text) function.
|
||||||
|
///
|
||||||
/// # Example
|
/// # Example
|
||||||
/// ````example
|
/// ````example
|
||||||
/// Adding `rbx` to `rcx` gives
|
/// Adding `rbx` to `rcx` gives
|
||||||
@ -57,6 +63,38 @@ use crate::World;
|
|||||||
/// #raw("fn " + "main() {}", lang: "rust")
|
/// #raw("fn " + "main() {}", lang: "rust")
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
|
/// # Styling
|
||||||
|
/// By default, the `raw` element uses the `DejaVu Sans Mono` font, available
|
||||||
|
/// by default in Typst, with a smaller font size of `0.8em` (that is, 80% of
|
||||||
|
/// the global font size). This is because monospace fonts tend to be visually
|
||||||
|
/// larger than non-monospace fonts.
|
||||||
|
///
|
||||||
|
/// You can customize these properties with show-set rules:
|
||||||
|
///
|
||||||
|
/// ````example
|
||||||
|
/// // Switch to Cascadia Code for
|
||||||
|
/// // both inline and block raw.
|
||||||
|
/// #show raw: set text(font: "Cascadia Code")
|
||||||
|
///
|
||||||
|
/// // Make raw blocks 20% larger than their default size.
|
||||||
|
/// // Keep inline raw at the same size.
|
||||||
|
/// #show raw.where(block: true): set text(1.2em)
|
||||||
|
///
|
||||||
|
/// Now using the `Cascadia Code` font for raw text.
|
||||||
|
/// Here's some Python code. It looks larger now:
|
||||||
|
///
|
||||||
|
/// ```py
|
||||||
|
/// def python():
|
||||||
|
/// return 5 + 5
|
||||||
|
/// ```
|
||||||
|
/// ````
|
||||||
|
///
|
||||||
|
/// In addition, you can customize the syntax highlighting colors by setting
|
||||||
|
/// a custom theme through the [`theme`]($raw.theme) field.
|
||||||
|
///
|
||||||
|
/// For complete customization of the appearance of a raw block, a show rule
|
||||||
|
/// on [`raw.line`]($raw.line) could be helpful, such as to add line numbers.
|
||||||
|
///
|
||||||
/// # Syntax
|
/// # Syntax
|
||||||
/// This function also has dedicated syntax. You can enclose text in 1 or 3+
|
/// This function also has dedicated syntax. You can enclose text in 1 or 3+
|
||||||
/// backticks (`` ` ``) to make it raw. Two backticks produce empty raw text.
|
/// backticks (`` ` ``) to make it raw. Two backticks produce empty raw text.
|
||||||
@ -73,6 +111,10 @@ use crate::World;
|
|||||||
/// needed, start the text with a single space (which will be trimmed) or use
|
/// needed, start the text with a single space (which will be trimmed) or use
|
||||||
/// the single backtick syntax. If your text should start or end with a
|
/// the single backtick syntax. If your text should start or end with a
|
||||||
/// backtick, put a space before or after it (it will be trimmed).
|
/// backtick, put a space before or after it (it will be trimmed).
|
||||||
|
///
|
||||||
|
/// If no syntax highlighting is available by default for your specified
|
||||||
|
/// language tag, you may provide a custom syntax specification file to the
|
||||||
|
/// [`syntaxes`]($raw.syntaxes) field.
|
||||||
#[elem(
|
#[elem(
|
||||||
scope,
|
scope,
|
||||||
title = "Raw Text / Code",
|
title = "Raw Text / Code",
|
||||||
|
@ -797,7 +797,9 @@ impl Color {
|
|||||||
components
|
components
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the constructor function for this color's space:
|
/// Returns the constructor function for this color's space.
|
||||||
|
///
|
||||||
|
/// Returns one of:
|
||||||
/// - [`luma`]($color.luma)
|
/// - [`luma`]($color.luma)
|
||||||
/// - [`oklab`]($color.oklab)
|
/// - [`oklab`]($color.oklab)
|
||||||
/// - [`oklch`]($color.oklch)
|
/// - [`oklch`]($color.oklch)
|
||||||
|
@ -75,21 +75,23 @@ Emphasis (usually rendered as italic text) is expressed by enclosing text in
|
|||||||
Here is a list of common markup commands used in LaTeX and their Typst
|
Here is a list of common markup commands used in LaTeX and their Typst
|
||||||
equivalents. You can also check out the [full syntax cheat sheet]($syntax).
|
equivalents. You can also check out the [full syntax cheat sheet]($syntax).
|
||||||
|
|
||||||
| Element | LaTeX | Typst | See |
|
| Element | LaTeX | Typst | See |
|
||||||
|:-----------------|:--------------------------|:-----------------------|:-----------|
|
|:-----------------------|:--------------------------|:-----------------------|:-----------|
|
||||||
| Strong emphasis | `\textbf{strong}` | `[*strong*]` | [`strong`] |
|
| Strong emphasis | `\textbf{strong}` | `[*strong*]` | [`strong`] |
|
||||||
| Emphasis | `\emph{emphasis}` | `[_emphasis_]` | [`emph`] |
|
| Emphasis | `\emph{emphasis}` | `[_emphasis_]` | [`emph`] |
|
||||||
| Monospace / code | `\texttt{print(1)}` | ``[`print(1)`]`` | [`raw`] |
|
| Link | `\url{https://typst.app}` | `[https://typst.app/]` | [`link`] |
|
||||||
| Link | `\url{https://typst.app}` | `[https://typst.app/]` | [`link`] |
|
| Label | `\label{intro}` | `[<intro>]` | [`label`] |
|
||||||
| Label | `\label{intro}` | `[<intro>]` | [`label`] |
|
| Reference | `\ref{intro}` | `[@intro]` | [`ref`] |
|
||||||
| Reference | `\ref{intro}` | `[@intro]` | [`ref`] |
|
| Citation | `\cite{humphrey97}` | `[@humphrey97]` | [`cite`] |
|
||||||
| Citation | `\cite{humphrey97}` | `[@humphrey97]` | [`cite`] |
|
| Verbatim / code | `\verb|print(f"{x}")|`, `verbatim` / `listing` environments | ``[`print(f"{x}")`]`` | [`raw`] |
|
||||||
| Bullet list | `itemize` environment | `[- List]` | [`list`] |
|
| Monospace / typewriter | `\texttt{mono}` | ``[`mono`]`` or `text` function | [`raw`], [`text`] |
|
||||||
| Numbered list | `enumerate` environment | `[+ List]` | [`enum`] |
|
| Verbatim | `verbatim` environment | ``[`#typst-code()`]`` | [`raw`] |
|
||||||
| Term list | `description` environment | `[/ Term: List]` | [`terms`] |
|
| Bullet list | `itemize` environment | `[- List]` | [`list`] |
|
||||||
| Figure | `figure` environment | `figure` function | [`figure`] |
|
| Numbered list | `enumerate` environment | `[+ List]` | [`enum`] |
|
||||||
| Table | `table` environment | `table` function | [`table`] |
|
| Term list | `description` environment | `[/ Term: List]` | [`terms`] |
|
||||||
| Equation | `$x$`, `align` / `equation` environments | `[$x$]`, `[$ x = y $]` | [`equation`]($math.equation) |
|
| Figure | `figure` environment | `figure` function | [`figure`] |
|
||||||
|
| Table | `table` environment | `table` function | [`table`] |
|
||||||
|
| Equation | `$x$`, `align` / `equation` environments | `[$x$]`, `[$ x = y $]` | [`equation`]($math.equation) |
|
||||||
|
|
||||||
[Lists]($list) do not rely on environments in Typst. Instead, they have
|
[Lists]($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`),
|
||||||
@ -121,6 +123,16 @@ To get a [numbered list]($enum) (`enumerate`) instead, use a `+` instead of the
|
|||||||
hyphen. For a [term list]($terms) (`description`), write `[/ Term: Description]`
|
hyphen. For a [term list]($terms) (`description`), write `[/ Term: Description]`
|
||||||
instead.
|
instead.
|
||||||
|
|
||||||
|
Regarding the usage of monospace fonts (also known as "typewriter" font style
|
||||||
|
in LaTeX), it should be noted that using [`raw`] such as in
|
||||||
|
``[`monospace`]`` (where you'd use `\texttt{monospace}` in LaTeX) works for
|
||||||
|
most cases where you only have simple text. If you need to use formatting, such
|
||||||
|
as in `\texttt{monospace \textbf{bold}}`, you will need to replicate its look by
|
||||||
|
switch to changing the text font to a monospace font with
|
||||||
|
`#text(font: "DejaVu Sans Mono", size: 0.8em)[monospace *bold*]`, for example,
|
||||||
|
since `raw` only supports verbatim (unformatted) text. See its documentation
|
||||||
|
for more details.
|
||||||
|
|
||||||
## How do I use a command? { #commands }
|
## How do I use a command? { #commands }
|
||||||
LaTeX heavily relies on commands (prefixed by backslashes). It uses these
|
LaTeX heavily relies on commands (prefixed by backslashes). It uses these
|
||||||
_macros_ to affect the typesetting process and to insert and manipulate content.
|
_macros_ to affect the typesetting process and to insert and manipulate content.
|
||||||
|
@ -242,7 +242,7 @@ fn category_page(resolver: &dyn Resolver, category: Category) -> PageModel {
|
|||||||
items.push(CategoryItem {
|
items.push(CategoryItem {
|
||||||
name: group.name.clone(),
|
name: group.name.clone(),
|
||||||
route: subpage.route.clone(),
|
route: subpage.route.clone(),
|
||||||
oneliner: oneliner(docs).into(),
|
oneliner: oneliner(docs),
|
||||||
code: true,
|
code: true,
|
||||||
});
|
});
|
||||||
children.push(subpage);
|
children.push(subpage);
|
||||||
@ -296,7 +296,7 @@ fn category_page(resolver: &dyn Resolver, category: Category) -> PageModel {
|
|||||||
items.push(CategoryItem {
|
items.push(CategoryItem {
|
||||||
name: name.into(),
|
name: name.into(),
|
||||||
route: subpage.route.clone(),
|
route: subpage.route.clone(),
|
||||||
oneliner: oneliner(func.docs().unwrap_or_default()).into(),
|
oneliner: oneliner(func.docs().unwrap_or_default()),
|
||||||
code: true,
|
code: true,
|
||||||
});
|
});
|
||||||
children.push(subpage);
|
children.push(subpage);
|
||||||
@ -306,7 +306,7 @@ fn category_page(resolver: &dyn Resolver, category: Category) -> PageModel {
|
|||||||
items.push(CategoryItem {
|
items.push(CategoryItem {
|
||||||
name: ty.short_name().into(),
|
name: ty.short_name().into(),
|
||||||
route: subpage.route.clone(),
|
route: subpage.route.clone(),
|
||||||
oneliner: oneliner(ty.docs()).into(),
|
oneliner: oneliner(ty.docs()),
|
||||||
code: true,
|
code: true,
|
||||||
});
|
});
|
||||||
children.push(subpage);
|
children.push(subpage);
|
||||||
@ -637,7 +637,7 @@ fn group_page(
|
|||||||
let item = CategoryItem {
|
let item = CategoryItem {
|
||||||
name: group.name.clone(),
|
name: group.name.clone(),
|
||||||
route: model.route.clone(),
|
route: model.route.clone(),
|
||||||
oneliner: oneliner(&group.details).into(),
|
oneliner: oneliner(&group.details),
|
||||||
code: false,
|
code: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -772,8 +772,24 @@ pub fn urlify(title: &str) -> EcoString {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Extract the first line of documentation.
|
/// Extract the first line of documentation.
|
||||||
fn oneliner(docs: &str) -> &str {
|
fn oneliner(docs: &str) -> EcoString {
|
||||||
docs.lines().next().unwrap_or_default()
|
let paragraph = docs.split("\n\n").next().unwrap_or_default();
|
||||||
|
let mut depth = 0;
|
||||||
|
let mut period = false;
|
||||||
|
let mut end = paragraph.len();
|
||||||
|
for (i, c) in paragraph.char_indices() {
|
||||||
|
match c {
|
||||||
|
'(' | '[' | '{' => depth += 1,
|
||||||
|
')' | ']' | '}' => depth -= 1,
|
||||||
|
'.' if depth == 0 => period = true,
|
||||||
|
c if period && c.is_whitespace() && !docs[..i].ends_with("e.g.") => {
|
||||||
|
end = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
_ => period = false,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
EcoString::from(&docs[..end]).replace("\r\n", " ").replace("\n", " ")
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The order of types in the documentation.
|
/// The order of types in the documentation.
|
||||||
|
@ -86,7 +86,7 @@ pub struct FuncModel {
|
|||||||
pub name: EcoString,
|
pub name: EcoString,
|
||||||
pub title: &'static str,
|
pub title: &'static str,
|
||||||
pub keywords: &'static [&'static str],
|
pub keywords: &'static [&'static str],
|
||||||
pub oneliner: &'static str,
|
pub oneliner: EcoString,
|
||||||
pub element: bool,
|
pub element: bool,
|
||||||
pub contextual: bool,
|
pub contextual: bool,
|
||||||
pub deprecation: Option<&'static str>,
|
pub deprecation: Option<&'static str>,
|
||||||
@ -139,7 +139,7 @@ pub struct TypeModel {
|
|||||||
pub name: &'static str,
|
pub name: &'static str,
|
||||||
pub title: &'static str,
|
pub title: &'static str,
|
||||||
pub keywords: &'static [&'static str],
|
pub keywords: &'static [&'static str],
|
||||||
pub oneliner: &'static str,
|
pub oneliner: EcoString,
|
||||||
pub details: Html,
|
pub details: Html,
|
||||||
pub constructor: Option<FuncModel>,
|
pub constructor: Option<FuncModel>,
|
||||||
pub scope: Vec<FuncModel>,
|
pub scope: Vec<FuncModel>,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user