Skip to content

Commit

Permalink
Add fonts directory
Browse files Browse the repository at this point in the history
  • Loading branch information
sitandr committed Jan 3, 2024
1 parent d03f40b commit ba18c36
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
8 changes: 8 additions & 0 deletions example-book/src/chapter_2.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,12 @@ It uses external Typst that should be installed in path, so you can use packages
domain: (-calc.pi, calc.pi), x => calc.cos((x + calc.pi) * 1rad))
})
})
```

```typ
$integral_a^b x^2$
#show math.equation: set text(font: "Fira Math", fallback: false)
$integral_a^b x^2$
```
Binary file added example-book/src/fonts/FiraMath-Regular.otf
Binary file not shown.
16 changes: 13 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ fn process_chapter(
let (file, err) = render_block(
text,
chapter_path.clone(),
build_dir.clone(),
chapter.name.clone(),
!lang.contains("nopreamble"),
);
Expand Down Expand Up @@ -297,6 +298,7 @@ fn sha256_hash(input: &str) -> String {
fn render_block(
src: String,
mut dir: PathBuf,
mut build_dir: PathBuf,
name: String,
preamble: bool,
) -> (String, Option<impl Future<Output = ()>>) {
Expand All @@ -319,13 +321,21 @@ fn render_block(
};
write!(file, "{}", src).expect("Error writing to file");

let res = Command::new("typst")
let mut res = Command::new("typst");
let mut res = res
.arg("c")
.arg(&dir)
.arg("--root")
.arg(dir.parent().unwrap().parent().unwrap())
.arg(&output)
.output();
.arg(&output);

build_dir.push("fonts");

if build_dir.exists() {
res = res.arg("--font-path").arg(build_dir)
}

let res = res.output();

command = Some(async move {
let output = res.await.expect("Failed").stderr;
Expand Down

0 comments on commit ba18c36

Please sign in to comment.