mirror of
https://github.com/typst/typst
synced 2025-05-14 04:56:26 +08:00
Switch to New Computer Modern Math
This commit is contained in:
parent
3965e10281
commit
5a7c901f21
2
Cargo.lock
generated
2
Cargo.lock
generated
@ -862,7 +862,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "rex"
|
name = "rex"
|
||||||
version = "0.1.2"
|
version = "0.1.2"
|
||||||
source = "git+https://github.com/laurmaedje/ReX#b44e59bfa68cc4b0288bd2be80e093ed3b279af5"
|
source = "git+https://github.com/laurmaedje/ReX#7362b0cbb229211d6206198d80382a9b23eda993"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"font",
|
"font",
|
||||||
"unicode-math",
|
"unicode-math",
|
||||||
|
2
NOTICE
2
NOTICE
@ -460,6 +460,8 @@ The GUST Font License Version 1.0 applies to:
|
|||||||
* Latin Modern fonts in fonts/LatinModern*.otf
|
* Latin Modern fonts in fonts/LatinModern*.otf
|
||||||
(http://www.gust.org.pl/projects/e-foundry/lm-math)
|
(http://www.gust.org.pl/projects/e-foundry/lm-math)
|
||||||
|
|
||||||
|
* NewComputerModern fonts in fonts/NewCM*.otf
|
||||||
|
|
||||||
% This is version 1.0, dated 22 June 2009, of the GUST Font License.
|
% This is version 1.0, dated 22 June 2009, of the GUST Font License.
|
||||||
% (GUST is the Polish TeX Users Group, http://www.gust.org.pl)
|
% (GUST is the Polish TeX Users Group, http://www.gust.org.pl)
|
||||||
%
|
%
|
||||||
|
Binary file not shown.
BIN
fonts/NewCMMath-Regular.otf
Normal file
BIN
fonts/NewCMMath-Regular.otf
Normal file
Binary file not shown.
@ -20,7 +20,7 @@ pub struct MathNode {
|
|||||||
impl MathNode {
|
impl MathNode {
|
||||||
/// The math font family.
|
/// The math font family.
|
||||||
#[property(referenced)]
|
#[property(referenced)]
|
||||||
pub const FAMILY: FontFamily = FontFamily::new("Latin Modern Math");
|
pub const FAMILY: FontFamily = FontFamily::new("NewComputerModernMath");
|
||||||
/// The spacing above display math.
|
/// The spacing above display math.
|
||||||
#[property(resolve, shorthand(around))]
|
#[property(resolve, shorthand(around))]
|
||||||
pub const ABOVE: Option<BlockSpacing> = Some(Ratio::one().into());
|
pub const ABOVE: Option<BlockSpacing> = Some(Ratio::one().into());
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
|
use rex::error::{Error, LayoutError};
|
||||||
use rex::font::{FontContext, MathFont};
|
use rex::font::{FontContext, MathFont};
|
||||||
use rex::layout::{LayoutSettings, Style};
|
use rex::layout::{LayoutSettings, Style};
|
||||||
use rex::parser::color::RGBA;
|
use rex::parser::color::RGBA;
|
||||||
use rex::render::{Backend, Cursor, Renderer};
|
use rex::render::{Backend, Cursor, Renderer};
|
||||||
use rex::error::{Error, LayoutError};
|
|
||||||
|
|
||||||
use crate::font::FaceId;
|
use crate::font::FaceId;
|
||||||
use crate::library::prelude::*;
|
use crate::library::prelude::*;
|
||||||
@ -27,30 +27,33 @@ impl Layout for RexNode {
|
|||||||
styles: StyleChain,
|
styles: StyleChain,
|
||||||
) -> TypResult<Vec<Arc<Frame>>> {
|
) -> TypResult<Vec<Arc<Frame>>> {
|
||||||
// Load the font.
|
// Load the font.
|
||||||
let face_id = match ctx.fonts.select(self.family.as_str(), variant(styles)) {
|
let span = self.tex.span;
|
||||||
Some(id) => id,
|
let face_id = ctx
|
||||||
None => return Ok(vec![]),
|
.fonts
|
||||||
};
|
.select(self.family.as_str(), variant(styles))
|
||||||
|
.ok_or("failed to find math font")
|
||||||
|
.at(span)?;
|
||||||
|
|
||||||
// Prepare the font.
|
// Prepare the font.
|
||||||
let data = ctx.fonts.get(face_id).buffer();
|
let data = ctx.fonts.get(face_id).buffer();
|
||||||
let font = match MathFont::parse(data) {
|
let font = MathFont::parse(data)
|
||||||
Ok(font) => font,
|
.map_err(|_| "failed to parse math font")
|
||||||
Err(_) => return Ok(vec![]),
|
.at(span)?;
|
||||||
};
|
|
||||||
|
let ctx = FontContext::new(&font).ok_or("failed to parse math font").at(span)?;
|
||||||
|
|
||||||
// Layout the formula.
|
// Layout the formula.
|
||||||
let ctx = FontContext::new(&font);
|
|
||||||
let em = styles.get(TextNode::SIZE);
|
let em = styles.get(TextNode::SIZE);
|
||||||
let style = if self.display { Style::Display } else { Style::Text };
|
let style = if self.display { Style::Display } else { Style::Text };
|
||||||
let settings = LayoutSettings::new(&ctx, em.to_pt(), style);
|
let settings = LayoutSettings::new(&ctx, em.to_pt(), style);
|
||||||
let renderer = Renderer::new();
|
let renderer = Renderer::new();
|
||||||
let layout = renderer.layout(&self.tex.v, settings)
|
let layout = renderer
|
||||||
|
.layout(&self.tex.v, settings)
|
||||||
.map_err(|err| match err {
|
.map_err(|err| match err {
|
||||||
Error::Parse(err) => err.to_string(),
|
Error::Parse(err) => err.to_string(),
|
||||||
Error::Layout(LayoutError::Font(err)) => err.to_string(),
|
Error::Layout(LayoutError::Font(err)) => err.to_string(),
|
||||||
})
|
})
|
||||||
.at(self.tex.span)?;
|
.at(span)?;
|
||||||
|
|
||||||
// Determine the metrics.
|
// Determine the metrics.
|
||||||
let (x0, y0, x1, y1) = renderer.size(&layout);
|
let (x0, y0, x1, y1) = renderer.size(&layout);
|
||||||
|
Binary file not shown.
Before Width: | Height: | Size: 55 KiB After Width: | Height: | Size: 55 KiB |
Binary file not shown.
Before Width: | Height: | Size: 5.8 KiB After Width: | Height: | Size: 6.4 KiB |
Binary file not shown.
Before Width: | Height: | Size: 21 KiB After Width: | Height: | Size: 19 KiB |
@ -23,7 +23,7 @@
|
|||||||
[X]
|
[X]
|
||||||
}
|
}
|
||||||
|
|
||||||
#set text("Latin Modern Math", size)
|
#set text("Latin Modern Roman", size)
|
||||||
Neither #tex, \
|
Neither #tex, \
|
||||||
nor #xetex!
|
nor #xetex!
|
||||||
|
|
||||||
|
@ -11,6 +11,10 @@ $[ a^2 + b^2 = c^2 ]$
|
|||||||
Prove by induction:
|
Prove by induction:
|
||||||
$[ \sum_{k=0}^n k = \frac{n(n+1)}{2} ]$
|
$[ \sum_{k=0}^n k = \frac{n(n+1)}{2} ]$
|
||||||
|
|
||||||
|
---
|
||||||
|
// Test that blackboard style looks nice.
|
||||||
|
$[ f: \mathbb{N} \rightarrow \mathbb{R} ]$
|
||||||
|
|
||||||
---
|
---
|
||||||
// Error: 1-10 expected '}' found EOF
|
// Error: 1-10 expected '}' found EOF
|
||||||
$\sqrt{x$
|
$\sqrt{x$
|
||||||
|
@ -24,9 +24,6 @@
|
|||||||
// Emoji.
|
// Emoji.
|
||||||
Emoji: 🐪, 🌋, 🏞
|
Emoji: 🐪, 🌋, 🏞
|
||||||
|
|
||||||
// Math.
|
|
||||||
#text("Latin Modern Math")[∫ 𝛼 + 3𝛽 d𝑡]
|
|
||||||
|
|
||||||
// Colors.
|
// Colors.
|
||||||
[
|
[
|
||||||
#set text(fill: eastern)
|
#set text(fill: eastern)
|
||||||
@ -34,7 +31,7 @@ Emoji: 🐪, 🌋, 🏞
|
|||||||
]
|
]
|
||||||
|
|
||||||
// Disable font fallback beyond the user-specified list.
|
// Disable font fallback beyond the user-specified list.
|
||||||
// Without disabling, Latin Modern Math would come to the rescue.
|
// Without disabling, NewComputerModernMath would come to the rescue.
|
||||||
#set text("PT Sans", "Twitter Color Emoji", fallback: false)
|
#set text("PT Sans", "Twitter Color Emoji", fallback: false)
|
||||||
2π = 𝛼 + 𝛽. ✅
|
2π = 𝛼 + 𝛽. ✅
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user