mirror of
https://github.com/typst/typst
synced 2025-07-31 16:27:56 +08:00
Compare commits
4 Commits
9e571580a8
...
dd5fe542f3
Author | SHA1 | Date | |
---|---|---|---|
|
dd5fe542f3 | ||
|
b1c79b50d4 | ||
|
4629ede020 | ||
|
3d7a289334 |
@ -173,8 +173,11 @@ typst help
|
||||
typst help watch
|
||||
```
|
||||
|
||||
If you prefer an integrated IDE-like experience with autocompletion and instant
|
||||
preview, you can also check out [Typst's free web app][app].
|
||||
If you prefer an integrated IDE-like experience with autocompletion and instant
|
||||
preview, you can also check out our [free web app][app]. Alternatively, there is
|
||||
a community-created language server called
|
||||
[Tinymist](https://myriad-dreamin.github.io/tinymist/) which is integrated into
|
||||
various editor extensions.
|
||||
|
||||
## Community
|
||||
The main places where the community gathers are our [Forum][forum] and our
|
||||
|
@ -87,7 +87,7 @@ pub fn layout_mat(
|
||||
let augment = elem.augment.resolve(styles);
|
||||
if let Some(aug) = &augment {
|
||||
for &offset in &aug.hline.0 {
|
||||
if offset == 0 || offset.unsigned_abs() >= rows.len() {
|
||||
if offset > rows.len() as isize || offset.unsigned_abs() > rows.len() + 1 {
|
||||
bail!(
|
||||
span,
|
||||
"cannot draw a horizontal line after row {} of a matrix with {} rows",
|
||||
@ -98,7 +98,7 @@ pub fn layout_mat(
|
||||
}
|
||||
|
||||
for &offset in &aug.vline.0 {
|
||||
if offset == 0 || offset.unsigned_abs() >= ncols {
|
||||
if offset > ncols as isize || offset.unsigned_abs() > ncols + 1 {
|
||||
bail!(
|
||||
span,
|
||||
"cannot draw a vertical line after column {} of a matrix with {} columns",
|
||||
@ -165,7 +165,7 @@ fn layout_body(
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
let (hline, vline, stroke) = match augment {
|
||||
let (mut hline, mut vline, stroke) = match augment {
|
||||
Some(augment) => {
|
||||
// We need to get stroke here for ownership.
|
||||
let stroke = augment.stroke.unwrap_or_default().unwrap_or(default_stroke);
|
||||
@ -216,20 +216,48 @@ fn layout_body(
|
||||
}
|
||||
}
|
||||
|
||||
for line in hline.0.iter_mut() {
|
||||
if *line < 0 {
|
||||
*line += (nrows as isize) + 1
|
||||
}
|
||||
}
|
||||
|
||||
for line in vline.0.iter_mut() {
|
||||
if *line < 0 {
|
||||
*line += (ncols as isize) + 1
|
||||
}
|
||||
}
|
||||
|
||||
// For each row, combine maximum ascent and descent into a row height.
|
||||
// Sum the row heights, then add the total height of the gaps between rows.
|
||||
let total_height =
|
||||
let mut total_height =
|
||||
heights.iter().map(|&(a, b)| a + b).sum::<Abs>() + gap.y * (nrows - 1) as f64;
|
||||
|
||||
if hline.0.contains(&0_isize) {
|
||||
total_height += gap.y;
|
||||
}
|
||||
|
||||
if hline.0.contains(&(nrows as isize)) {
|
||||
total_height += gap.y;
|
||||
}
|
||||
|
||||
// Width starts at zero because it can't be calculated until later
|
||||
let mut frame = Frame::soft(Size::new(Abs::zero(), total_height));
|
||||
|
||||
let mut x = Abs::zero();
|
||||
|
||||
if vline.0.contains(&(0_isize)) {
|
||||
frame.push(
|
||||
Point::with_x(x + half_gap.x),
|
||||
line_item(total_height, true, stroke.clone(), span),
|
||||
);
|
||||
x += gap.x;
|
||||
}
|
||||
|
||||
for (index, col) in cols.into_iter().enumerate() {
|
||||
let AlignmentResult { points, width: rcol } = alignments(&col);
|
||||
|
||||
let mut y = Abs::zero();
|
||||
let mut y = if hline.0.contains(&0_isize) { gap.y } else { Abs::zero() };
|
||||
|
||||
for (cell, &(ascent, descent)) in col.into_iter().zip(&heights) {
|
||||
let cell = cell.into_line_frame(&points, alternator);
|
||||
@ -251,9 +279,7 @@ fn layout_body(
|
||||
x += rcol;
|
||||
|
||||
// If a vertical line should be inserted after this column
|
||||
if vline.0.contains(&(index as isize + 1))
|
||||
|| vline.0.contains(&(1 - ((ncols - index) as isize)))
|
||||
{
|
||||
if vline.0.contains(&(index as isize + 1)) {
|
||||
frame.push(
|
||||
Point::with_x(x + half_gap.x),
|
||||
line_item(total_height, true, stroke.clone(), span),
|
||||
@ -264,16 +290,17 @@ fn layout_body(
|
||||
x += gap.x;
|
||||
}
|
||||
|
||||
// Once all the columns are laid out, the total width can be calculated
|
||||
let total_width = x - gap.x;
|
||||
let total_width = if !(vline.0.contains(&(ncols as isize))) { x - gap.x } else { x };
|
||||
|
||||
// This allows the horizontal lines to be laid out
|
||||
for line in hline.0 {
|
||||
let real_line =
|
||||
if line < 0 { nrows - line.unsigned_abs() } else { line as usize };
|
||||
let offset = (heights[0..real_line].iter().map(|&(a, b)| a + b).sum::<Abs>()
|
||||
+ gap.y * (real_line - 1) as f64)
|
||||
+ half_gap.y;
|
||||
let offset = if line == 0 {
|
||||
gap.y
|
||||
} else {
|
||||
(heights[0..line as usize].iter().map(|&(a, b)| a + b).sum::<Abs>()
|
||||
+ gap.y * (line - 1) as f64)
|
||||
+ half_gap.y
|
||||
};
|
||||
|
||||
frame.push(
|
||||
Point::with_y(offset),
|
||||
|
@ -797,7 +797,9 @@ impl Color {
|
||||
components
|
||||
}
|
||||
|
||||
/// Returns the constructor function for this color's space:
|
||||
/// Returns the constructor function for this color's space.
|
||||
///
|
||||
/// Returns one of:
|
||||
/// - [`luma`]($color.luma)
|
||||
/// - [`oklab`]($color.oklab)
|
||||
/// - [`oklch`]($color.oklch)
|
||||
|
@ -242,7 +242,7 @@ fn category_page(resolver: &dyn Resolver, category: Category) -> PageModel {
|
||||
items.push(CategoryItem {
|
||||
name: group.name.clone(),
|
||||
route: subpage.route.clone(),
|
||||
oneliner: oneliner(docs).into(),
|
||||
oneliner: oneliner(docs),
|
||||
code: true,
|
||||
});
|
||||
children.push(subpage);
|
||||
@ -296,7 +296,7 @@ fn category_page(resolver: &dyn Resolver, category: Category) -> PageModel {
|
||||
items.push(CategoryItem {
|
||||
name: name.into(),
|
||||
route: subpage.route.clone(),
|
||||
oneliner: oneliner(func.docs().unwrap_or_default()).into(),
|
||||
oneliner: oneliner(func.docs().unwrap_or_default()),
|
||||
code: true,
|
||||
});
|
||||
children.push(subpage);
|
||||
@ -306,7 +306,7 @@ fn category_page(resolver: &dyn Resolver, category: Category) -> PageModel {
|
||||
items.push(CategoryItem {
|
||||
name: ty.short_name().into(),
|
||||
route: subpage.route.clone(),
|
||||
oneliner: oneliner(ty.docs()).into(),
|
||||
oneliner: oneliner(ty.docs()),
|
||||
code: true,
|
||||
});
|
||||
children.push(subpage);
|
||||
@ -637,7 +637,7 @@ fn group_page(
|
||||
let item = CategoryItem {
|
||||
name: group.name.clone(),
|
||||
route: model.route.clone(),
|
||||
oneliner: oneliner(&group.details).into(),
|
||||
oneliner: oneliner(&group.details),
|
||||
code: false,
|
||||
};
|
||||
|
||||
@ -772,8 +772,24 @@ pub fn urlify(title: &str) -> EcoString {
|
||||
}
|
||||
|
||||
/// Extract the first line of documentation.
|
||||
fn oneliner(docs: &str) -> &str {
|
||||
docs.lines().next().unwrap_or_default()
|
||||
fn oneliner(docs: &str) -> EcoString {
|
||||
let paragraph = docs.split("\n\n").next().unwrap_or_default();
|
||||
let mut depth = 0;
|
||||
let mut period = false;
|
||||
let mut end = paragraph.len();
|
||||
for (i, c) in paragraph.char_indices() {
|
||||
match c {
|
||||
'(' | '[' | '{' => depth += 1,
|
||||
')' | ']' | '}' => depth -= 1,
|
||||
'.' if depth == 0 => period = true,
|
||||
c if period && c.is_whitespace() && !docs[..i].ends_with("e.g.") => {
|
||||
end = i;
|
||||
break;
|
||||
}
|
||||
_ => period = false,
|
||||
}
|
||||
}
|
||||
EcoString::from(&docs[..end]).replace("\r\n", " ").replace("\n", " ")
|
||||
}
|
||||
|
||||
/// The order of types in the documentation.
|
||||
|
@ -86,7 +86,7 @@ pub struct FuncModel {
|
||||
pub name: EcoString,
|
||||
pub title: &'static str,
|
||||
pub keywords: &'static [&'static str],
|
||||
pub oneliner: &'static str,
|
||||
pub oneliner: EcoString,
|
||||
pub element: bool,
|
||||
pub contextual: bool,
|
||||
pub deprecation: Option<&'static str>,
|
||||
@ -139,7 +139,7 @@ pub struct TypeModel {
|
||||
pub name: &'static str,
|
||||
pub title: &'static str,
|
||||
pub keywords: &'static [&'static str],
|
||||
pub oneliner: &'static str,
|
||||
pub oneliner: EcoString,
|
||||
pub details: Html,
|
||||
pub constructor: Option<FuncModel>,
|
||||
pub scope: Vec<FuncModel>,
|
||||
|
Binary file not shown.
Before Width: | Height: | Size: 3.5 KiB After Width: | Height: | Size: 12 KiB |
@ -96,12 +96,18 @@ $ mat(column-gap: #1em, 1, 2; 3, 4)
|
||||
|
||||
$ mat(10, 2, 3, 4; 5, 6, 7, 8; augment: #3) $,
|
||||
$ mat(10, 2, 3, 4; 5, 6, 7, 8; augment: #(-1)) $,
|
||||
$ mat(100, 2, 3; 4, 5, 6; 7, 8, 9; augment: #(hline: 0)) $,
|
||||
$ mat(100, 2, 3; 4, 5, 6; 7, 8, 9; augment: #(hline: -4)) $,
|
||||
$ mat(100, 2, 3; 4, 5, 6; 7, 8, 9; augment: #(hline: 2)) $,
|
||||
$ mat(100, 2, 3; 4, 5, 6; 7, 8, 9; augment: #(hline: -1)) $,
|
||||
$ mat(100, 2, 3; 4, 5, 6; 7, 8, 9; augment: #(hline: 1, vline: 1)) $,
|
||||
$ mat(100, 2, 3; 4, 5, 6; 7, 8, 9; augment: #(hline: -2, vline: -2)) $,
|
||||
$ mat(100, 2, 3; 4, 5, 6; 7, 8, 9; augment: #(vline: 2, stroke: 1pt + blue)) $,
|
||||
$ mat(100, 2, 3; 4, 5, 6; 7, 8, 9; augment: #(vline: -1, stroke: 1pt + blue)) $,
|
||||
$ mat(10, 2, 3, 4; 5, 6, 7, 8; augment: #4) $,
|
||||
$ mat(100, 2, 3; 4, 5, 6; 7, 8, 9; augment: #(vline: 3, stroke: 1pt + blue)) $,
|
||||
$ mat(100, 2, 3; 4, 5, 6; 7, 8, 9; augment: #(vline: 0, stroke: 1pt + blue)) $,
|
||||
$ mat(10, 2, 3, 4; 5, 6, 7, 8; augment: #(vline: -5, stroke: 1pt + blue)) $,
|
||||
)
|
||||
|
||||
--- math-mat-augment-set ---
|
||||
@ -115,8 +121,8 @@ $ mat(1, 0, 0, 0; 0, 1, 0, 0; 0, 0, 1, 1) $
|
||||
#set math.mat(augment: none)
|
||||
|
||||
--- math-mat-augment-line-out-of-bounds ---
|
||||
// Error: 3-37 cannot draw a vertical line after column 3 of a matrix with 3 columns
|
||||
$ mat(1, 0, 0; 0, 1, 1; augment: #3) $,
|
||||
// Error: 3-37 cannot draw a vertical line after column 4 of a matrix with 3 columns
|
||||
$ mat(1, 0, 0; 0, 1, 1; augment: #4) $,
|
||||
|
||||
--- math-mat-align ---
|
||||
$ mat(-1, 1, 1; 1, -1, 1; 1, 1, -1; align: #left) $
|
||||
|
Loading…
x
Reference in New Issue
Block a user