Compare commits

...

6 Commits

Author SHA1 Message Date
PgBiel
3ea05056ef
Merge 25ad4f7d419b5d2798645a565138c97c65c0eab6 into e9f1b5825a9d37ca0c173a7b2830ba36a27ca9e0 2025-07-25 00:37:51 +08:00
Laurenz
e9f1b5825a
Lint for iterations over hash types (#6652) 2025-07-24 11:34:08 +00:00
PgBiel
25ad4f7d41 mention typewriter font in LaTeX guide 2025-03-04 18:00:47 -03:00
PgBiel
c4d7faf527 laurenz review adjustments 2025-03-04 17:18:46 -03:00
PgBiel
ec3c058220
use markup highlighting
Co-authored-by: Malo <57839069+MDLC01@users.noreply.github.com>
2025-03-04 16:53:53 -03:00
PgBiel
a3c2489eb6 improve raw docs 2025-03-03 21:19:59 -03:00
5 changed files with 72 additions and 15 deletions

View File

@ -159,6 +159,7 @@ strip = true
[workspace.lints.clippy] [workspace.lints.clippy]
blocks_in_conditions = "allow" blocks_in_conditions = "allow"
comparison_chain = "allow" comparison_chain = "allow"
iter_over_hash_type = "warn"
manual_range_contains = "allow" manual_range_contains = "allow"
mutable_key_type = "allow" mutable_key_type = "allow"
uninlined_format_args = "warn" uninlined_format_args = "warn"

View File

@ -139,6 +139,7 @@ impl Watcher {
fn update(&mut self, iter: impl IntoIterator<Item = PathBuf>) -> StrResult<()> { fn update(&mut self, iter: impl IntoIterator<Item = PathBuf>) -> StrResult<()> {
// Mark all files as not "seen" so that we may unwatch them if they // Mark all files as not "seen" so that we may unwatch them if they
// aren't in the dependency list. // aren't in the dependency list.
#[allow(clippy::iter_over_hash_type, reason = "order does not matter")]
for seen in self.watched.values_mut() { for seen in self.watched.values_mut() {
*seen = false; *seen = false;
} }

View File

@ -173,6 +173,7 @@ impl SystemWorld {
/// Reset the compilation state in preparation of a new compilation. /// Reset the compilation state in preparation of a new compilation.
pub fn reset(&mut self) { pub fn reset(&mut self) {
#[allow(clippy::iter_over_hash_type, reason = "order does not matter")]
for slot in self.slots.get_mut().values_mut() { for slot in self.slots.get_mut().values_mut() {
slot.reset(); slot.reset();
} }

View File

@ -31,6 +31,12 @@ use crate::visualize::Color;
/// 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::visualize::Color;
/// #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::visualize::Color;
/// 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",

View File

@ -76,14 +76,16 @@ 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`] |
| Monospace / typewriter | `\texttt{mono}` | ``[`mono`]`` or `text` function | [`raw`], [`text`] |
| Verbatim | `verbatim` environment | ``[`#typst-code()`]`` | [`raw`] |
| Bullet list | `itemize` environment | `[- List]` | [`list`] | | Bullet list | `itemize` environment | `[- List]` | [`list`] |
| Numbered list | `enumerate` environment | `[+ List]` | [`enum`] | | Numbered list | `enumerate` environment | `[+ List]` | [`enum`] |
| Term list | `description` environment | `[/ Term: List]` | [`terms`] | | Term list | `description` environment | `[/ Term: List]` | [`terms`] |
@ -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.