Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions packages/preview/labtyp/0.1.0/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2025 evidlabel

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
41 changes: 41 additions & 0 deletions packages/preview/labtyp/0.1.0/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# `labtyp`

`labtyp` is a package that allows using typst for labelling text documents like dialogue threads or legal documents for precise citing.

A json file with the labels in a document can be produced using `typst query`:

```bash
typst query main.typ <lab> > doclabels.json
```
Which can then be translated into `hayagriva` or `biblatex` formats.

`labtyp` defines 3 commands:

- `lab`: creates an in-place label, defined by key, text, note
- `mset`: adds metadata that gets assigned to _subsequent labels_ (i.e. labels defined below the current mset command in the document), like the title of the document, date, pagenumber in the original document, this can be expanded with any key
- Each label ends up being a concatenation of the label information, and the mset information.
- `lablist`: prints a table of the labels created

## Test document
```typst
#import "@preview/labtyp:0.1.0": mset, lab, lablist

#mset(values: (
title: "My Document",
author: "John Doe",
date: "2025-07-31"
))

= Heading
== Subheading
This is some text.

#lab("key", "Highlighted text", "This is a note") // Creates underlined text and footnote

#mset(values: (date: "2025-08-01")) // Redefine date for subsequent labels
= Another Heading
#lab("key2", "More text", "Another note")

= List of Labels
#lablist() // Displays a table of all labels with hyperlinks
```
59 changes: 59 additions & 0 deletions packages/preview/labtyp/0.1.0/lib.typ
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// State to track the current headings hierarchy
#let current-headings = state("current-headings", ())

// State for document metadata
#let document-metadata = state("document-metadata", (:))

// Function to update document metadata
#let mset(values: (:)) = {
document-metadata.update(old => {
let updated = old
for (k, v) in values {
updated.insert(k, v)
}
updated
})
}

// Function to create a label with underlined text, footnote, and metadata
#let lab(key, text, note) = {
context [
#let meta = document-metadata.at(here())
#underline(stroke: blue)[#text]#footnote[#key: #note]#hide[
#metadata( meta + (
key: key,
text: text,
note: note,
page: counter(page).at(here()).first(),
)) <lab>
]
]
}

// Function to list all labels in a table with hyperlinks
#let lablist() = {
context {
let labels = query(selector(<lab>))
if labels.len() == 0 {
[No labels found.]
} else {
table(
columns: (auto, auto, auto, auto, auto, auto, auto, auto),
[*Key*], [*Text*], [*Note*], [*Page*], [*Original Page*], [*Title*], [*Author*], [*Date*],
..labels.map(l => {
let data = l.value
(
link(l.location(), data.at("key", default: [Undefined])),
link(l.location(), data.at("text", default: [Undefined])),
link(l.location(), data.at("note", default: [Undefined])),
link(l.location(), str(data.at("page", default: 0))),
link(l.location(), if data.at("page", default: none) != none { str(data.at("page")) } else { [Undefined] }),
link(l.location(), data.at("title", default: [Undefined])),
link(l.location(), data.at("author", default: [Undefined])),
link(l.location(), data.at("date", default: [Undefined]))
)
}).flatten()
)
}
}
}
Binary file added packages/preview/labtyp/0.1.0/preview.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
73 changes: 73 additions & 0 deletions packages/preview/labtyp/0.1.0/template/main.typ
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#import "@preview/labtyp:0.1.0": lablist, lab, mset
// #import "../lib.typ": lablist, lab, mset

#mset(values: (
title: "The title of the document",
author: "Jane Doe",
date: "2025-07-31",
newlab: "more"))

= `labtyp`
`labtyp` is for labeling text documents like dialogue threads or legal documents for precise citing.

// A json file with the labels in a document can be produced using `typst query`

// ```bash
// typst query main.typ <lab> > doclabels.json
// ```
// Which can then be translated into `hayagriva` or `biblatex` formats.


// `labtyp` defines 3 commands:

// - `lab`: creates an in-place label, defined by `key`, `text` and `note`
// - `mset`: adds metadata that gets assigned to _subsequent labels_ (i.e. labels defined below the current mset command in the document), like the title of the document, date, pagenumber in the original document, this can be expanded with any key for other labelling needs

// - Each label ends up being a concatenation of the label information, and the mset information.
// - `lablist`: prints a table of the labels created


// #mset(values: (opage: 1))
// #mset(values: (date: "2025-08-01", opage: 2))

// = Labelling in vscode

// In order to label currently selected text in vscode using `ctrl+L`, define the following in `keybindings.json`:

// ```json
// {
// "key": "ctrl+L",
// "command": "editor.action.insertSnippet",
// "when": "editorTextFocus && editorLangId == 'typst'",
// "args": {"snippet": "#lab(\"$1\",\"${TM_SELECTED_TEXT}\",\"$2\")"}
// }
// ```
= Example
This is what a labelled document looks like in typst:
```typst
#mset(values: (
title: "The title of the document",
author: "Jane Doe",
date: "2025-07-31",
newlab: "more"))
=== A labelled dialogue
#mset(values:(date:"2025-07-1", author:"X"))
X: #lab("mail1","Can you get some rice and coffee on the way home","email by X to Y")
#mset(values:(date:"2025-07-2", author:"Y"))
Y: #lab("mail2","Sorry, I didn't check my mail.. ","reply by Y to X")
= List of Labels
#lablist()
```
== Rendered
Below the same dialogue rendered:

=== A labelled dialogue
#mset(values:(date:"2025-07-1", author:"X"))
X: #lab("mail1","Can you get some rice and coffee on the way home","email by X to Y")

#mset(values:(date:"2025-07-2", author:"Y"))

Y: #lab("mail2","Sorry, I didn't check my mail.. ","reply by Y to X")

= List of Labels
#lablist()
16 changes: 16 additions & 0 deletions packages/preview/labtyp/0.1.0/typst.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[package]
name = "labtyp"
version = "0.1.0"
entrypoint = "lib.typ"
authors = ["evidlabel"]
license = "MIT"
description = "Label text and extract to json using typst query"
repository = "https://github.com/evidlabel/labtyp" # Optional, update if hosting on GitHub
keywords = ["headings", "labels", "footnotes", "metadata", "hyperlinks"]
categories = ["utility"]


[template]
path = "template"
entrypoint = "main.typ"
thumbnail = "preview.png"