From 97747c6b5cba57ea33e097a70255e843f391e14a Mon Sep 17 00:00:00 2001 From: ajet Date: Fri, 30 Jan 2026 09:45:24 -1000 Subject: [PATCH] ideate --- dual-mode.md | 22 ++--- hiccup-prototype.md | 18 ++-- typst-mapping.md | 201 ++++++++++++++++++++++++++++++++------------ 3 files changed, 167 insertions(+), 74 deletions(-) diff --git a/dual-mode.md b/dual-mode.md index ba7e7c1..f2cc90f 100644 --- a/dual-mode.md +++ b/dual-mode.md @@ -85,7 +85,7 @@ Using `~()` - the unquote concept from Clojure's syntax-quote: #t"The value is ~(expr)." ;; Hiccup expression returns content -#t"Click ~([:link {:dest url} label]) to continue." +#t"Click ~([:link {:src url} label]) to continue." ;; Conditional #t"Status: ~(if done? 'Complete' 'Pending')" @@ -128,7 +128,7 @@ Same mental model as macro unquote: [:block {:inset "1em"} [:strong name] [:linebreak] [:emph affiliation] [:linebreak] - [:link {:dest (str "mailto:" email)} email]]) + [:link {:src (str "mailto:" email)} email]]) (defn results-table [data] [:table {:columns 2 :align ["left" "right"]} @@ -171,8 +171,8 @@ Same mental model as macro unquote: " ;; Back to hiccup for the technical diagram - [:figure {:caption "System architecture overview."} - [:image {:width "80%"} "architecture.png"]] + [:figure {:caption "System architecture overview." :label :fig/arch} + [:image {:src "architecture.png" :width "80%"}]] #t" Our method works by first processing the input through @@ -198,7 +198,7 @@ Same mental model as macro unquote: " ;; Bibliography could be generated - [:bibliography "refs.bib"]]) + [:bibliography {:src "refs.bib"}]]) ;; Compile it (compile-to-typst paper "paper.typ") @@ -303,7 +303,7 @@ Build mini-languages for specific domains: `(do (register-figure! ~id) [:figure {:label ~id :caption ["Figure " (figure-num ~id) ": " ~caption]} - [:image {:width ~(or width "100%")} ~src]])) + [:image {:src ~src :width ~(or width "100%")}]])) (figure :arch :src "architecture.png" @@ -319,15 +319,15 @@ Build mini-languages for specific domains: ;; Shorthand for references (defmacro ref [id] - `[:ref ~(str "@" (name id))]) + `[:ref {:target ~id}]) ;; Shorthand for citations (defmacro cite [& keys] - `[:cite ~@(map #(str "@" (name %)) keys)]) + `[:cite {:keys [~@keys]}]) ;; Usage -(ref :fig:arch) ; => @fig:arch -(cite :smith2020 :jones2021) ; => @smith2020 @jones2021 +(ref :fig/arch) ; => [:ref {:target :fig/arch}] +(cite :smith2020 :jones2021) ; => [:cite {:keys [:smith2020 :jones2021]}] ``` ### Template Macros @@ -339,7 +339,7 @@ Build mini-languages for specific domains: ~@structure)) (deftemplate ieee-paper [title authors abstract] - [[:set :page {:paper "us-letter" :columns 2}] + [[:set {:element :page :paper "us-letter" :columns 2}] [:heading {:level 1 :align "center"} ~title] (render-authors ~authors) (render-abstract ~abstract) diff --git a/hiccup-prototype.md b/hiccup-prototype.md index f6557dc..ebf6e19 100644 --- a/hiccup-prototype.md +++ b/hiccup-prototype.md @@ -40,26 +40,24 @@ Hiccup represents markup as nested data structures: ;; [1], [2], [3] ;; ) -;; Raw content blocks -[:raw "= Direct Typst Markup\nJust passed through"] - -;; Code blocks (use :raw with :lang) +;; Code blocks (use :raw for displayed code) [:raw {:lang "python" :block true} "print('hello')"] ;; => #raw(lang: "python", block: true, "print('hello')") -;; Math +;; Math (inline by default) [:math "x^2 + y^2 = z^2"] ;; => $x^2 + y^2 = z^2$ +;; Math (block/display) [:math {:block true} "sum_(i=0)^n i = (n(n+1))/2"] ;; => $ sum_(i=0)^n i = (n(n+1))/2 $ -;; Images -[:image {:width "50%"} "diagram.png"] +;; Images (src in attrs, no children) +[:image {:src "diagram.png" :width "50%"}] ;; => #image("diagram.png", width: 50%) -;; Links -[:link {:dest "https://typst.app"} "Typst"] +;; Links (src in attrs, child is display text) +[:link {:src "https://typst.app"} "Typst"] ;; => #link("https://typst.app")[Typst] ``` @@ -85,7 +83,7 @@ Hiccup represents markup as nested data structures: [:heading {:level 2} "Results"] - "The result is " [:$ "x = 42"] "." + "The result is " [:math "x = 42"] "." [:table {:columns 2} [:strong "Input"] [:strong "Output"] diff --git a/typst-mapping.md b/typst-mapping.md index 84d1faa..8792fda 100644 --- a/typst-mapping.md +++ b/typst-mapping.md @@ -1,5 +1,84 @@ # Hiccup → Typst Mapping Reference +## Hiccup Syntax + +All elements follow standard Hiccup: + +```clojure +[:tag {attrs} children...] +``` + +- **tag**: Element type (keyword) +- **attrs**: Optional map of attributes +- **children**: Content (strings, nested elements, or expressions) + +### Element Categories + +| Category | Examples | Children | +|----------|----------|----------| +| Content elements | `heading`, `strong`, `emph`, `block` | Display content | +| Source elements | `link`, `image`, `bibliography` | `link` has display text; others have none | +| List elements | `list`, `enum`, `table` | Each child = one item/cell | +| Container elements | `figure` | Single content child (compiled as function arg) | +| Math | `math` | Math expression string | +| References | `ref`, `cite` | None | +| Code | `raw` | Code string to display | +| Rules | `set` | None | +| Show rules | `show` | A `set` rule as child | + +### Reserved Attributes + +| Attr | Used by | Purpose | +|------|---------|---------| +| `:src` | `link`, `image`, `bibliography` | Source URL/path | +| `:label` | Any element | Makes element referenceable | +| `:caption` | `figure` | Figure caption text | +| `:target` | `ref` | Label to reference | +| `:keys` | `cite` | Citation key(s) | +| `:element` | `set`, `show` | Element type to configure | +| `:block` | `math`, `raw` | Display as block (default: inline) | +| `:lang` | `raw` | Code language for syntax highlighting | + +### Examples + +```clojure +;; Content element +[:heading {:level 2} "Section Title"] + +;; Source element with children +[:link {:src "https://example.com"} "Click here"] + +;; Source element without children +[:image {:src "diagram.png" :width "80%"}] + +;; List element +[:list "First" "Second" "Third"] + +;; Container with label +[:figure {:caption "Results" :label :fig/results} + [:image {:src "chart.png"}]] + +;; Math (inline and block) +[:math "E = m c^2"] +[:math {:block true} "sum_(i=0)^n i"] + +;; Reference and citation +[:ref {:target :fig/results}] +[:cite {:keys [:smith2020 :jones2021]}] + +;; Code display +[:raw {:lang "python" :block true} "print('hello')"] + +;; Set rule +[:set {:element :page :margin "2cm"}] + +;; Show rule (child is the set rule to apply) +[:show {:element :heading} + [:set {:element :text :fill "blue"}]] +``` + +--- + ## Audit of Current Tags ### ✅ Valid - Direct Typst Functions @@ -9,10 +88,10 @@ | `[:heading {:level 2} "Text"]` | `#heading(level: 2)[Text]` | ✅ Works | | `[:strong "text"]` | `#strong[text]` | ✅ Works | | `[:emph "text"]` | `#emph[text]` | ✅ Works | -| `[:link {:dest "url"} "text"]` | `#link("url")[text]` | ✅ Works | -| `[:image {:width "50%"} "path.png"]` | `#image("path.png", width: 50%)` | ✅ Works | +| `[:link {:src "url"} "text"]` | `#link("url")[text]` | ✅ Works | +| `[:image {:src "path.png" :width "50%"}]` | `#image("path.png", width: 50%)` | ✅ Works | | `[:block {:inset "1em"} ...]` | `#block(inset: 1em)[...]` | ✅ Works | -| `[:bibliography "refs.bib"]` | `#bibliography("refs.bib")` | ✅ Works | +| `[:bibliography {:src "refs.bib"}]` | `#bibliography("refs.bib")` | ✅ Works | ### ❌ Invalid - Don't Exist in Typst @@ -34,11 +113,8 @@ |---------|---------|---------| | `[:linebreak]` | Function name | `[:linebreak]` → `#linebreak()` ✅ actually works | | `[:h-space "2em"]` | Wrong name | `[:h "2em"]` → `#h(2em)` | -| `[:figure [:image ...] [:caption ...]]` | Caption isn't a child | See below | -| `[:math "x^2"]` | Need to distinguish inline/block | `$x^2$` vs `$ x^2 $` | -| `[:code {:lang "py"} "..."]` | Function is `raw` | `#raw(lang: "python", "...")` | -| `[:ref :label]` | Takes label not string | `#ref(