Switch to New Computer Modern Math

This commit is contained in:
Laurenz 2022-05-19 12:59:39 +02:00
parent 3965e10281
commit 5a7c901f21
12 changed files with 25 additions and 19 deletions

2
Cargo.lock generated
View File

@ -862,7 +862,7 @@ dependencies = [
[[package]]
name = "rex"
version = "0.1.2"
source = "git+https://github.com/laurmaedje/ReX#b44e59bfa68cc4b0288bd2be80e093ed3b279af5"
source = "git+https://github.com/laurmaedje/ReX#7362b0cbb229211d6206198d80382a9b23eda993"
dependencies = [
"font",
"unicode-math",

2
NOTICE
View File

@ -460,6 +460,8 @@ The GUST Font License Version 1.0 applies to:
* Latin Modern fonts in fonts/LatinModern*.otf
(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.
% (GUST is the Polish TeX Users Group, http://www.gust.org.pl)
%

Binary file not shown.

BIN
fonts/NewCMMath-Regular.otf Normal file

Binary file not shown.

View File

@ -20,7 +20,7 @@ pub struct MathNode {
impl MathNode {
/// The math font family.
#[property(referenced)]
pub const FAMILY: FontFamily = FontFamily::new("Latin Modern Math");
pub const FAMILY: FontFamily = FontFamily::new("NewComputerModernMath");
/// The spacing above display math.
#[property(resolve, shorthand(around))]
pub const ABOVE: Option<BlockSpacing> = Some(Ratio::one().into());

View File

@ -1,8 +1,8 @@
use rex::error::{Error, LayoutError};
use rex::font::{FontContext, MathFont};
use rex::layout::{LayoutSettings, Style};
use rex::parser::color::RGBA;
use rex::render::{Backend, Cursor, Renderer};
use rex::error::{Error, LayoutError};
use crate::font::FaceId;
use crate::library::prelude::*;
@ -27,30 +27,33 @@ impl Layout for RexNode {
styles: StyleChain,
) -> TypResult<Vec<Arc<Frame>>> {
// Load the font.
let face_id = match ctx.fonts.select(self.family.as_str(), variant(styles)) {
Some(id) => id,
None => return Ok(vec![]),
};
let span = self.tex.span;
let face_id = ctx
.fonts
.select(self.family.as_str(), variant(styles))
.ok_or("failed to find math font")
.at(span)?;
// Prepare the font.
let data = ctx.fonts.get(face_id).buffer();
let font = match MathFont::parse(data) {
Ok(font) => font,
Err(_) => return Ok(vec![]),
};
let font = MathFont::parse(data)
.map_err(|_| "failed to parse math font")
.at(span)?;
let ctx = FontContext::new(&font).ok_or("failed to parse math font").at(span)?;
// Layout the formula.
let ctx = FontContext::new(&font);
let em = styles.get(TextNode::SIZE);
let style = if self.display { Style::Display } else { Style::Text };
let settings = LayoutSettings::new(&ctx, em.to_pt(), style);
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 {
Error::Parse(err) => err.to_string(),
Error::Layout(LayoutError::Font(err)) => err.to_string(),
})
.at(self.tex.span)?;
.at(span)?;
// Determine the metrics.
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

View File

@ -23,7 +23,7 @@
[X]
}
#set text("Latin Modern Math", size)
#set text("Latin Modern Roman", size)
Neither #tex, \
nor #xetex!

View File

@ -11,6 +11,10 @@ $[ a^2 + b^2 = c^2 ]$
Prove by induction:
$[ \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
$\sqrt{x$

View File

@ -24,9 +24,6 @@
// Emoji.
Emoji: 🐪, 🌋, 🏞
// Math.
#text("Latin Modern Math")[ 𝛼 + 3𝛽 d𝑡]
// Colors.
[
#set text(fill: eastern)
@ -34,7 +31,7 @@ Emoji: 🐪, 🌋, 🏞
]
// 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)
= 𝛼 + 𝛽.