diff --git a/Cargo.lock b/Cargo.lock
index e1eabd019..aabc95e1a 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -1110,49 +1110,78 @@ version = "0.1.0"
dependencies = [
"bitflags",
"bytemuck",
- "chrono",
- "codespan-reporting",
"comemo",
- "csv",
- "dirs",
"elsa",
"flate2",
- "hypher",
"iai",
"image",
- "kurbo",
- "lipsum",
- "memmap2",
"miniz_oxide",
- "notify",
"once_cell",
"pdf-writer",
- "pico-args",
"pixglyph",
"regex",
"resvg",
"rex",
"roxmltree",
"rustybuzz",
- "same-file",
"serde",
- "serde_json",
"siphasher",
"subsetter",
"svg2pdf",
"syntect",
"tiny-skia",
"ttf-parser 0.17.1",
- "typed-arena",
+ "typst-library",
"typst-macros",
- "unicode-bidi",
- "unicode-math",
- "unicode-script",
"unicode-segmentation",
"unicode-xid",
"unscanny",
"usvg",
"walkdir",
+]
+
+[[package]]
+name = "typst-cli"
+version = "0.1.0"
+dependencies = [
+ "chrono",
+ "codespan-reporting",
+ "comemo",
+ "dirs",
+ "elsa",
+ "memmap2",
+ "notify",
+ "once_cell",
+ "pico-args",
+ "same-file",
+ "siphasher",
+ "typst",
+ "typst-library",
+ "walkdir",
+]
+
+[[package]]
+name = "typst-library"
+version = "0.1.0"
+dependencies = [
+ "comemo",
+ "csv",
+ "hypher",
+ "kurbo",
+ "lipsum",
+ "once_cell",
+ "rex",
+ "roxmltree",
+ "rustybuzz",
+ "serde_json",
+ "syntect",
+ "ttf-parser 0.17.1",
+ "typed-arena",
+ "typst",
+ "unicode-bidi",
+ "unicode-math",
+ "unicode-script",
+ "unscanny",
"xi-unicode",
]
diff --git a/Cargo.toml b/Cargo.toml
index f08f9056f..0e9648771 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -5,97 +5,47 @@ authors = ["The Typst Project Developers"]
edition = "2021"
[workspace]
-members = ["macros"]
+members = ["cli", "library", "macros"]
[dependencies]
-# Workspace
-typst-macros = { path = "./macros" }
-
-# Utilities
+typst-macros = { path = "macros" }
bitflags = "1"
bytemuck = "1"
comemo = "0.1"
+flate2 = "1"
+image = { version = "0.24", default-features = false, features = ["png", "jpeg", "gif"] }
+miniz_oxide = "0.5"
once_cell = "1"
+pdf-writer = "0.6"
+pixglyph = { git = "https://github.com/typst/pixglyph" }
regex = "1"
+resvg = { version = "0.22", default-features = false }
+rex = { git = "https://github.com/laurmaedje/ReX" }
+roxmltree = "0.14"
+rustybuzz = "0.5"
serde = { version = "1", features = ["derive"] }
siphasher = "0.3"
-typed-arena = "2"
-unscanny = "0.1"
-
-# Text and font handling
-hypher = "0.1"
-kurbo = "0.8"
-rustybuzz = "0.5"
-ttf-parser = "0.17"
-unicode-bidi = "0.3.5"
-unicode-script = "0.5"
-unicode-segmentation = "1"
-unicode-xid = "0.2"
-xi-unicode = "0.3"
-
-# Raster and vector graphics handling
-image = { version = "0.24", default-features = false, features = ["png", "jpeg", "gif"] }
-usvg = { version = "0.22", default-features = false }
-
-# External implementation of user-facing features
-csv = "1"
-lipsum = { git = "https://github.com/reknih/lipsum" }
-rex = { git = "https://github.com/laurmaedje/ReX" }
-serde_json = "1"
-syntect = { version = "5", default-features = false, features = ["default-syntaxes", "regex-fancy"] }
-unicode-math = { git = "https://github.com/s3bk/unicode-math/" }
-
-# PDF export
-miniz_oxide = "0.5"
-pdf-writer = "0.6"
subsetter = "0.1"
svg2pdf = "0.4"
-
-# Rendering
-flate2 = "1"
-pixglyph = { git = "https://github.com/typst/pixglyph" }
-resvg = { version = "0.22", default-features = false }
-roxmltree = "0.14"
+syntect = { version = "5", default-features = false, features = ["default-syntaxes", "regex-fancy"] }
tiny-skia = "0.6.2"
-
-# Command line interface
-chrono = { version = "0.4", default-features = false, features = ["clock", "std"], optional = true }
-codespan-reporting = { version = "0.11", optional = true }
-dirs = { version = "4", optional = true }
-elsa = { version = "1.7", optional = true }
-memmap2 = { version = "0.5", optional = true }
-notify = { version = "5", optional = true }
-pico-args = { version = "0.4", optional = true }
-same-file = { version = "1", optional = true }
-walkdir = { version = "2", optional = true }
+ttf-parser = "0.17"
+unicode-segmentation = "1"
+unicode-xid = "0.2"
+unscanny = "0.1"
+usvg = { version = "0.22", default-features = false }
[dev-dependencies]
+typst-library = { path = "library" }
iai = { git = "https://github.com/reknih/iai" }
elsa = "1.7"
walkdir = "2"
-[features]
-cli = [
- "chrono",
- "codespan-reporting",
- "dirs",
- "elsa",
- "memmap2",
- "notify",
- "pico-args",
- "same-file",
- "walkdir",
-]
-
[profile.dev]
-debug = 0 # Faster compilation
+debug = 0
[profile.dev.package."*"]
-opt-level = 2 # Faster test execution
-
-[[bin]]
-name = "typst"
-required-features = ["cli"]
+opt-level = 2
[[test]]
name = "typeset"
diff --git a/benches/oneshot.rs b/benches/oneshot.rs
index 2437b7236..965d0c788 100644
--- a/benches/oneshot.rs
+++ b/benches/oneshot.rs
@@ -1,4 +1,4 @@
-use std::path::Path;
+use std::path::{Path, PathBuf};
use comemo::{Prehashed, Track, Tracked};
use iai::{black_box, main, Iai};
@@ -20,7 +20,7 @@ main!(
bench_parse,
bench_edit,
bench_eval,
- bench_layout,
+ bench_typeset,
bench_highlight,
bench_render,
);
@@ -80,12 +80,10 @@ fn bench_eval(iai: &mut Iai) {
iai.run(|| typst::model::eval(world.track(), route.track(), id).unwrap());
}
-fn bench_layout(iai: &mut Iai) {
+fn bench_typeset(iai: &mut Iai) {
let world = BenchWorld::new();
let id = world.source.id();
- let route = typst::model::Route::default();
- let module = typst::model::eval(world.track(), route.track(), id).unwrap();
- iai.run(|| typst::library::layout::Layout::layout(&module.content, world.track()));
+ iai.run(|| typst::typeset(&world, id));
}
fn bench_render(iai: &mut Iai) {
@@ -104,7 +102,13 @@ struct BenchWorld {
impl BenchWorld {
fn new() -> Self {
- let config = Config::default();
+ let config = Config {
+ root: PathBuf::new(),
+ scope: typst_library::scope(),
+ styles: typst_library::styles(),
+ items: typst_library::items(),
+ };
+
let font = Font::new(FONT.into(), 0).unwrap();
let book = FontBook::from_fonts([&font]);
let id = SourceId::from_u16(0);
diff --git a/cli/Cargo.toml b/cli/Cargo.toml
new file mode 100644
index 000000000..5e3f227ad
--- /dev/null
+++ b/cli/Cargo.toml
@@ -0,0 +1,26 @@
+[package]
+name = "typst-cli"
+version = "0.1.0"
+authors = ["The Typst Project Developers"]
+edition = "2021"
+
+[[bin]]
+name = "typst"
+path = "src/main.rs"
+doc = false
+
+[dependencies]
+typst = { path = ".." }
+typst-library = { path = "../library" }
+chrono = { version = "0.4", default-features = false, features = ["clock", "std"] }
+codespan-reporting = "0.11"
+comemo = "0.1"
+dirs = "4"
+elsa = "1.7"
+memmap2 = "0.5"
+notify = "5"
+once_cell = "1"
+pico-args = "0.4"
+same-file = "1"
+siphasher = "0.3"
+walkdir = "2"
diff --git a/src/main.rs b/cli/src/main.rs
similarity index 98%
rename from src/main.rs
rename to cli/src/main.rs
index e32bb8c60..62cad8ab5 100644
--- a/src/main.rs
+++ b/cli/src/main.rs
@@ -174,13 +174,20 @@ fn dispatch(command: Command) -> StrResult<()> {
/// Execute a typesetting command.
fn typeset(command: TypesetCommand) -> StrResult<()> {
- let mut config = Config::default();
- if let Some(root) = &command.root {
- config.root = root.clone();
+ let root = if let Some(root) = &command.root {
+ root.clone()
} else if let Some(dir) = command.input.parent() {
- config.root = dir.into();
- }
+ dir.into()
+ } else {
+ PathBuf::new()
+ };
+ let config = Config {
+ root,
+ scope: typst_library::scope(),
+ styles: typst_library::styles(),
+ items: typst_library::items(),
+ };
// Create the world that serves sources, fonts and files.
let mut world = SystemWorld::new(config);
diff --git a/library/Cargo.toml b/library/Cargo.toml
new file mode 100644
index 000000000..18f4779c4
--- /dev/null
+++ b/library/Cargo.toml
@@ -0,0 +1,26 @@
+[package]
+name = "typst-library"
+version = "0.1.0"
+authors = ["The Typst Project Developers"]
+edition = "2021"
+
+[dependencies]
+typst = { path = ".." }
+comemo = "0.1"
+csv = "1"
+hypher = "0.1"
+kurbo = "0.8"
+lipsum = { git = "https://github.com/reknih/lipsum" }
+once_cell = "1"
+rex = { git = "https://github.com/laurmaedje/ReX" }
+roxmltree = "0.14"
+rustybuzz = "0.5"
+serde_json = "1"
+syntect = { version = "5", default-features = false, features = ["default-syntaxes", "regex-fancy"] }
+ttf-parser = "0.17"
+typed-arena = "2"
+unicode-bidi = "0.3.5"
+unicode-math = { git = "https://github.com/s3bk/unicode-math/" }
+unicode-script = "0.5"
+unscanny = "0.1"
+xi-unicode = "0.3"
diff --git a/src/library/ext.rs b/library/src/ext.rs
similarity index 93%
rename from src/library/ext.rs
rename to library/src/ext.rs
index 07b55a7bb..72ef484b6 100644
--- a/src/library/ext.rs
+++ b/library/src/ext.rs
@@ -1,5 +1,5 @@
use super::*;
-use crate::library::prelude::*;
+use crate::prelude::*;
/// Additional methods on content.
pub trait ContentExt {
@@ -19,7 +19,7 @@ pub trait ContentExt {
fn boxed(self, sizing: Axes