Skip to content

Instantly share code, notes, and snippets.

@beeb
Created June 19, 2023 13:06
Show Gist options
  • Save beeb/75259a150e8dadf1a973eaf4151c70aa to your computer and use it in GitHub Desktop.
Save beeb/75259a150e8dadf1a973eaf4151c70aa to your computer and use it in GitHub Desktop.
Product nomenclature template for Typst
#let segments = (
(nomenclature: "4", title: "Refrigerant Type", description: [4 = R-410A \ 2 = R22], separator: ""),
(nomenclature: "TE", title: "Application", description: [TE = Fully Convertible \ TG = Semi Convertible], separator: "-"),
(nomenclature: "E", title: "Product Family", description: [E = Leadership -- Variable Speed \ P = Leadership], separator: "-"),
)
#let nomenclature(
segments: ((nomenclature: "A", title: "Foo", description: [Bar], separator: "-"))
) = {
place(top + left, [#box()#label("margins")]) // get top + left margins dynamically
let widths = state("widths", 0) // records the width of each segment in the example line
align(right,
for (i, seg) in segments.enumerate() {
// store segment in a variable to measure its width
let body = [ #box(underline(offset: 3pt, stroke: 1pt,seg.nomenclature))#label("nom_segment_" + str(i)) ]
style(styles => {
let size = measure(body, styles)
widths.update(size.width) // store width of the segment
body // display segment
})
if i < segments.len()-1 {
[#seg.separator] // don't display separator after the last segment
}
}
)
for (i, seg) in segments.enumerate() {
[== #seg.title #box()#label("nom_title_" + str(i))]
[#seg.description]
locate(loc => {
let top_left = query(label("margins"), loc).first().location().position() // get margins
let begin = query(label("nom_title_" + str(i)), loc).first().location().position()
let segment = query(label("nom_segment_" + str(i)), loc).first()
let end = segment.location().position()
let width = widths.at(segment.location())
let endPath = (end.x + (width / 2), end.y + 1em + 0.1cm)
place(
top + left,
dx: -top_left.x,
dy: -top_left.y,
path(
(begin.x, begin.y - 0.3em),
(end.x + (width / 2),
begin.y - 0.3em),
endPath
)
)
place(
top + left,
dx: -top_left.x,
dy: -top_left.y,
polygon(
fill: black,
stroke: none,
(endPath.at(0), endPath.at(1) - 0.1cm),
(endPath.at(0) - 0.1cm, endPath.at(1) + 0.2cm),
(endPath.at(0) + 0.1cm, endPath.at(1) + 0.2cm)
)
)
})
}
}
= Air Handlers - Residential
#nomenclature(segments: segments)
@taylorh140
Copy link

This seems to have an issue with sizing. trying to make two of these breaks the arrow lengths.

@beeb
Copy link
Author

beeb commented Jun 19, 2023

This seems to have an issue with sizing. trying to make two of these breaks the arrow lengths.

I think that makes sense. If you use this function more than once, you will probably have duplicate labels and conflicting states.

Using more than one would require some way to add a unique identifier to each of the labels and the state, maybe adding a unique name as an additional parameter which would be included in each label id and state id.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment