Skip to content

Instantly share code, notes, and snippets.

@esafwan
Created April 19, 2024 15:36
Show Gist options
  • Save esafwan/9f75be44d6a5e232acc8a41d76f90efe to your computer and use it in GitHub Desktop.
Save esafwan/9f75be44d6a5e232acc8a41d76f90efe to your computer and use it in GitHub Desktop.
short & Simple Typst Guide (WIP)

Image in Typst:

image in typst(raster/vector.Support: PNG, JPEG, GIF & SVG. Params:

image(
str,
format: autostr,
width: autorelative,
height: autorelative,
alt: nonestr,
fit: str, // opts- cover(default),contain, stretch
)

Eg: #image("molecular.jpg", width: 80%)

#figure(
  image("molecular.jpg", width: 80%),
  caption: [
    A step in the molecular testing
    pipeline of our lab.
  ],
)

Template in Typst:

Function with Named Params:

Eg of a function (sparkles & text color):

     //Create
     #let amazed(term, color: blue) = {
       text(color, box[✨ #term ✨])
     }
     //Use
     You are #amazed[beautiful]!
     I am #amazed(color: purple)[amazed]!

Show Rules

Set and Show Rules Embedded:

//create
     #let template(doc) = [
       #set text(font: "Inria Serif")
       #show "something cool": [Typst]
       #doc
     ]

//use
     #show: template
     I am learning something cool today.
     It's going great so far!

Adv. templates (structured):

    //Create Function
     #let conf(title, doc) = {
       set page(paper: "us-letter", header: align(right + horizon, title))
       set par(justify: true)
       set text(font: "Linux Libertine", size: 11pt)
       columns(2, doc)
     }
     
    //Use
     #show: doc => conf([Paper title], doc)
     = Introduction
     #lorem(90)

Importing & Reusing

 > conf.typ
     #let conf(title: none, authors: (), abstract: [], doc) = {
       set align(center)
       text(17pt, title)
       grid(columns: (1fr,) * calc.min(authors.len(), 3), row-gutter: 24pt, ..authors.map(author => [#author.name \ #author.affiliation \ #link("mailto:" + author.email)]))
       par(justify: false)[*Abstract* \ #abstract]
       set align(left)
       columns(2, doc)
     }

Importing and Using:

     #import "conf.typ": conf
     #show: doc => conf(
       title: [Towards Improved Modelling],
       authors: (
         (
           name: "Theresa Tungsten",
           affiliation: "Artos Institute",
           email: "tung@artos.edu",
         ),
         (
           name: "Eugene Deklan",
           affiliation: "Honduras State",
           email: "e.deklan@hstate.hn",
         ),
       ),
       abstract: lorem(80),
       doc,
     )
     = Introduction
     #lorem(90)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment