feat: add alt parameter to math.equation

This commit is contained in:
Tobias Schmitz 2025-07-18 15:55:56 +02:00
parent d2105dcc35
commit 9649def108
No known key found for this signature in database
4 changed files with 9 additions and 5 deletions

View File

@ -1,6 +1,7 @@
use std::num::NonZeroUsize; use std::num::NonZeroUsize;
use codex::styling::MathVariant; use codex::styling::MathVariant;
use ecow::EcoString;
use typst_utils::NonZeroExt; use typst_utils::NonZeroExt;
use unicode_math_class::MathClass; use unicode_math_class::MathClass;
@ -47,6 +48,9 @@ use crate::text::{FontFamily, FontList, FontWeight, LocalName, TextElem};
/// [main math page]($category/math). /// [main math page]($category/math).
#[elem(Locatable, Synthesize, ShowSet, Count, LocalName, Refable, Outlinable)] #[elem(Locatable, Synthesize, ShowSet, Count, LocalName, Refable, Outlinable)]
pub struct EquationElem { pub struct EquationElem {
/// An alternative description of the mathematical equation.
pub alt: Option<EcoString>,
/// Whether the equation is displayed as a separate block. /// Whether the equation is displayed as a separate block.
#[default(false)] #[default(false)]
pub block: bool, pub block: bool,

View File

@ -88,7 +88,7 @@ use crate::text::{LocalName, TextElem};
/// generated. /// generated.
#[elem(Locatable)] #[elem(Locatable)]
pub struct LinkElem { pub struct LinkElem {
/// A text describing the link. /// An alternative description of the link.
pub alt: Option<EcoString>, pub alt: Option<EcoString>,
/// The destination the link points to. /// The destination the link points to.

View File

@ -124,7 +124,7 @@ pub struct ImageElem {
/// The height of the image. /// The height of the image.
pub height: Sizing, pub height: Sizing,
/// A text describing the image. /// An alternative description of the image.
pub alt: Option<EcoString>, pub alt: Option<EcoString>,
/// How the image should adjust itself to a given area (the area is defined /// How the image should adjust itself to a given area (the area is defined

View File

@ -123,9 +123,9 @@ pub(crate) fn handle_start(
} else { } else {
TagKind::Figure.with_alt_text(alt) TagKind::Figure.with_alt_text(alt)
} }
} else if let Some(_) = elem.to_packed::<EquationElem>() { } else if let Some(equation) = elem.to_packed::<EquationElem>() {
// TODO: alt text let alt = equation.alt.get_as_ref().map(|s| s.to_string());
TagKind::Formula.into() TagKind::Formula.with_alt_text(alt)
} else if let Some(table) = elem.to_packed::<TableElem>() { } else if let Some(table) = elem.to_packed::<TableElem>() {
let table_id = gc.tags.next_table_id(); let table_id = gc.tags.next_table_id();
let summary = table.summary.get_as_ref().map(|s| s.to_string()); let summary = table.summary.get_as_ref().map(|s| s.to_string());