- Fix: typstyle previously incorrectly remove comments in math equations. Now it is fixed.
- Cli:
- typstyle now reports error when the input file is invalid.
typstyle --check
no longer changes the file content.- Other minor improvements.
No changes. We failed to publish the previous release because of the ci issue.
Packaging: We've split typstyle crate into two independent crates: typstyle
and typstyle-core
. typstyle
is the CLI tool, and typstyle-core
is the core library. The npm package is now typstyle-core
, typstyle
on npm will be deprecated in the future.
- Fix:
// @typstyle off
not working in certain cases. See #182 - Feature: dot chain formatting is more smart now. We will only break dot chain into multiple lines if it is long enough or complex enough. For example, the following result is generated by typstyle previously:
#{
cetz
.draw
.group({
cetz.draw.translate(node.pos.xyz)
for (i, extrude) in node.extrude.enumerate() {
cetz
.draw
.set-style(
fill: if i == 0 { node.fill },
stroke: node.stroke,
)
(node.shape)(node, extrude)
}
})
}
Now it will be formatted as following. This is more readable and compact:
#{
cetz.draw.group({
cetz.draw.translate(node.pos.xyz)
for (i, extrude) in node.extrude.enumerate() {
cetz.draw.set-style(
fill: if i == 0 { node.fill },
stroke: node.stroke,
)
(node.shape)(node, extrude)
}
})
}
- Fix: musl build is now statically linked. This fixes the issue that the musl build doesn't work on systems other than alpine.
- Typstyle now break content blocks into multiple lines if they have leading spaces and trailing spaces.
For example, the following code is not formattable by typstyle previously:
#{
let res = if true [ The Result is definitely true. And it is a very long sentence that needs to be broken into multiple lines. ] else [ The Result is definitely false. And it is a very long sentence that needs to be broken into multiple lines. ]
}
Now it will be formatted as:
#{
let res = if true [
The Result is definitely true. And it is a very long sentence that needs to be broken into multiple lines.
] else [
The Result is definitely false. And it is a very long sentence that needs to be broken into multiple lines.
]
}
- Typstyle no longer force single arg function call to be in a single line. Instead, it is determined in a smarter way. And this fixes #143.
- Typstyle will always add newline at the end of the file. Previously, it only adds newline when it already exists.
- Typstyle will format binary expressions as operator chains. Parentheses are added if necessary.
- Formatting chains with comments is supported now. This is the last piece of formatting with comments.
- Dot chains in markup with parentheses will be broken into multiple lines, if the it contains at least two dots and one function calls.
For example, the following code:
#let _is_block(e,fn)=fn==heading or (fn==math.equation and e.block) or (fn==raw and e.has("block") and e.block) or fn==figure or fn==block or fn==list.item or fn==enum.item or fn==table or fn==grid or fn==align or (fn==quote and e.has("block") and e.block)
Will be formatted as this in previous versions:
#let _is_block(e, fn) = (
fn == heading or (fn == math.equation and e.block) or (
fn == raw and e.has("block") and e.block
) or fn == figure or fn == block or fn == list.item or fn == enum.item or fn == table or fn == grid or fn == align or (
fn == quote and e.has("block") and e.block
)
)
Now it will be formatted as:
#let _is_block(e, fn) = (
fn == heading
or (fn == math.equation and e.block)
or (fn == raw and e.has("block") and e.block)
or fn == figure
or fn == block
or fn == list.item
or fn == enum.item
or fn == table
or fn == grid
or fn == align
or (fn == quote and e.has("block") and e.block)
)
- Dot chain related improvement:
- Previously if the last item of a dot chain is a function call, typstyle doesn't indent it correctly. Now it is fixed.
- Previously typstyle formats function calls in dot chains in a very conversative way. Now it is the same as normal function calls.
- Function calls with comments are made formattable.
For example, the following code is not formattable by typstyle previously:
#{
let x = f(
cetz.draw.super-long-name.line(
start: (0, 0),
end: (1, 1), // note
) // my comment
)
}
Now it will be formatted as:
#{
let x = f(
cetz
.draw
.super-long-name
.line(
start: (0, 0),
end: (1, 1), // note
), // my comment
)
}
- Parenthesized expressions with comments can be formatted by typstyle now.
- Closure with comments can be formatted by typstyle now.
- Typstyle will removes unnecessary parentheses if the inner expression is literal, array, dict, destructuring, block, or pattern. For safety, parens around idents are kept.
- Destructuring and params with comments are no longer forced to fold into one line.
- Typstyle can format comments appears in most places. Previously it simply gives up when it encounters comments in these places. Now it can format them correctly.
For example, this code:
#let conf(
title: none, //comments
authors: (),
abstract: [],
lang: "zh", // language
doctype: "book", //comments
doc // my docs
) = {
doc }
Previously typstyle will not format it. Now it will be formatted as:
#let conf(
title: none, //comments
authors: (),
abstract: [],
lang: "zh", // language
doctype: "book", //comments
doc, // my docs
) = {
doc
}
However, there are still some limitations. For more information, see Limitation.
- Fix typstyle previously would format parenthesized patterns incorrectly into
none
. Now it is fixed.
- Performance improvement(#158, #159 by @QuadnucYard): Typstyle now becomes 10-100x faster than before. Previously formatting tablex source code takes ~500ms, but now it only takes less than 5ms.
- Fix doc test failure that prevents nixpkgs from building typstyle.
Introducing new contributor: @QuadnucYard. Welcome! 🎉
- For single item code block, typstyle will try to keep it inline if it fits in a single line and it's inline in original code.
For example, you will get following code:
#{
let x = if true { 1 } else { 2 }
}
Instead of:
#{
let x = if true {
1
} else {
2
}
}
- Typstyle now strip excessive newlines in code blocks. Previously, typstyle will keep all newlines in code blocks. Now it will strip newlines at beginning and end of code blocks. It will also strip newlines in the middle of code blocks if there are more than 2 consecutive newlines.
For example, the following code:
#{
let x = 1
let y = 2
}
After formatting, it will become:
#{
let x = 1
let y = 2
}
- Formatting block comments are now improved. Previously, leading spaces in block comments are blindly removed. Now typstyle will keep leading spaces in block comments if they are consistent. Typstyle will also try to align
*
in block comments.
For example, the following code:
#{
let x = 1 /* Attached block comment
that spans
multiple lines
*/
/* Block comment
that spans
multiple lines
*/
/* Block comment with leading stars
* that
* spans
* multiple
* lines
*/
}
Will be formatted as:
#{
let x = 1 /* Attached block comment
that spans
multiple lines
*/
/* Block comment
that spans
multiple lines
*/
/* Block comment with leading stars
* that
* spans
* multiple
* lines
*/
}
- Fix:
context
expressions are now longer surrounded by unneeded parentheses. Previously, if a context expression spans multiple lines, typstyle will wrap it in parentheses. Now it doesn't.
- Typstyle now keeps spaces around math-delimited when there is already space around it. This prevents a bug when removing the space can cause wrong format result.
For example, this code:
$[ | | ]$
Previous:
$[| |]$
Now it is fixed.
- Bump to typst v0.12.0
- Support new import syntax. Now long import can be broken into multiple lines.
Previous:
#import "test.typ": aaa, bbb as cccccccccc, ddd as eeeeeeeeeee, fff as g
Now:
#import "test.typ": (
aaa,
bbb as cccccccccc,
ddd as eeeeeeeeeee,
fff as g,
)
- Fix block comments drifting right if they have indentation. Now we strips all leading whitespaces in block comments.
- Fix a bug in the
completions
subcommand. #131 (comment)
- feat: add command-line completions
Generate shell completions for the given shell to stdout
Usage: typstyle completions <SHELL>
Arguments:
<SHELL> The shell to generate completions for [possible values: bash, elvish, fish, powershell, zsh]
- Bug fix: Typstyle previously fails to correctly format inline triple backtick code block without a lang tag or an empty inline triple backtick code block with only a lang tag. Now it is fixed.
#text(``` test ```)
#text(```test ```)
Previously, it will be formatted as:
#text(```test ```)
#text(```test ```)
Now it is fixed.
- Bug fix: Typstyle previously removes necessary leading colon in dict. Now it is fixed.
#{
let a = (a: 1)
let b = (b: 2)
(: ..a, ..b) // previously it will be formatted as (..a, ..b)
}
- Bug fix: previously when a destructing pattern has extra parentheses, typstyle will completely remove everything inside the parentheses. Now it is fixed.
- Typstyle now collapses extra parentheses in expression.
- typstyle cli now can be installed from
cargo-binstall
- typstyle now recognize dot chains and keep them aligned on multiple lines when possible.
Previously, typstyle's format result looks like this:
#{
let (title, _) = query(heading.where(level: 1)).map(e => (
e.body,
e.location().page(),
)).rev().find(((_, v)) => v <= page)
}
Now it will be formatted as:
#{
let (title, _) = query(heading.where(level: 1))
.map(e => (e.body, e.location().page()))
.rev()
.find(((_, v)) => v <= page)
}
- Minor adjustment for closure body formatting.
- typstyle cli now has a
--check
flag to check if the input is formatted. If it's not formatted, it will return a non-zero exit code. - Allow disabling git info collection in build time.
- Fix #97. Typstyle previously add an extra newline for
table
andgrid
when there is no positional argument and there are extra arguments. Now it doesn't add an extra newline. - Typstyle cli now returns non-zero exit code when there are formatting errors.
- Typstyle now keeps newlines in function call args. Multiple newlines in function call args are common in fletcher diagrams. Before this release, typstyle removes all extra newlines in function call args. Now it keeps them as they are.
Example
#set text(10pt)
#diagram(
node-stroke: .1em,
node-fill: gradient.radial(blue.lighten(80%), blue, center: (30%, 20%), radius: 80%),
spacing: 4em,
node((0,0), `reading`, radius: 2em),
node((1,0), `eof`, radius: 2em),
node((2,0), `closed`, radius: 2em, extrude: (-2.5, 0)),
edge((-1,0), "r", "-|>", `open(path)`, label-pos: 0, label-side: center),
edge(`read()`, "-|>"),
edge(`close()`, "-|>"),
edge((0,0), (0,0), `read()`, "--|>", bend: 130deg),
edge((0,0), (2,0), `close()`, "-|>", bend: -40deg),
)
After formatting, it will become this. Notice the extra newlines are kept.
#set text(10pt)
#diagram(
node-stroke: .1em,
node-fill: gradient.radial(
blue.lighten(80%),
blue,
center: (30%, 20%),
radius: 80%,
),
spacing: 4em,
node((0, 0), `reading`, radius: 2em),
node((1, 0), `eof`, radius: 2em),
node((2, 0), `closed`, radius: 2em, extrude: (-2.5, 0)),
edge((-1, 0), "r", "-|>", `open(path)`, label-pos: 0, label-side: center),
edge(`read()`, "-|>"),
edge(`close()`, "-|>"),
edge((0, 0), (0, 0), `read()`, "--|>", bend: 130deg),
edge((0, 0), (2, 0), `close()`, "-|>", bend: -40deg),
)
- For tables, if typstyle is unable to format it in a column-aware way, it will now format each arg, but do not reflow them. That is, the relative position of each arg is kept. If you put something in a single line, it will stay in a single line. Newlines are also kept.
Example
#table(
columns: 4 * (1fr,),
[a], [b], [c], [d],
fill: (_, y) => if y == 0 { black },
table.cell(rowspan: 2)[aa], table.cell(colspan: 2)[bc], [d],
[b], table.cell(colspan: 2)[cd],
)
After formatting, it will become this. Notice the relative position of each arg is kept.
#table(
columns: 4 * (1fr,),
[a], [b], [c], [d],
fill: (_, y) => if y == 0 {
black
},
table.cell(rowspan: 2)[aa], table.cell(colspan: 2)[bc], [d],
[b], table.cell(colspan: 2)[cd],
)
- Typstyle now keeps extra newlines in markup mode. Multiple newlines are sometimes used to separate different sections in a document or act as a paragraph placeholder. Typstyle now keeps them as they are.
== Unfinished Title
=== Section 1
=== Section 2
Previously, it will be formatted as:
== Unfinished Title
== Section 1
== Section 2
Now it is kept as it is.
- Now typstyle can format table with
table.header
andtable.footer
attributes. The header and footer will be put in a single line if possible. For what it cannot do, see #59 (comment).
#table(
columns: 3,
table.header(
[Substance],
[Subcritical °C],
[Supercritical °C],
repeat: true,
),
[Hydrochloric Acid],
[12.0],
[92.1],
[Sodium Myreth Sulfate],
[16.6],
[104],
[Potassium Hydroxide],
[24.7],
[114.514],
)
After formatting, it will become:
#table(
columns: 3,
table.header(
[Substance],
[Subcritical °C],
[Supercritical °C],
repeat: true,
),
[Hydrochloric Acid], [12.0], [92.1],
[Sodium Myreth Sulfate], [16.6], [104],
[Potassium Hydroxide], [24.7], [114.514],
)
- Enhance table formatting. When a table row cannot fit in a single line, each cell will be put in a single line.
For example, this code:
#figure(
grid(
columns: (auto, auto),
rows: (auto, auto),
gutter: 0em,
[ #image("assets/1.png", width: 59%) ], [ #image("assets/2.png",width: 55%) ],
),
caption: [],
)
After formatting, it will become:
#figure(
grid(
columns: (auto, auto),
rows: (auto, auto),
gutter: 0em,
[ #image("assets/1.png", width: 59%) ],
[ #image("assets/2.png", width: 55%) ],
),
caption: [],
)
- Typstyle now can format table and grid in a "column-aware" way. It now recognizes basic patterns and column numbers, and put a single row in a single line if possible.
For example, this code:
#table(
columns: 3,
[Substance],
[Subcritical °C],
[Supercritical °C],
[Hydrochloric Acid],
[12.0], [92.1],
[Sodium Myreth Sulfate],
[16.6], [104],
[Potassium Hydroxide],
[24.7],
[114.514]
)
After formatting, it will become:
#table(
columns: 3,
[Substance], [Subcritical °C], [Supercritical °C],
[Hydrochloric Acid], [12.0], [92.1],
[Sodium Myreth Sulfate], [16.6], [104],
[Potassium Hydroxide], [24.7], [114.514],
)
Bump to typst v0.11.1
Typstyle cli now include a format-all
subcommand to format all files in a directory in-place.
typstyle format-all dir
# or omit the dir to format the current directory
typstyle format-all
- Typstyle now indent block math equations.
For example, this code:
$
E = mc^2
$
Now it will be formatted as:
$
E = mc^2
$
- Typstyle now can keep line comments attached to the end of the line when formatting code blocks.
For example, this code:
#{
let c = 0 // my comment
}
Previously, the comment will be moved to the next line after formatting. Now it's attached to the end of the line.
#{
let c = 0 // my comment
}
- Fix typstyle cli not stripping trailing spaces.
- Fix comment loss in closure definition
- Fix comment loss in destruction and set rules
Previously for this code, the comment will be removed after formatting. Now it's kept.
#let (
// abc
a, b, c,
) = (1, 2, 3)
#set text(
size: 10pt,
fallback: false,
// lang: "de",
)
- API Change: allow takes a
typst::Source
as input to avoid re-parsing
-
(#49) typstyle cli now support multiple input files. If multiple files are provided, they will be processed in order. This is especially useful when you want to format multiple files inplace with a single command.
typstyle -i **/*.typ
- Improve performance when formatting nested structures.
Previously it takes infinite time to format this code:
#let f(..arg) = arg
#f(f(f(f(f(f(f(f(f(f(f(f(f(f(f(f(f(f(f(f(f(f(1,2,3))))))))))))))))))))))
Now it is done in instant.
- Fix set rules args are always spread into multiple lines. It now behaves like function call args.
For example, this code:
#set text( font: body-font,
lang: "zh", region: "cn",
)
After formatting, it will become:
#set text(font: body-font, lang: "zh", region: "cn")
- Fix flavor detection for function call args. It now works correctly when the first space in the args contains a newline.
- Block math equations are no longer indented.
- We now support flavor detection for block equations.
For example, this code:
$
F(x) = integral_0^x f(t) dif t
$
$ F(x) = integral_0^x f(t) dif t
$
After formatting, it will become:
$
F(x) = integral_0^x f(t) dif t
$
$ F(x) = integral_0^x f(t) dif t $
- Trailing spaces are now trimmed.
- Spread args/array/dict into multiple lines if the first space in it contains a newline. This enables flexible control over the formatting of spread args. This is called flavor detection.
For example, this code:
#let my-f(arg1, arg2,
args: none) = {
arg1 + arg2
}
#let my-f(arg1,
arg2, args: none) = {
arg1 + arg2
}
After formatting, it will become:
#let my-f(arg1, arg2, args: none) = {
arg1 + arg2
}
#let my-f(
arg1,
arg2,
args: none,
) = {
arg1 + arg2
}
- Fix multiline string/single-backtick-raw-block being wrongly formatted
- Fix missing trailing comma single element array destruct
- Fix
#
is missing in some math environments
- Fix import rename being wrongly formatted
- Fix raw block that starts/ends with backtick is wrongly formatted
- Add version string in
--version
output
- Fix long import item being spread across multiple lines
- Fix bad formatting of destruct items
- Enable formatting when line comment presents in code block
- Put
clap
andwasm-bindgen
under feature flags to reduce binary size when use as a library
- Nothing new. Just testing ci auto-release
- Fix math attach and function call mis-formatting
- Read from stdin when no arguments are provided
- Initial release