• Stars
    star
    162
  • Rank 232,284 (Top 5 %)
  • Language Typst
  • License
    MIT License
  • Created about 1 year ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Relative positioning by pins, especially useful for making slides in typst.

Pinit

Relative positioning by pins, especially useful for making slides in typst.

Example

Pin things as you like

Have a look at the source here.

Example

Dynamic Slides

Pinit works with Touying or Polylux animations.

Have a look at the pdf file here.

Example Pages

Usage

Examples

The idea of pinit is pinning pins on the normal flow of the text, and then placing the content on the page by absolute-place function.

For example, we can highlight text and add a tip by pins simply:

#import "@preview/pinit:0.1.4": *

#set text(size: 24pt)

A simple #pin(1)highlighted text#pin(2).

#pinit-highlight(1, 2)

#pinit-point-from(2)[It is simple.]

simple-demo

A more complex example, Have a look at the source here.

equation-desc

Pinit for raw

In the code block, we need to use a regex trick to get pinit to work, for example

#show raw: it => {
  show regex("pin\d"): it => pin(eval(it.text.slice(3)))
  it
}

`print(pin1"hello, world"pin2)`

#pinit-highlight(1, 2)

equation-desc

Note that typst's code highlighting breaks up the text, causing overly complex regular expressions such as '#pin(.*?)' to not work properly.

However, you may want to consider putting it in a comment to avoid highlighting the text and breaking it up.


Warning: You should add a blank line before the #pinit-xxx function call, otherwise it will cause misalignment.


Outline

Reference

pin

Pinning a pin in text, the pin is supposed to be unique in one page.

#let pin(name) = { .. }

Arguments:

  • name: [integer or string or any] — Name of pin, which can be any types with unique repr() return value, such as integer and string.

pinit

Query positions of pins in the same page, then call the callback function func.

#let pinit(pins, func) = { .. }

Arguments:

  • pins: [pin or array] — Names of pins you want to query. It is supposed to be a pin, or an array of pins.
  • func: [(positions) => { .. }] — A callback function accepting an array of positions (or a single position) as a parameter. Each position is a dictionary like (page: 1, x: 319.97pt, y: 86.66pt). You can use the absolute-place function in this callback function to display something around the pins.

absolute-place

Place content at a specific location on the page relative to the top left corner of the page, regardless of margins, current containers, etc.

This function comes from typst-drafting.

#let absolute-place(
  dx: 0em,
  dy: 0em,
  content,
) = { .. }

Arguments:

  • dx: [length] — Length in the x-axis relative to the left edge of the page.
  • dy: [length] — Length in the y-axis relative to the top edge of the page.
  • content: [content] — The content you want to place.

pinit-place

Place content at a specific location on the page relative to the pin.

#let pinit-place(
  dx: 0pt,
  dy: 0pt,
  pin-name,
  body,
) = { .. }

Arguments:

  • dx: [length] — Offset X relative to the pin.
  • dy: [length] — Offset Y relative to the pin.
  • pin-name: [pin] — Name of the pin to which you want to locate.
  • body: [content] — The content you want to place.

pinit-rect

Draw a rectangular shape on the page containing all pins with optional extended width and height.

#let pinit-rect(
  dx: 0em,
  dy: -1em,
  extended-width: 0em,
  extended-height: 1.4em,
  pin1,
  pin2,
  pin3,  // Optional
  ..pinX,
  ..args,
) = { .. }

Arguments:

  • dx: [length] — Offset X relative to the min-left of pins.
  • dy: [length] — Offset Y relative to the min-top of pins.
  • extended-width: [length] — Optional extended width of the rectangular shape.
  • extended-height: [length] — Optional extended height of the rectangular shape.
  • pin1: [pin] — One of these pins.
  • pin2: [pin] — One of these pins.
  • pin3: [pin] — One of these pins, optionally.
  • ...args: Additional named arguments or settings for rect, like fill, stroke and radius.

pinit-highlight

Highlight a specific area on the page with a filled color and optional radius and stroke. It is just a simply styled pinit-rect.

#let pinit-highlight(
  fill: rgb(255, 0, 0, 20),
  radius: 5pt,
  stroke: 0pt,
  dx: 0em,
  dy: -1em,
  extended-width: 0em,
  extended-height: 1.4em,
  pin1,
  pin2,
  pin3,  // Optional
  ..pinX,
  ...args,
) = { .. }

Arguments:

  • fill: [color] — The fill color for the highlighted area.
  • radius: [length] — Optional radius for the highlight.
  • stroke: [stroke] — Optional stroke width for the highlight.
  • dx: [length] — Offset X relative to the min-left of pins.
  • dy: [length] — Offset Y relative to the min-top of pins.
  • extended-width: [length] — Optional extended width of the rectangular shape.
  • extended-height: [length] — Optional extended height of the rectangular shape.
  • pin1: [pin] — One of these pins.
  • pin2: [pin] — One of these pins.
  • pin3: [pin] — One of these pins, optionally.
  • ...args: Additional arguments or settings for pinit-rect.

