Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

# [0.7.1] - 2024-11-18

## Added

- Added support for `equation` and `equation*` environments.

# [0.7.0] - 2024-10-10

## Fixed
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "pulldown-latex"
version = "0.7.0"
version = "0.7.1"
authors = ["Charles Edward Gagnon"]
edition = "2021"
description = "Pull parser to convert LaTeX equations to MathML"
Expand Down
22 changes: 20 additions & 2 deletions src/mathml.rs
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,14 @@
self.writer.write_all(b"><mtd>")?;
EnvGrouping::Split { used_align: false }
}
Grouping::Equation { .. } => todo!(),
Grouping::Equation { eq_numbers } => {
self.writer.write_all(b"<mtable")?;
if eq_numbers {
self.writer.write_all(b" class=\"menv-with-eqn\"")?;
}
self.writer.write_all(b"><mtr><mtd>")?;
EnvGrouping::Equation
}
};
self.env_stack.push(Environment::from(env_group));
Ok(())
Expand Down Expand Up @@ -349,6 +356,7 @@
| EnvGrouping::SubArray
| EnvGrouping::Gather
| EnvGrouping::Multline
| EnvGrouping::Equation
| EnvGrouping::Split { .. }
| EnvGrouping::Alignat { .. } => {
self.writer.write_all(b"</mtd></mtr></mtable>")
Expand Down Expand Up @@ -453,13 +461,22 @@
spacing,
horizontal_lines,
})) => {
*self.state_stack.last_mut().expect("state stack is empty") = State::default();
*self
.state_stack
.last_mut()
.expect("state stack should not be empty") = State::default();
self.previous_atom = None;

if let Some(Environment::Group(EnvGrouping::Array { cols, cols_index })) =
self.env_stack.last()
{
array_close_line(&mut self.writer, &cols[*cols_index..])?;
} else if let Some(Environment::Group(EnvGrouping::Equation { .. })) =
self.env_stack.last()
{
// LaTeX does _nothing_ when a newline is encountered in an eqution, we do the
// same thing.
return Ok(());

Check warning on line 479 in src/mathml.rs

View check run for this annotation

Codecov / codecov/patch

src/mathml.rs#L479

Added line #L479 was not covered by tests
} else {
self.writer.write_all(b"</mtd></mtr><mtr")?;
}
Expand Down Expand Up @@ -1098,6 +1115,7 @@
Split {
used_align: bool,
},
Equation,
}

#[derive(Debug, Clone, PartialEq)]
Expand Down
4 changes: 2 additions & 2 deletions src/parser/primitives.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1668,12 +1668,12 @@ impl<'b, 'store> InnerParser<'b, 'store> {
}
"equation" => (
G::Equation { eq_numbers: true },
u16::MAX,
0,
GroupingKind::Equation { eq_numbers: true },
),
"equation*" => (
G::Equation { eq_numbers: false },
u16::MAX,
0,
GroupingKind::Equation { eq_numbers: false },
),
"align" => (
Expand Down
9 changes: 9 additions & 0 deletions tests/cross-browser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,15 @@ round_trip! {
d + e + f
\end{split}"#,
}
round_trip! {
equation,
r#"\begin{equation}
a = b + c
\end{equation}"#,
r#"\begin{equation*}
a = b + c
\end{equation*}"#,
}
round_trip_display! {
colors,
r"\fcolorbox{red}{blue}{\textcolor{white}{a + b = c}}"
Expand Down
Loading