Typstyle v0.13.4 is here with huge updates!

(synchronized with discord showcase)

In v0.13.2 and v0.13.3, we supported full-text formatting, including code mixed in markup texts and equations with comments, along with a few bug fixes. These have been integrated into the latest published tinymist.

Now, we have more exciting features in v0.13.4! Feel free to share your ideas!

Text Wrapping

It’s a long-requested feature of non-CJK users, which had been one inadequacy compared with typstfmt. Fans of text-wrapping can now try typstyle instead!

For example, this code

/ Term with display math:
  $ sum_(i=0)^n i = frac(n(n+1),2) $
  And explanation with more    text      following
Text with special Unicode: "Em—dash" and "en–dash" with *formatting* mixed in áéíóú äëïöü characters.

This paragraph contains special sequences that shouldn't be interpreted as markup:
A mathematical expression like 3 + 4 = 7 should remain intact.
Symbol sequences like a / b or x - y should not be treated as list markers.

This is a paragraph with // an inline comment that shouldn't break
the flow of text or create a new line. The formatter should handle
// multiple comments spread across
several lines while maintaining proper *formatting* and `code elements`.

Here's text with /* block-style comments */ mixed with *strong text*
and $"math" "equations"$ to ensure /* multi-line
   block comments */ don't interfere with text flow or // inline elements.

Testing comments near special characters:
a + b // comment after plus
x - y /* comment after minus */
term / definition // comment after slash
heading = title // comment after equals

A complex case mixing everything:
*bold text* // comment after strong
`code block` /* block comment */ with $"math"$ // final comment
and #text(red)[colored text] // with formatting

will be formatted to (with column with 80)

/ Term with display math:
  $ sum_(i=0)^n i = frac(n(n+1), 2) $
  And explanation with more text following
Text with special Unicode: "Em—dash" and "en–dash" with *formatting* mixed in
áéíóú äëïöü characters.

This paragraph contains special sequences that shouldn't be interpreted as
markup: A mathematical expression like 3 + 4 = 7 should remain intact. Symbol
sequences like a / b or x - y should not be treated as list markers.

This is a paragraph with // an inline comment that shouldn't break
the flow of text or create a new line. The formatter should handle
// multiple comments spread across
several lines while maintaining proper *formatting* and `code elements`.

Here's text with /* block-style comments */ mixed with *strong text* and
$"math" "equations"$ to ensure /* multi-line
                               block comments */ don't interfere with text flow
or // inline elements.

Testing comments near special characters: a + b // comment after plus
x - y /* comment after minus */ term / definition // comment after slash
heading = title // comment after equals

A complex case mixing everything: *bold text* // comment after strong
`code block` /* block comment */ with $"math"$ // final comment
and #text(red)[colored text] // with formatting

This feature has gone through rigorous tests, so it should work in the vast majority of cases. Special characters (=, /, -, +) will surely not be reflowed to the start of a line.

Math Alignment

A wonderful feature in prettyst now comes to typstyle!

Currently it it works in most cases, no matter with multiline cells or comments, except the following:

  • Has multiline Str or Raw descendants.
  • Not following a linebreak when in MathDelimited or Args.
  • Across args of functions such as cases.
  • Exceeds the width limit.
    In these cases, the whole aligned environment will not be specially treated, just as before.

For example, this code:

$
F_n &= sum_(i=1)^n i^2 & n > 0 \
a &< b+1 & forall b < 1
$
$ sum_(k=1)^n a_k & = (a_1 + a_2 + dots.c \
    & + a_(n-1) + a_n) \
    & = x $
$ ∫_0^∞ &= ∑_(n=1)^∞ & "subject to" & α ≤ β \
  &= ∏_(k=1)^n & "또는" & γ ∈ Δ \
  &= √(π + φ) $
$ vec(1,
2,
3)
  &= (1 + 2 +
      3) + (4 +
      5 + 6) \
  &= sum_(i=1)^3 i +
     sum_(i=4)^6 i $

Will be formatted as:

$
  F_n & = sum_(i=1)^n i^2 &        n > 0 \
    a & < b+1             & forall b < 1 \
$
$
  sum_(k=1)^n a_k & = (a_1 + a_2 + dots.c \
                  & + a_(n-1) + a_n)      \
                  & = x                   \
$
$
  ∫_0^∞ & = ∑_(n=1)^∞ & "subject to" & α ≤ β \
        & = ∏_(k=1)^n &       "또는" & γ ∈ Δ \
        & = √(π + φ)                         \
$
$
  vec(
    1,
    2,
    3
  )    & = (1 + 2 +
           3) + (4 +
           5 + 6)          \
       & = sum_(i=1)^3 i +
         sum_(i=4)^6 i     \
$

Compact Layout

Typstyle now generates more compact results when formatting complex function calls. Similar to what rustfmt does, when the only argument is combinable, it will be put in the same line as the function call. When the last argument is blocky, it will also be put in the same line if possible.
For example, this code:

#figure(
  fletcher.diagram(
    node-outset: .5em,
    node-stroke: .075em,
    node(
      (+1,0,),
      [variable],
      radius: 3em,
    ), // test
  ))

Will be formatted as:

#figure(fletcher.diagram(
  node-outset: .5em,
  node-stroke: .075em,
  node((+1, 0), [variable], radius: 3em), // test
))

For another example, this code:

#set page(
  margin: 0.5in,
  footer: context {
    if counter(page).display() == "2" {
      [test]
    } else {
      []
    }
  }
)

Will be formatted as:

#set page(margin: 0.5in, footer: context {
  if counter(page).display() == "2" {
    [test]
  } else {
    []
  }
})

Due to the limitations of the currently used pretty engine, there is still much room for improvement in some cases. In future versions, we will prioritize improving this feature.

Reordering Import Items

It was introduced early in 0.13.2, and now it is stabilized and enabled by default.

To avoid destruction, it will not work in case of comments or duplicated names.

For example, this code:

#import "common.typ": format
#import "common.typ": layout as l, render
#import "common.typ": style.color, transform as t
#import "common.typ": data.table, data.chart as graph
#import "special.typ": _hidden, a.b.c.d.e.f, _private.func as _f, x-y-z as x_y_z, very.deep.nested.module.function as fn

Will be formatted as:

#import "common.typ": format
#import "common.typ": layout as l, render
#import "common.typ": style.color, transform as t
#import "common.typ": data.chart as graph, data.table

#import "special.typ": (
  _hidden,
  _private.func as _f,
  a.b.c.d.e.f,
  very.deep.nested.module.function as fn,
  x-y-z as x_y_z,
)
7 Likes

image

3 Likes