Utensil's Zettelkasten-style forest of evergreen notes on math and tech. utensil.tngl.sh/forest/
0

Configure Feed

Select the types of activity you want to include in your feed.

fix(render): iter 107 — write rewrite_dvi.py via printf (heredoc broke YAML)

iter 106 confirmed python failed on every shim invocation with
'IndentationError'. iter 107's first attempt used a quoted heredoc
('PYEOF') to write the python to a file, but the 0-indented python
lines exited the YAML block scalar and broke pipeline parsing
('could not find expected':'').

iter 107 (v2): use 'printf %s\n' with each python line as a
single-quoted argument. All lines stay within the YAML block scalar
(6-space leading); printf assembles them with newlines into
/tmp/bin/rewrite_dvi.py. Tested locally that the generated file
py_compiles cleanly.

The shim then invokes 'python3 /tmp/bin/rewrite_dvi.py $tmp' (file,
not -c). Same length-preserving LM->CM substitution.

[AGENT: kael]

+33 -30
+33 -30
.tangled/workflows/render.yml
··· 354 354 # inputs (first byte == 0xf7); PDF path (below) is unaffected. 355 355 first_byte=\$(od -An -N1 -tx1 "\$tmp" 2>/dev/null | tr -d ' \n') 356 356 if [ "\$first_byte" = "f7" ]; then 357 - # iter 106 — tag every shim invocation so I can prove python 358 - # actually ran. >> append, /tmp/iter106-shim.log gets stashed. 359 - echo "iter106-shim hit: first_byte=\$first_byte size=\$(wc -c < \$tmp)" >> /tmp/iter106-shim.log 2>/dev/null || true 360 - python3 -c ' 361 - import sys, os 362 - p = sys.argv[1] 363 - with open(p, "rb") as f: d = f.read() 364 - d2 = d.replace(b"pdf:pagesize", b"xyz:pagesize") 365 - # iter 105: narrow iter 102 LM-to-CM substitution to just the two 366 - # fonts the operator confirmed visually correct after iter 102. 367 - # iter 103/104 inexplicably failed render at the 2-5 minute mark 368 - # with the same logic; simplify (drop the f-string assertion, 369 - # use ASCII-only comments) to rule out parse issues. Lengths 370 - # are checked manually: lmromancaps10-regular = 21 bytes; 371 - # cmcsc10 + 14 NULs = 21 bytes. lmroman10-italic = 16 bytes; 372 - # cmti10 + 10 NULs = 16 bytes. 373 - cm_subs = [ 374 - (b"lmromancaps10-regular", b"cmcsc10\0\0\0\0\0\0\0\0\0\0\0\0\0\0"), 375 - (b"lmroman10-italic", b"cmti10\0\0\0\0\0\0\0\0\0\0"), 376 - ] 377 - hits = [] 378 - for lm, cm in cm_subs: 379 - if len(lm) == len(cm) and lm in d2: 380 - hits.append(lm.decode("ascii", "replace")) 381 - d2 = d2.replace(lm, cm) 382 - if d2 != d: 383 - with open(p, "wb") as f: f.write(d2) 384 - with open("/tmp/iter106-shim.log", "a") as logf: 385 - logf.write(f" py ran size_d={len(d)} size_d2={len(d2)} hits={hits}\n") 386 - ' "\$tmp" 2>>/tmp/iter106-shim.log || echo "py FAILED on \$tmp" >> /tmp/iter106-shim.log 357 + # iter 107 — call the rewrite script from a real file (vs heredoc- 358 + # embedded -c) so python's indentation parser can't choke on 359 + # heredoc-stripped whitespace (iter 106's IndentationError). 360 + echo "iter107-shim hit: first_byte=\$first_byte size=\$(wc -c < \$tmp)" >> /tmp/iter106-shim.log 2>/dev/null || true 361 + python3 /tmp/bin/rewrite_dvi.py "\$tmp" 2>>/tmp/iter106-shim.log || echo "py FAILED on \$tmp" >> /tmp/iter106-shim.log 387 362 fi 388 363 389 364 # iter 47 — for XDV/DVI inputs dvisvgm needs dvips .pro headers ··· 537 512 EOF 538 513 sed -i 's/^ //' /tmp/bin/dvisvgm 539 514 chmod +x /tmp/bin/dvisvgm 515 + 516 + # iter 107 — write the DVI-rewrite python to a real file via printf 517 + # so we don't get bash heredoc / YAML block-scalar interaction issues. 518 + # Single-line printf with %s args inside YAML, no heredoc. 519 + printf '%s\n' \ 520 + 'import sys' \ 521 + '' \ 522 + 'p = sys.argv[1]' \ 523 + 'with open(p, "rb") as f:' \ 524 + ' d = f.read()' \ 525 + 'd2 = d.replace(b"pdf:pagesize", b"xyz:pagesize")' \ 526 + 'subs = [' \ 527 + ' (b"lmromancaps10-regular", b"cmcsc10\0\0\0\0\0\0\0\0\0\0\0\0\0\0"),' \ 528 + ' (b"lmroman10-italic", b"cmti10\0\0\0\0\0\0\0\0\0\0"),' \ 529 + ']' \ 530 + 'hits = []' \ 531 + 'for lm, cm in subs:' \ 532 + ' if len(lm) == len(cm) and lm in d2:' \ 533 + ' hits.append(lm.decode("ascii", "replace"))' \ 534 + ' d2 = d2.replace(lm, cm)' \ 535 + 'if d2 != d:' \ 536 + ' with open(p, "wb") as f:' \ 537 + ' f.write(d2)' \ 538 + 'with open("/tmp/iter106-shim.log", "a") as logf:' \ 539 + ' logf.write(" py ran size_d={} size_d2={} hits={}\n".format(len(d), len(d2), hits))' \ 540 + > /tmp/bin/rewrite_dvi.py 541 + chmod +x /tmp/bin/rewrite_dvi.py 542 + echo " ✓ wrote /tmp/bin/rewrite_dvi.py ($(wc -l < /tmp/bin/rewrite_dvi.py) lines)" 540 543 541 544 # Sanity: shim takes precedence over any latex/dvisvgm that nixery might provide. 542 545 echo "latex resolves to: $(command -v latex)"