pinit-line

Draw a line on the page between two specified pins with an optional stroke.

#let pinit-line(
  stroke: 1pt,
  start-dx: 0pt,
  start-dy: 0pt,
  end-dx: 0pt,
  end-dy: 0pt,
  start,
  end,
) = { ... }

Arguments:

  • stroke: [stroke] — The stroke for the line.
  • start-dx: [length] — Offset X relative to the start pin.
  • start-dy: [length] — Offset Y relative to the start pin.
  • end-dx: [length] — Offset X relative to the end pin.
  • end-dy: [length] — Offset Y relative to the end pin.
  • start: [pin] — The start pin.
  • end: [pin] — The end pin.

pinit-line-to

Draw an line from a specified pin to a point on the page with optional settings.

#let pinit-line-to(
  stroke: 1pt,
  pin-dx: 5pt,
  pin-dy: 5pt,
  body-dx: 5pt,
  body-dy: 5pt,
  offset-dx: 35pt,
  offset-dy: 35pt,
  pin-name,
  body,
) = { ... }

Arguments:

  • stroke: [stroke] — The stroke for the line.
  • pin-dx: [length] — Offset X of arrow start relative to the pin.
  • pin-dy: [length] — Offset Y of arrow start relative to the pin.
  • body-dx: [length] — Offset X of arrow end relative to the body.
  • body-dy: [length] — Offset Y of arrow end relative to the body.
  • offset-dx: [length] — Offset X relative to the pin.
  • offset-dy: [length] — Offset Y relative to the pin.
  • pin-name: [pin] — The name of the pin to start from.
  • body: [content] — The content to draw the arrow to.

pinit-arrow

Draw an arrow between two specified pins with optional settings.

#let pinit-arrow(
  start-dx: 0pt,
  start-dy: 0pt,
  end-dx: 0pt,
  end-dy: 0pt,
  start,
  end,
  ..args,
) = { ... }

Arguments:

  • start-dx: [length] — Offset X relative to the start pin.
  • start-dy: [length] — Offset Y relative to the start pin.
  • end-dx: [length] — Offset X relative to the end pin.
  • end-dy: [length] — Offset Y relative to the end pin.
  • start: [pin] — The start pin.
  • end: [pin] — The end pin.
  • ...args: Additional arguments or settings for simple-arrow, like fill, stroke and thickness.

pinit-point-to

Draw an arrow from a specified pin to a point on the page with optional settings.

#let pinit-point-to(
  pin-dx: 5pt,
  pin-dy: 5pt,
  body-dx: 5pt,
  body-dy: 5pt,
  offset-dx: 35pt,
  offset-dy: 35pt,
  pin-name,
  body,
  ..args,
) = { ... }

Arguments:

  • pin-dx: [length] — Offset X of arrow start relative to the pin.
  • pin-dy: [length] — Offset Y of arrow start relative to the pin.
  • body-dx: [length] — Offset X of arrow end relative to the body.
  • body-dy: [length] — Offset Y of arrow end relative to the body.
  • offset-dx: [length] — Offset X relative to the pin.
  • offset-dy: [length] — Offset Y relative to the pin.
  • pin-name: [pin] — The name of the pin to start from.
  • body: [content] — The content to draw the arrow to.
  • ...args: Additional arguments or settings for simple-arrow, like fill, stroke and thickness.

pinit-point-from

Draw an arrow from a point on the page to a specified pin with optional settings.

#let pinit-point-from(
  pin-dx: 5pt,
  pin-dy: 5pt,
  body-dx: 5pt,
  body-dy: 5pt,
  offset-dx: 35pt,
  offset-dy: 35pt,
  pin-name,
  body,
  ..args,
) = { ... }

Arguments:

  • pin-dx: [length] — Offset X relative to the pin.
  • pin-dy: [length] — Offset Y relative to the pin.
  • body-dx: [length] — Offset X relative to the body.
  • body-dy: [length] — Offset Y relative to the body.
  • offset-dx: [length] — Offset X relative to the left edge of the page.
  • offset-dy: [length] — Offset Y relative to the top edge of the page.
  • pin-name: [pin] — The name of the pin that the arrow to.
  • body: [content] — The content to draw the arrow from.
  • ...args: Additional arguments or settings for simple-arrow, like fill, stroke and thickness.

simple-arrow

Draw a simple arrow on the page with optional settings, implemented by polygon.

#let simple-arrow(
  fill: black,
  stroke: 0pt,
  start: (0pt, 0pt),
  end: (30pt, 0pt),
  thickness: 2pt,
  arrow-width: 4,
  arrow-height: 4,
  inset: 0.5,
  tail: (),
) = { ... }

Arguments:

  • fill: [color] — The fill color for the arrow.
  • stroke: [stroke] — The stroke for the arrow.
  • start: [point] — The starting point of the arrow.
  • end: [point] — The ending point of the arrow.
  • thickness: [length] — The thickness of the arrow.
  • arrow-width: [integer or float] — The width of the arrowhead relative to thickness.
  • arrow-height: [integer or float] — The height of the arrowhead relative to thickness.
  • inset: [integer or float] — The inset value for the arrowhead relative to thickness.
  • tail: [array] — The tail settings for the arrow.

