# Lambda Draw

> Diagram production for λambda — ANY teaching figure OR data chart, any subject. Graphical models (BNs, Markov chains, HMMs, DBNs, jointrees) AND quantitative charts (time-series, line/bar plots, distributions, option-payoff diagrams). Use for "/lambda-draw <description>" or whenever a session's teaching step needs a figure or a chart. Picks the medium (mermaid / mermaid xychart / TikZ / DOT / ASCII), enforces the compile→render→LOOK→fix loop for TikZ and a trace-every-point check for data charts; nothing unviewed or unverified is ever embedded.

- Skill: `abaj8494/lambda-draw` (Agent Skill)
- Install (CLI): `npx skillmds@latest add abaj8494/lambda-draw`
- Raw SKILL.md: https://api.skillmd.com/api/skills/abaj8494/lambda-draw/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Coding & Dev Tools
- Author: abaj8494 (https://skillmd.com/u/abaj8494)
- Updated: 2026-09-17
- Page: https://skillmd.com/skills/abaj8494/lambda-draw

---


# λambda draw protocol

Diagrams for three destinations: live session files, vault course notes,
and Anki cards. The failure mode this skill exists to kill: TikZ written
blind and shipped unverified. **You have vision — every figure gets
rendered and looked at before it is embedded, no exceptions.**

## Medium decision table

| Situation | Medium | Why |
|---|---|---|
| Plan DAGs, quick structure inside a live session | **mermaid** | renders instantly in Obsidian/GitHub; zero toolchain; fine for arrows-and-boxes |
| Course figures and Anki cards: BNs with observed/latent shading, HMM/DBN time slices, plates, message passing | **TikZ** (default) | course-faithful notation; Anki's builtin LaTeX already renders it |
| Layout is the hard part: moral graphs, jointrees, >12 nodes, elimination orderings | **DOT → `dot -Tsvg`** | graphviz auto-layout beats hand-placing; optionally use the result as a layout draft for TikZ |
| Quantitative data: a time-series, a line/bar plot, a distribution, an option-payoff diagram | **mermaid `xychart-beta`** (renders natively in the app), or a labelled ASCII/Unicode plot in a code fence | native render, no toolchain; ASCII when the plot is small or xychart fights you — see the rules below, this is where wrong charts ship |

## Quantitative charts (a chart is a claim — the trap that shipped a wrong graph)

A wrong chart is a wrong claim delivered with false confidence. On surfaces
where you cannot compile-and-LOOK (mermaid in chat, the lounge), the LOOK step
becomes a **trace-every-point check you run in your head before emitting**.

**mermaid `xychart-beta` — all binding:**
- **x-axis category labels MUST be unique.** The band axis keys on the label
  *string*: two identical labels collapse to ONE slot, and any later point
  carrying that label jumps **backward** onto the earlier slot. This is the
  exact bug that shipped — an implied-vol series with
  `x-axis ["pre-Q3","Q3 print","post","pre-Q4","Q4 print","post"]` rendered
  its final point regressed, because the second `"post"` collapsed onto the
  first. For repeating phases, disambiguate: `post-Q3`, `post-Q4`.
- **Data length == x-axis count.** `line [...]` / `bar [...]` with N values
  needs exactly N x-categories, in the same order.
- **y-axis range spans the data:** `y-axis "label" MIN --> MAX`, MIN below the
  smallest value, MAX above the largest — else points clip at the frame.
- **Trace every point before shipping.** Read each value against its (unique)
  x-label and confirm the shape is what you meant: the monotone part is
  monotone, the sawtooth actually saws, the last point sits at the last x.
  This is the data-chart equivalent of the TikZ LOOK.

**Prefer a labelled ASCII/Unicode plot** for a quick trend, ≤ ~8 points, or
when xychart fights you: it renders everywhere (monospace code fence), cannot
collapse labels, and matches the house classical-print style. Hand-place the
marks against a labelled axis and trace them the same way, e.g.:

```
implied vol (pts)
 58 ┤ ●
    │  \        ● rebuild is slow…
 42 ┤   ●______/ \
 38 ┤    \    /   \
 37 ┤     \__/     ●   ← still below, mean-reverting up into the next print
    └────┬────┬────┬────┬────┬────
      pre-Q3  post   Q4  post-Q4
```

**Renderer note:** LambdaMind's chat and session panes render mermaid
natively (```mermaid fences). `xychart-beta` works there; the band-axis
label-collapse is a mermaid property, **not an app bug** — uniqueness is on
you. Never emit a chart you have not traced.

## The TikZ loop (mandatory)

1. Write the picture into the scratchpad using the standalone harness from
   `~/lattice/org-notes/uni/Anki.md` (binding — read it first in any session
   that draws for Anki):
   ```
   \documentclass[tikz,border=3pt]{standalone}
   \usepackage{amsmath,amssymb}
   \usetikzlibrary{arrows.meta,positioning,calc,backgrounds,shapes.geometric,fit}
   \begin{document}
   ...
   \end{document}
   ```
2. `lualatex -interaction=nonstopmode -halt-on-error` in the scratchpad.
3. `pdftoppm -png -r 150` the result.
4. **Read the PNG and inspect it**: arrowheads point the right way; no
   label/edge collisions; observed nodes actually shaded; slices aligned;
   nothing orphaned or overlapping. Fix and recompile.
5. Budget ≤3 compile-view cycles; if it still fights you, simplify the
   figure (fewer nodes, drop the plate, straight edges) rather than
   fight TikZ. A clean simple figure beats a mangled ambitious one.
6. Only a viewed, passing figure may be embedded or pushed to a card.

## PGM drawing conventions

- Latent variables: `\node[vertex] (X1) {$X_1$};` with
  `vertex/.style={circle, draw, minimum size=8mm}`.
- Observed variables: `observed/.style={vertex, fill=gray!30}`.
- DBN/HMM time slices: one column per slice, transition arrows
  horizontal, emission arrows vertical, trailing `\node {$\cdots$}` for
  unrolling. 2-TBN form: two slices + the inter-slice arrows only.
- Plates: `backgrounds` layer + `fit`, label bottom-right.
- Undirected (Markov networks): plain `--` edges, no arrowheads.
- Style names: never bare English words TikZ may own (`out`, `in`, `at`,
  `to`, `node`, `edge`, `every`, `cap` have all bitten). Use `vertex`,
  `observed`, `slice`, `blanket`.
- No pgfplots; hand-draw curves if ever needed.
- Course-faithful notation (check the course's own slides for symbol
  conventions before labelling).

## Slide excerpts (fourth tier — not drawing, extracting)

When a teaching step cites slide/page $N$ of a course PDF, show it:

1. `pdftoppm -png -r 150 -f N -l N <pdf> <scratchpad>/slide` (single page).
2. If only a region matters, crop: `magick <png> -crop WxH+X+Y +repage out.png`
   — then **view the result** to confirm the crop caught the right region.
3. Copy to `<vault>/sessions/assets/<lecture>-s<N>.png`, embed relatively
   in the session file next to the teaching step.

Course slides are copyrighted: excerpts live in the private vault only —
never in anything public, never in the OSS repo, never in shared decks.

## Destinations

- **Vault embed**: save PNG to `<vault>/courses/<course>/figs/<name>.png`
  and embed relatively (`![...](../courses/<course>/figs/<name>.png)` from
  a session file, or wiki-embed). Keep the `.tex` source next to it.
- **Anki card**: the card carries the **bare** `\begin{tikzpicture}...`
  source (never wrapped in `\[...\]`) — only after the local compile
  passed. All Anki.md TikZ rules binding.
- **Session file quick-structure**: mermaid inline; no files.

## Compile hygiene

All compiles run in the scratchpad, never in the vault. Copy in only the
final PNG + tex source. If the vault is a git repo, figures ride the
session's end-of-session commit.

