Quick Start
Get up and running with typstyle in minutes.
Create a simple Typst file:
// example.typ#import "@preview/cetz:0.2.2": draw, canvas,#import"@preview/fletcher:0.5.1"as fletcher:diagram,node,edge#set page( margin:(x:1.2in, y:1in ) )#set text(font:("Times New Roman",)) Mathematical Analysis of Algorithm PerformanceConsider the time complexity analysis for sorting algorithms.The bubble sort algorithm has quadratic time complexity.= Performance Comparison#figure(table(columns:(auto, )+(1fr,)*3,[Algorithm],[Best Case],[Average Case],[Worst Case],[Bubble Sort],$O(n)$,$O(n^2)$,$O(n^2)$,[Quick Sort],$O(n log n)$,$O(n log n)$,$O(n^2)$,[Merge Sort],$O(n log n)$,$O(n log n)$,$O(n log n)$),caption:[Time complexity comparison])The mathematical relationship between input size and execution time can be expressed as:$T(n)&=sum_(i=1)^(n-1) sum_(j=1)^(n-i) 1\&= sum_(i=1)^(n-1) (n-i)\&= sum_(k=1)^(n-1) k "where" k=n-i\&= (n-1)n/2\&= O(n^2)$#figure(canvas(length:1cm,{draw.plot.plot(size:(8,6),x-tick-step:none,y-tick-step:none,{draw.plot.add(((0,0),(1,1),(2,4),(3,9),(4,16)))})}),caption:[Quadratic growth visualization])
// example.typ#import "@preview/cetz:0.2.2": draw, canvas,#import"@preview/fletcher:0.5.1"as fletcher:diagram,node,edge#set page( margin:(x:1.2in, y:1in ) )#set text(font:("Times New Roman",)) Mathematical Analysis of Algorithm PerformanceConsider the time complexity analysis for sorting algorithms.The bubble sort algorithm has quadratic time complexity.= Performance Comparison#figure(table(columns:(auto, )+(1fr,)*3,[Algorithm],[Best Case],[Average Case],[Worst Case],[Bubble Sort],$O(n)$,$O(n^2)$,$O(n^2)$,[Quick Sort],$O(n log n)$,$O(n log n)$,$O(n^2)$,[Merge Sort],$O(n log n)$,$O(n log n)$,$O(n log n)$),caption:[Time complexity comparison])The mathematical relationship between input size and execution time can be expressed as:$T(n)&=sum_(i=1)^(n-1) sum_(j=1)^(n-i) 1\&= sum_(i=1)^(n-1) (n-i)\&= sum_(k=1)^(n-1) k "where" k=n-i\&= (n-1)n/2\&= O(n^2)$#figure(canvas(length:1cm,{draw.plot.plot(size:(8,6),x-tick-step:none,y-tick-step:none,{draw.plot.add(((0,0),(1,1),(2,4),(3,9),(4,16)))})}),caption:[Quadratic growth visualization])
Format it with typstyle:
typstyle example.typ
typstyle example.typ
Output:
// example.typ#import "@preview/cetz:0.2.2": canvas, draw#import "@preview/fletcher:0.5.1" as fletcher: diagram, edge, node#set page(margin: (x: 1.2in, y: 1in))#set text(font: ("Times New Roman",))Mathematical Analysis of Algorithm PerformanceConsider the time complexity analysis for sorting algorithms.The bubble sort algorithm has quadratic time complexity.= Performance Comparison#figure( table( columns: (auto,) + (1fr,) * 3, [Algorithm], [Best Case], [Average Case], [Worst Case], [Bubble Sort], $O(n)$, $O(n^2)$, $O(n^2)$, [Quick Sort], $O(n log n)$, $O(n log n)$, $O(n^2)$, [Merge Sort], $O(n log n)$, $O(n log n)$, $O(n log n)$, ), caption: [Time complexity comparison],)The mathematical relationship between input size and execution time can be expressed as:$ T(n) & =sum_(i=1)^(n-1) sum_(j=1)^(n-i) 1 \ & = sum_(i=1)^(n-1) (n-i) \ & = sum_(k=1)^(n-1) k "where" k=n-i \ & = (n-1)n/2 \ & = O(n^2)$#figure( canvas(length: 1cm, { draw.plot.plot(size: (8, 6), x-tick-step: none, y-tick-step: none, { draw.plot.add(((0, 0), (1, 1), (2, 4), (3, 9), (4, 16))) }) }), caption: [Quadratic growth visualization],)
// example.typ#import "@preview/cetz:0.2.2": canvas, draw#import "@preview/fletcher:0.5.1" as fletcher: diagram, edge, node#set page(margin: (x: 1.2in, y: 1in))#set text(font: ("Times New Roman",))Mathematical Analysis of Algorithm PerformanceConsider the time complexity analysis for sorting algorithms.The bubble sort algorithm has quadratic time complexity.= Performance Comparison#figure( table( columns: (auto,) + (1fr,) * 3, [Algorithm], [Best Case], [Average Case], [Worst Case], [Bubble Sort], $O(n)$, $O(n^2)$, $O(n^2)$, [Quick Sort], $O(n log n)$, $O(n log n)$, $O(n^2)$, [Merge Sort], $O(n log n)$, $O(n log n)$, $O(n log n)$, ), caption: [Time complexity comparison],)The mathematical relationship between input size and execution time can be expressed as:$ T(n) & =sum_(i=1)^(n-1) sum_(j=1)^(n-i) 1 \ & = sum_(i=1)^(n-1) (n-i) \ & = sum_(k=1)^(n-1) k "where" k=n-i \ & = (n-1)n/2 \ & = O(n^2)$#figure( canvas(length: 1cm, { draw.plot.plot(size: (8, 6), x-tick-step: none, y-tick-step: none, { draw.plot.add(((0, 0), (1, 1), (2, 4), (3, 9), (4, 16))) }) }), caption: [Quadratic growth visualization],)
To modify the file directly:
typstyle -i example.typ
typstyle -i example.typ
cat example.typ | typstyle > formatted.typ
cat example.typ | typstyle > formatted.typ
# Format specific filestypstyle -i file1.typ file2.typ# Format entire directorytypstyle -i src/# Format with specific line widthtypstyle -l 100 -i src/
# Format specific filestypstyle -i file1.typ file2.typ# Format entire directorytypstyle -i src/# Format with specific line widthtypstyle -l 100 -i src/
Use check mode in CI/CD to ensure code is properly formatted:
typstyle --check src/typstyle --diff src/
typstyle --check src/typstyle --diff src/
This exits with code 0 if files are properly formatted, non-zero otherwise.
# Set maximum line width to 100 characterstypstyle -l 100 file.typ
# Set maximum line width to 100 characterstypstyle -l 100 file.typ
# Use 4 spaces for indentation instead of default 2typstyle -t 4 file.typ
# Use 4 spaces for indentation instead of default 2typstyle -t 4 file.typ
# Disable automatic import sortingtypstyle --no-reorder-import-items file.typ
# Disable automatic import sortingtypstyle --no-reorder-import-items file.typ
# Enable text wrapping in markuptypstyle --wrap-text file.typ
# Enable text wrapping in markuptypstyle --wrap-text file.typ
- Install Tinymist extension
-
Add to
settings.jsonsettings.json:{"tinymist.formatterMode": "typstyle","editor.formatOnSave": true}{"tinymist.formatterMode": "typstyle","editor.formatOnSave": true}
- Learn about features
- See detailed CLI usage