Acknowledgements

  • Some of the inspirations and codes comes from typst-drafting.
  • Thanks to polylux, you can create beautiful and dynamic slides by polylux simply.
  • The concise and aesthetic example slide style come from course Data Structures and Algorithms of Chaodong ZHENG.

License

This project is licensed under the MIT License.

More Repositories

1

NJUAI-Notes

我在南京大学人工智能专业学习时所做的笔记 :-)
Terra
548
star
2

Chinese-Resume-in-Typst

使用 Typst 编写的中文简历, 语法简洁, 样式美观, 开箱即用, 可选是否显示照片
Typst
289
star
3

Latex-Sympy-Calculator

Convert Latex to Sympy and calculate it in Latex or Markdown in VSCode.
JavaScript
87
star
4

GitNotes

一个在浏览器上运行的笔记浏览应用, 用于浏览以 Markdown 书写的, 存放在 GitLab 或 GitHub 上的笔记.
TypeScript
80
star
5

OrangeX4-HyperSnips

OrangeX4's HyperSnips
53
star
6

typst-talk

并不复杂的 Typst 讲座 - Typst is Simple
Typst
50
star
7

typst-tablem

Write markdown-like tables easily.
Typst
38
star
8

simple-pinyin

simple-pinyin 基于隐马尔可夫模型的简易拼音输入法(拼音转汉字)
Python
38
star
9

vscode-typst-sympy-calculator

VS Code extension for Typst math calculating, includes Arithmetic, Calculous, Matrix, Custom Variances and Funcions by yourself
JavaScript
36
star
10

typst-sympy-calculator

Parse typst math expressions into sympy form for calc and define your custom functions in typst files.
Python
30
star
11

vscode-smart-ime

在 VS Code 中智能地进行中英输入法的切换
TypeScript
28
star
12

GitHub-Tutorials

GitHub 简易指南。
26
star
13

typst-cheq

Write markdown-like checklist easily.
Typst
26
star
14

hexo-link-card

Convert a link to a link card via existing markdown grammar. 使用现有 Markdown 语法将链接转换为卡片式链接.
21
star
15

Orangex-Mobile

A useful tool chain for mobile coding with termux.
JavaScript
21
star
16

Termux-Finux

A file manager for mobile linux like termux.
JavaScript
19
star
17

drawio-function-plot-plugin

Function Plot plugin for Draw.io Desktop.
JavaScript
16
star
18

Reversi

黑白棋前端界面与 AI 实现.
TypeScript
14
star
19

vscode-typst-sync

A vscode extension for Typst local packages management and synchronization.
TypeScript
12
star
20

Better-Markdown-Latex-Shortcuts

Providing some useful shortcuts for markdown with latex.
TypeScript
10
star
21

Orangex-Translator

中 文 编 程 , 最 为 致 命
TypeScript
8
star
22

Python-Brackets

A convenient way to nest brackets in python with VSCode.
TypeScript
7
star
23

Warma

Warma!
HTML
6
star
24

OrangeX4

OrangeX4
6
star
25

Auto-Vscode-Cpp

自动搭建基于Vscode和MinGW的C语言和C++开发环境. Automatically install the environment for Vscode and C++.
Python
5
star
26

Reversi-Back

黑白棋后端.
Python
4
star
27

typst-sympy-calculator.typ

typst-sympy-calculator.typ
Typst
3
star
28

cheatsheets

OrangeX4's cheatsheets website.
CSS
3
star
29

marp-pdr

JavaScript
3
star
30

RegExr-for-VSCode

RegExr for VSCode
JavaScript
2
star
31

Orangex-UI

UI for orangex.
TypeScript
2
star
32

Orangex-Docs

Orangex Docs
2
star
33

Orangex-s-Deep-Learning-Notes

Orangex's Deep Learning Notes with PyTorch.
Jupyter Notebook
2
star
34

Leetcode

Some my answers for Leetcode.
Python
2
star
35

autodiff-frontend

autodiff-frontend
JavaScript
1
star
36

PoseKey-Desktop

An app that can recognize poses and map them into keys.
Jupyter Notebook
1
star
37

PoseKey-Android

An app that recognizes your poses and maps them into keys.
Java
1
star
38

Guess-Words

Guess Words
JavaScript
1
star
39

autodiff

autodiff - software engineering project
Python
1
star
40

AFox

ANeko -> AFox
Java
1
star
41

Selector

Selector for windows。
1
star
42

First-Pull-Requests

用于接收 pull requests 的仓库.
1
star
43

Finux-vue

File manager for mobile linux like Termux.
Vue
1
star
44

gvgai-assignment1

gvgai-assignment1
Java
1
star
45

live2d

JavaScript
1
star
46

ParallelComputing

Project of ParallelComputing
Java
1
star