zettelkasten.equation_snapshot¶
zettelkasten.equation_snapshot ¶
Equation snapshots: crop the source-PDF region for an equation note.
PDF text extraction destroys math (symbols become mojibake or vanish, structure linearizes), so the LaTeX an equation note carries in its body is a transcription — not verbatim. The visual ground-truth is the equation as it actually appears in the source, so this module renders that region to a committed PNG sidecar.
Given a source graph, it resolves the original PDF from the source's committed
pointer (source_path or zotero_key in _meta.yaml), renders the
relevant page with pypdfium2, optionally crops to a rectangle (typically a Zotero
image/area annotation the reader drew around the equation), and writes the crop
to <graph>/_equations/<note_id>.png. The pointer it returns
({path, content_hash, page, rect?}) makes the crop reproducible from the
original PDF, mirroring how the full-text cache re-derives from its pointer.
Everything here is best-effort: a missing PDF, an out-of-range page, or an
uninstalled renderer returns an {"error": ...} dict rather than raising, so a
snapshot failure never blocks authoring the equation note itself.
capture_snapshot ¶
capture_snapshot(graph: str, note_id: str, *, page_index: int, page_label: str = '', rect: list[float] | tuple[float, float, float, float] | None = None, scale: float = _DEFAULT_SCALE, subdir: str = SNAPSHOT_SUBDIR) -> dict[str, Any]
Render (and optionally crop) a source PDF region into a committed sidecar.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph
|
str
|
The source graph whose PDF the equation was transcribed from. |
required |
note_id
|
str
|
The equation note id; names the sidecar file. |
required |
page_index
|
int
|
Zero-based page index to render. |
required |
page_label
|
str
|
Human page label to store in the pointer (defaults to
|
''
|
rect
|
list[float] | tuple[float, float, float, float] | None
|
Optional |
None
|
scale
|
float
|
Render scale (≈ DPI / 72). |
_DEFAULT_SCALE
|
subdir
|
str
|
Sidecar subdirectory under |
SNAPSHOT_SUBDIR
|
Returns the pointer dict {path, content_hash, page, rect?} on success —
path is POSIX-relative to the graphs dir — or {"error": ...} on any
failure (missing PDF, bad page, renderer not installed).
Source code in zettelkasten/equation_snapshot.py
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 | |
resolve_snapshot_path ¶
Resolve a stored snapshot path (relative to the graphs dir) to a file.
Path-jailed via :func:safe_join; returns None when the file is absent
or the path escapes the graphs dir. Used by the dashboard image endpoint.