Skip to content

Instantly share code, notes, and snippets.

@mpizenberg
Created April 3, 2023 07:28
Show Gist options
  • Save mpizenberg/c6ed7bc3992ee5dfed55edce508080bb to your computer and use it in GitHub Desktop.
Save mpizenberg/c6ed7bc3992ee5dfed55edce508080bb to your computer and use it in GitHub Desktop.
Example for code blocks in Typst
#set par(justify: true)
*Goal*: being able to add line numbers, which are correct even in case of long lines that need wrapping.
*Strategy*: duplicate the code block, once for getting the line numbers correct, and the other for syntax highlighting. The idea is to split lines and prefix each line with its line number such that line wrapping should be respected.
#show raw.where(block: true): it => { set par(justify: false); grid(
columns: (100%, 100%),
column-gutter: -100%,
block(width: 100%, inset: 1em, for i, line in it.text.split("\n") {
box(width: 0pt, align(right, str(i + 1) + h(2em)))
hide(line)
linebreak()
}),
block(radius: 1em, fill: luma(246), width: 100%, inset: 1em, it),
)}
#set text(size: 12pt)
#let code = read("config-pascal.json")
#raw(code, block:true, lang: "json")
```haskell
Bool = True | False
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment