{"generator":"Jekyll","link":[{"@attributes":{"href":"https:\/\/mil.ad\/feed.xml","rel":"self","type":"application\/atom+xml"}},{"@attributes":{"href":"https:\/\/mil.ad\/","rel":"alternate","type":"text\/html"}}],"updated":"2026-11-23T11:48:13+01:00","id":"https:\/\/mil.ad\/feed.xml","title":"Milad Alizadeh","author":{"name":"Milad Alizadeh"},"entry":[{"title":"wl-pick: a live window picker for Sway","link":{"@attributes":{"href":"https:\/\/mil.ad\/blog\/2026\/wl-pick.html","rel":"alternate","type":"text\/html","title":"wl-pick: a live window picker for Sway"}},"published":"2026-09-21T00:00:00+02:00","updated":"2026-09-21T00:00:00+02:00","id":"https:\/\/mil.ad\/blog\/2026\/wl-pick","content":"<p>I\u2019ve had a keyboard-driven window switcher in my window manager for a long time. It started as <a href=\"\/blog\/2021\/dmenu-window-switcher.html\">a shell script<\/a> piping i3\u2019s window list into dmenu, and over the years I tweaked it slightly as I moved to Sway\/Wayland and <a href=\"https:\/\/davatorium.github.io\/rofi\/\">rofi<\/a>.<\/p>\n\n<p>That was enough until a new use case turned up: sharing a single window in a video call. Until recently Sway could only share a whole display, but sharing windows is now possile thanks to the <a href=\"https:\/\/github.com\/emersion\/xdg-desktop-portal-wlr\">xdg-desktop-portal-wlr<\/a> backend, which lets you nominate an external program for picking the window. Browsers reach it through <a href=\"https:\/\/webrtc.github.io\/samples\/src\/content\/getusermedia\/getdisplaymedia\/\">getDisplayMedia<\/a>, which is handy for testing without having to join a call.<\/p>\n\n<p>I could of course have used my dmenu-style script, but picking the right window out of a list of names is a bit of guesswork, and guessing in front of an audience is not fun. A visual chooser seemed like an obvious improvement.<\/p>\n\n<p>My first attempt was to make rofi show me screenshots of all windows and displays. I put together a script using <a href=\"https:\/\/sr.ht\/~emersion\/grim\/\">grim<\/a> to take the screenshots, which can capture any window or display, including the ones that aren\u2019t currently on screen. It worked, and it was decent, but it had two problems:<\/p>\n\n<ul>\n  <li>The previews weren\u2019t live. Each thumbnail is frozen at the moment you launch the picker.<\/li>\n  <li>Launching it wasn\u2019t instantaneous. Every preview meant capturing a full-resolution frame, encoding it, writing it to disk, then reading and scaling it again.<\/li>\n<\/ul>\n\n<h2 id=\"wl-pick\">wl-pick<\/h2>\n\n<p>So I built <a href=\"https:\/\/github.com\/mil-ad\/wl-pick\">wl-pick<\/a>. It\u2019s a small Rust program that shows a grid of <em>live<\/em> previews of every open window and display. Move around with the arrow keys or <code class=\"language-plaintext highlighter-rouge\">hjkl<\/code>, press Enter, and it prints the selected window or output to stdout.<\/p>\n\n<video src=\"wl-pick.mp4\" autoplay=\"\" loop=\"\" muted=\"\" playsinline=\"\" style=\"width: 100%;\" aria-label=\"wl-pick\"><\/video>\n\n<p>wl-pick just prints the selection, so what happens next is up to the caller. The common case is window switching:<\/p>\n\n<div class=\"language-sh highlighter-rouge\"><div class=\"highlight\"><pre class=\"highlight\"><code>swaymsg <span class=\"s2\">\"[con_id=<\/span><span class=\"si\">$(<\/span>wl-pick <span class=\"nt\">--no-outputs<\/span> | <span class=\"nb\">cut<\/span> <span class=\"nt\">-f2<\/span><span class=\"si\">)<\/span><span class=\"s2\">] focus\"<\/span>\n<\/code><\/pre><\/div><\/div>\n\n<p>It can also be used as the screencast chooser, where <code class=\"language-plaintext highlighter-rouge\">--format portal<\/code> prints what <code class=\"language-plaintext highlighter-rouge\">xdg-desktop-portal-wlr<\/code> expects:<\/p>\n\n<div class=\"language-ini highlighter-rouge\"><div class=\"highlight\"><pre class=\"highlight\"><code><span class=\"nn\">[screencast]<\/span><span class=\"w\">\n<\/span><span class=\"py\">chooser_type<\/span><span class=\"p\">=<\/span><span class=\"s\">simple<\/span>\n<span class=\"py\">chooser_cmd<\/span><span class=\"p\">=<\/span><span class=\"s\">wl-pick --format portal<\/span>\n<\/code><\/pre><\/div><\/div>\n\n<h2 id=\"how-it-works\">How it works<\/h2>\n\n<p>The live previews rely on capture protocols that only landed in Sway recently. Sway <a href=\"https:\/\/github.com\/swaywm\/sway\/releases\/tag\/1.11\">1.11<\/a> added the <code class=\"language-plaintext highlighter-rouge\">ext-image-copy-capture-v1<\/code> protocol for capturing outputs, and <a href=\"https:\/\/github.com\/swaywm\/sway\/releases\/tag\/1.12\">1.12<\/a> extended it to individual windows.<\/p>\n\n<p>The trick to making it fast is that wl-pick doesn\u2019t draw anything. Each window\u2019s capture buffer is handed straight back to the compositor as a subsurface, along with the rectangle it should be scaled into. So the same process that captured the window at full resolution is also the one that shrinks it to a thumbnail. wl-pick allocates the memory, passes the file descriptor around, and does the arithmetic; it never looks at a pixel.<\/p>\n\n<p>What\u2019s left is the capture itself, and that\u2019s mostly bandwidth rather than computation. Keeping the previews live afterwards is nearly free, because the compositor only sends a new frame when a window\u2019s content actually changes, so a screen full of idle terminals generates no new frames.<\/p>\n\n<h2 id=\"installation\">Installation<\/h2>\n\n<p>Install it with:<\/p>\n\n<div class=\"language-plaintext highlighter-rouge\"><div class=\"highlight\"><pre class=\"highlight\"><code>cargo install wl-pick\n<\/code><\/pre><\/div><\/div>","author":{"name":"Milad Alizadeh"},"summary":"I\u2019ve had a keyboard-driven window switcher in my window manager for a long time. It started as a shell script piping i3\u2019s window list into dmenu, and over the years I tweaked it slightly as I moved to Sway\/Wayland and rofi."},{"title":"Rendering markdown with LaTeX in the terminal","link":{"@attributes":{"href":"https:\/\/mil.ad\/blog\/2026\/latex-in-markdown.html","rel":"alternate","type":"text\/html","title":"Rendering markdown with LaTeX in the terminal"}},"published":"2026-06-28T00:00:00+02:00","updated":"2026-06-28T00:00:00+02:00","id":"https:\/\/mil.ad\/blog\/2026\/latex-in-markdown","content":"<p>Even when I\u2019m not using Claude Code, most of my chatting with LLMs happens in the terminal. I use my fork of mods, the (now sunsetted) LLM CLI client from <a href=\"https:\/\/charm.land\/\">Charm<\/a>, to which I\u2019ve added <a href=\"\/blog\/2026\/interactive-mods.html\">an interactive mode<\/a> and a handful of other niceties for the majority of my day-to-day LLM interactions.<\/p>\n\n<p>LLMs output markdown constantly, and Charm\u2019s tools have some of the best terminal markdown rendering around, powered by their <a href=\"https:\/\/github.com\/charmbracelet\/glamour\">glamour<\/a> library. Occasionally I reach for <a href=\"https:\/\/simonwillison.net\/\">Simon Willison<\/a>\u2019s <a href=\"https:\/\/github.com\/simonw\/llm\">llm<\/a> CLI tool instead, which doesn\u2019t do any markdown rendering. In those cases I can still pipe the output to Charm\u2019s standalone markdown renderer <a href=\"https:\/\/github.com\/charmbracelet\/glow\">glow<\/a>, which I have forked as well to add streaming support.<\/p>\n\n<p>But a lot of my chats involve maths, and that\u2019s something these CLIs do nothing about. In a terminal that means squinting at raw LaTeX like<\/p>\n\n<div class=\"language-plaintext highlighter-rouge\"><div class=\"highlight\"><pre class=\"highlight\"><code>$$x = \\frac{-b \\pm \\sqrt{b^2 - 4ac}}{2a}$$\n<\/code><\/pre><\/div><\/div>\n\n<p>and reconstructing the formula in my head.<\/p>\n\n<p>I wondered whether this could be done better. This week, while <a href=\"\/blog\/2026\/kitcat-2.0.html\">working on an unrelated project<\/a> that relied on some of the fancier graphics features in <a href=\"https:\/\/sw.kovidgoyal.net\/kitty\/\">kitty<\/a> and <a href=\"https:\/\/ghostty.org\/\">Ghostty<\/a> terminals, it occurred to me the same trick could work for LaTeX in mods or glow. After a bit of trial and error and a lot of help from Claude, I ended up with something pretty decent.<\/p>\n\n<p>You can see it in action here in mods:<\/p>\n\n<video src=\"latex-in-mods.mp4\" autoplay=\"\" loop=\"\" muted=\"\" playsinline=\"\" style=\"width: 100%;\" aria-label=\"mods rendering a LaTeX equation as an image\"><\/video>\n\n<p>or as a pure markdown renderer with glow:<\/p>\n\n<p><img src=\"latex-in-glow.png\" alt=\"glow rendering a LaTeX equation as an image\" \/><\/p>\n\n<h2 id=\"how-does-it-work\">How does it work?<\/h2>\n\n<p>The first piece is turning the LaTeX into an image. I played around with integrating KaTeX or MathJax directly into mods or glow, but ended up just relying on the <a href=\"https:\/\/latex.codecogs.com\/\">CodeCogs<\/a> endpoint, which renders a snippet of LaTeX to a PNG over a plain HTTP request. It\u2019s remote, so it won\u2019t work offline and you\u2019re handing your equations to someone else\u2019s server, but it kept this part to a single GET, and I can swap in a local renderer later if it bothers me enough.<\/p>\n\n<p>The next piece is getting that image displayed in the terminal in a way that survives the TUI being redrawn constantly. I\u2019ve already <a href=\"\/blog\/2026\/kitcat-2.0.html\">written about<\/a> how kitty\u2019s <a href=\"https:\/\/sw.kovidgoyal.net\/kitty\/graphics-protocol\/#unicode-placeholders\">Unicode placeholders<\/a> can be used to draw images in the terminal that behave like text: you transmit the image as an invisible \u201cvirtual placement\u201d, then display it by writing out a grid of placeholder cells that encode the row, column and image id. That is useful here because the TUI redraws on every keystroke, so an image painted at the cursor would be trampled on the very next frame, while one made of ordinary text cells flows with the text.<\/p>\n\n<p>The last piece is doing all this while the response is still streaming, not only once it has finished. A round-trip to CodeCogs could be slow, so each equation renders on a background goroutine: when a <code class=\"language-plaintext highlighter-rouge\">$$\u2026$$<\/code> block closes I fire off the request and leave its spot blank, and the image drops in a beat later once the PNG arrives. It\u2019s cached from then on.<\/p>\n\n<h2 id=\"limitations\">Limitations<\/h2>\n\n<p>There are two main limitations.<\/p>\n\n<p>The first is that this only works in kitty and Ghostty, since it leans on their Unicode placeholder support; in any other terminal the LaTeX stays as raw text.<\/p>\n\n<p>The second is that only block equations get this treatment. Inline maths (the <code class=\"language-plaintext highlighter-rouge\">$x$<\/code> scattered mid-sentence) turned out fiddly: a terminal line can\u2019t grow taller to fit a fraction, and shrinking everything to a single cell looked weird. Getting the baseline right was its own headache, since an inline image wants to sit on the text baseline rather than the bottom of the cell, and lining that up cleanly was harder than I expected. I had something almost good enough, so I might still enable it behind a flag at some point.<\/p>\n\n<h2 id=\"how-to-get-it\">How to get it<\/h2>\n\n<p>glow a simpler place to start. I originally forked it to add support for streaming. Install my fork from:<\/p>\n\n<div class=\"language-plaintext highlighter-rouge\"><div class=\"highlight\"><pre class=\"highlight\"><code>go install github.com\/mil-ad\/glow\/v2@with-streaming\n<\/code><\/pre><\/div><\/div>\n\n<p>And if you\u2019re using mods you can get my fork from:<\/p>\n\n<div class=\"language-plaintext highlighter-rouge\"><div class=\"highlight\"><pre class=\"highlight\"><code>go install github.com\/mil-ad\/mods\n<\/code><\/pre><\/div><\/div>\n\n<p>LaTeX rendering is on by default and can be toggled with the <code class=\"language-plaintext highlighter-rouge\">--render-latex false<\/code> flag.<\/p>","author":{"name":"Milad Alizadeh"},"summary":"Even when I\u2019m not using Claude Code, most of my chatting with LLMs happens in the terminal. I use my fork of mods, the (now sunsetted) LLM CLI client from Charm, to which I\u2019ve added an interactive mode and a handful of other niceties for the majority of my day-to-day LLM interactions."},{"title":"kitcat 2.0","link":{"@attributes":{"href":"https:\/\/mil.ad\/blog\/2026\/kitcat-2.0.html","rel":"alternate","type":"text\/html","title":"kitcat 2.0"}},"published":"2026-06-22T00:00:00+02:00","updated":"2026-06-22T00:00:00+02:00","id":"https:\/\/mil.ad\/blog\/2026\/kitcat-2.0","content":"<p>I released <a href=\"https:\/\/github.com\/mil-ad\/kitcat\">kitcat<\/a> a while back: a matplotlib backend that draws plots directly into your terminal instead of opening a GUI window. The original release was barely a hundred lines and dead simple, and I\u2019ve ended up reaching for it almost every day since.<\/p>\n\n<p>The 2.0 release addresses the two things people asked for most:<\/p>\n\n<ul>\n  <li><strong>Plots that behave inside tmux<\/strong><\/li>\n  <li><strong>Better default sizing<\/strong><\/li>\n<\/ul>\n\n<p>Both rely on features only <a href=\"https:\/\/sw.kovidgoyal.net\/kitty\/\">kitty<\/a> and <a href=\"https:\/\/ghostty.org\/\">Ghostty<\/a> support, and better sizing needs kitty specifically. Everywhere else gets the old behaviour.<\/p>\n\n<h2 id=\"plots-that-behave-inside-tmux\">Plots that behave inside tmux<\/h2>\n\n<p>Previous versions drew plots at the cursor. They scrolled fine on their own, but the moment something other than the terminal itself started shuffling text around, things fell apart. tmux, for example, redraws its panes constantly with no idea there\u2019s an image there \u2014 so the plot would sit at a fixed position while the text scrolled out from under it, fail to clip at a pane boundary, or linger after the pane was hidden.<\/p>\n\n<p>This release switches to <strong><a href=\"https:\/\/sw.kovidgoyal.net\/kitty\/graphics-protocol\/#unicode-placeholders\">Unicode placeholders<\/a><\/strong>, a newer feature of the kitty graphics protocol that AFAIK only kitty and Ghostty implement. What\u2019s different is that the image is no longer painted at a screen position. Instead we use a Unicode character as a placeholder to tell the terminal to display an image at that cell. The picture you see is really just text. And because it\u2019s text, anything that moves text, e.g. tmux, moves the image for free \u2014 it scrolls with the buffer, clips at pane edges, and reflows when you resize the window:<\/p>\n\n<video src=\"kitcat-2.0-tmux.mp4\" autoplay=\"\" loop=\"\" muted=\"\" playsinline=\"\" style=\"width: 100%;\" aria-label=\"kitcat plotting inside tmux: the figure scrolls and clips with the pane\"><\/video>\n\n<h2 id=\"better-default-sizing\">Better default sizing<\/h2>\n\n<p>The other complaint was size. Previous versions always rendered at matplotlib\u2019s default DPI, so on a HiDPI display the plot and its labels came out noticeably smaller than the surrounding terminal text. In 2.0 kitcat queries the display\u2019s real DPI \u2014 something only kitty reports \u2014 and applies a scaling factor so the figure matches. Ghostty and everything else don\u2019t expose a DPI, so we fall back to the old behaviour.<\/p>\n\n<h2 id=\"detecting-the-terminal-program\">Detecting the terminal program<\/h2>\n\n<p>Surprisingly, most of my time went into figuring out which terminal program was in use. You can\u2019t trust environment variables like <code class=\"language-plaintext highlighter-rouge\">$TERM<\/code> or <code class=\"language-plaintext highlighter-rouge\">$TERM_PROGRAM<\/code> for this: even when they start out correct, SSH or a multiplexer like tmux may overwrite them \u2014 and those are exactly the cases kitcat needs to work in.<\/p>\n\n<p>The most reliable way I found was to <em>ask the terminal directly<\/em> \u2014 send it a <a href=\"https:\/\/invisible-island.net\/xterm\/ctlseqs\/ctlseqs.html\">query escape sequence<\/a> and read its reply. kitcat\u2019s first choice is <strong>XTGETTCAP<\/strong>, which queries a terminfo capability in real time; asking for the terminal-name capability (<code class=\"language-plaintext highlighter-rouge\">TN<\/code>) gets the terminal\u2019s own answer with no environment variable in the loop:<\/p>\n\n<div class=\"language-bash highlighter-rouge\"><div class=\"highlight\"><pre class=\"highlight\"><code><span class=\"nb\">printf<\/span> <span class=\"s1\">'\\033P+q544e\\033\\\\'<\/span>\n<\/code><\/pre><\/div><\/div>\n\n<p>The reply comes back hex-encoded \u2014 on kitty it\u2019s <code class=\"language-plaintext highlighter-rouge\">787465726d2d6b69747479<\/code>, which is just <code class=\"language-plaintext highlighter-rouge\">xterm-kitty<\/code> spelled out in hex.<\/p>\n\n<p><strong>XTVERSION<\/strong> is the next option. It just asks the terminal to identify itself:<\/p>\n\n<div class=\"language-bash highlighter-rouge\"><div class=\"highlight\"><pre class=\"highlight\"><code><span class=\"nb\">printf<\/span> <span class=\"s1\">'\\033[&gt;0q'<\/span>\n<\/code><\/pre><\/div><\/div>\n\n<p>Not every terminal answers these \u2014 they vary wildly in what they support and how they identify themselves (there\u2019s a <a href=\"https:\/\/ucs-detect.readthedocs.io\/results.html#terminal-capabilities\">running survey of terminal capabilities<\/a> that shows just how uneven it gets) \u2014 so environment variables stay as a last resort. In practice we mostly care about detecting kitty and Ghostty, which both support replying to these queries.<\/p>\n\n<h2 id=\"update\">Update<\/h2>\n\n<div class=\"language-plaintext highlighter-rouge\"><div class=\"highlight\"><pre class=\"highlight\"><code>pip install --upgrade kitcat\n<\/code><\/pre><\/div><\/div>","author":{"name":"Milad Alizadeh"},"category":[{"@attributes":{"term":"python"}},{"@attributes":{"term":"matplotlib"}}],"summary":"I released kitcat a while back: a matplotlib backend that draws plots directly into your terminal instead of opening a GUI window. The original release was barely a hundred lines and dead simple, and I\u2019ve ended up reaching for it almost every day since."},{"title":"Finding cited references faster in Sioyek","link":{"@attributes":{"href":"https:\/\/mil.ad\/blog\/2026\/find-references-sioyek.html","rel":"alternate","type":"text\/html","title":"Finding cited references faster in Sioyek"}},"published":"2026-06-09T00:00:00+02:00","updated":"2026-06-09T00:00:00+02:00","id":"https:\/\/mil.ad\/blog\/2026\/find-references-sioyek","content":"<p>One thing I do constantly as I read an academic paper is click citation links to see the work being referenced. The page jumps to the bibliography section \u2014 but with 10\u201320 entries crammed together on the page, it\u2019s difficult to spot the specific entry you landed on.<\/p>\n\n<p>It\u2019s a minor annoyance, but I now maintain <a href=\"\/blog\/2025\/supernote-in-sioyek.html\">a micro fork<\/a> of my PDF reader <a href=\"https:\/\/sioyek.info\/\">Sioyek<\/a> so I\u2019m more inclined to improve workflows like this.<\/p>\n\n<p>My solution: briefly highlight the destination when navigating to it \u2014 similar to <a href=\"https:\/\/pawelgrzybek.com\/highlight-yanked-text-in-neovim\/\">Neovim\u2019s highlight-on-yank feature<\/a> \u2014 then fade it out. The quick flash gives you an immediate visual anchor before it vanishes:<\/p>\n\n<video src=\".\/nvim-highlight-on-yank.mp4\" autoplay=\"\" loop=\"\" muted=\"\" playsinline=\"\" style=\"width: 100%;\"><\/video>\n\n<p>I put together <a href=\"https:\/\/github.com\/mil-ad\/sioyek\/pull\/2\">a hacky implementation<\/a> and Sioyek\u2019s developer was receptive to the idea. After <a href=\"https:\/\/github.com\/ahrm\/sioyek\/issues\/1622\">some back and forth<\/a>, the feature has now landed in the <code class=\"language-plaintext highlighter-rouge\">development<\/code> branch of Sioyek, exposing a few new config options:<\/p>\n\n<div class=\"language-plaintext highlighter-rouge\"><div class=\"highlight\"><pre class=\"highlight\"><code>highlight_link_destination 1\nlink_destination_highlight_timeout 0.75\nlink_destination_highlight_color #ffff00\n<\/code><\/pre><\/div><\/div>\n\n<p>and the result is:<\/p>\n\n<video src=\".\/sioyek-highlight-link-dest.mp4\" controls=\"\" muted=\"\" playsinline=\"\" style=\"width: 100%;\"><\/video>","author":{"name":"Milad Alizadeh"},"summary":"One thing I do constantly as I read an academic paper is click citation links to see the work being referenced. The page jumps to the bibliography section \u2014 but with 10\u201320 entries crammed together on the page, it\u2019s difficult to spot the specific entry you landed on."},{"title":"Auto Expand Linked References in Roam Research","link":{"@attributes":{"href":"https:\/\/mil.ad\/blog\/2026\/auto-expand-references-in-roam.html","rel":"alternate","type":"text\/html","title":"Auto Expand Linked References in Roam Research"}},"published":"2026-05-08T00:00:00+02:00","updated":"2026-05-08T00:00:00+02:00","id":"https:\/\/mil.ad\/blog\/2026\/auto-expand-references-in-roam","content":"<p>I have been using <a href=\"https:\/\/roamresearch.com\/\">Roam Research<\/a> for taking notes for years. One of the crucial features I like in Roam is linked references, also known as \u201cbacklinks\u201d: you create links to new or existing pages as you write by wrapping the page name in <code class=\"language-plaintext highlighter-rouge\">[[ ]]<\/code>, and along with creating the forward link, you get references <em>back<\/em> to your writing on each of those pages. This frees your mind from the \u201cWhere should I file this note?\u201d question \u2014 it doesn\u2019t really matter where you\u2019re taking the note. As long as you link relevant pages, your writing appears in <em>all<\/em> those places.<\/p>\n\n<p>For the illusion to work, I don\u2019t want to just have \u201clinks\u201d to the original writing \u2014 I want the references to <em>form<\/em> the content of a page by extending the native page content. And that\u2019s more or less how Roam does it.<\/p>\n\n<p>Roam isn\u2019t perfect though. While it does embed the linked references, it sometimes collapses them. In general, the collapse\/expand state of each bullet is something Roam tracks \u2014 it remembers when you collapse or expand a block, and the state syncs across sessions and devices. That works fine for normal blocks, but I can\u2019t, for the life of me, figure out how Roam decides to expand or collapse a linked reference. I often find that reference sections are collapsed without me explicitly doing it. I can, of course, expand them manually, but for me this breaks the whole illusion that the linked references are in fact part of the page.<\/p>\n\n<p>In the absence of predictable collapsing behaviour, I prefer to force linked references to always be expanded. Unfortunately, this is not an option in Roam\u2019s settings. The <a href=\"https:\/\/github.com\/RoamJs\/workbench\/blob\/main\/docs\/command-palette-plus.md\">Command Palette Plus feature<\/a> of the <a href=\"https:\/\/github.com\/RoamJS\/workbench\">Workbench plugin<\/a> does provide an \u201cExpand Reference Children\u201d command that makes it easier, but it still needs a manual step.<\/p>\n\n<p>Fortunately, Roam supports user-provided JavaScript, so I found a way to automate it:<\/p>\n\n<ol>\n  <li>Create a page in Roam (if not already present) called <code class=\"language-plaintext highlighter-rouge\">[[roam\/js]]<\/code><\/li>\n  <li>Create a new block on this page and enter: <code class=\"language-plaintext highlighter-rouge\">{{[[roam\/js]]}}<\/code><\/li>\n  <li>\n    <p>Nest a JavaScript code block under it with this content:<\/p>\n\n    <div class=\"language-js highlighter-rouge\"><div class=\"highlight\"><pre class=\"highlight\"><code><span class=\"p\">(()<\/span> <span class=\"o\">=&gt;<\/span> <span class=\"p\">{<\/span>\n  <span class=\"kd\">const<\/span> <span class=\"nx\">expandRefs<\/span> <span class=\"o\">=<\/span> <span class=\"p\">()<\/span> <span class=\"o\">=&gt;<\/span> <span class=\"p\">{<\/span>\n    <span class=\"nb\">document<\/span><span class=\"p\">.<\/span><span class=\"nf\">querySelectorAll<\/span><span class=\"p\">(<\/span><span class=\"dl\">\"<\/span><span class=\"s2\">.rm-reference-item .block-expand<\/span><span class=\"dl\">\"<\/span><span class=\"p\">).<\/span><span class=\"nf\">forEach<\/span><span class=\"p\">((<\/span><span class=\"nx\">btn<\/span><span class=\"p\">)<\/span> <span class=\"o\">=&gt;<\/span> <span class=\"p\">{<\/span>\n      <span class=\"nx\">btn<\/span><span class=\"p\">.<\/span><span class=\"nf\">dispatchEvent<\/span><span class=\"p\">(<\/span><span class=\"k\">new<\/span> <span class=\"nc\">MouseEvent<\/span><span class=\"p\">(<\/span><span class=\"dl\">\"<\/span><span class=\"s2\">contextmenu<\/span><span class=\"dl\">\"<\/span><span class=\"p\">,<\/span> <span class=\"p\">{<\/span> <span class=\"na\">bubbles<\/span><span class=\"p\">:<\/span> <span class=\"kc\">true<\/span><span class=\"p\">,<\/span> <span class=\"na\">button<\/span><span class=\"p\">:<\/span> <span class=\"mi\">2<\/span> <span class=\"p\">}));<\/span>\n      <span class=\"kd\">const<\/span> <span class=\"nx\">menu<\/span> <span class=\"o\">=<\/span> <span class=\"nb\">document<\/span><span class=\"p\">.<\/span><span class=\"nf\">querySelector<\/span><span class=\"p\">(<\/span>\n        <span class=\"dl\">'<\/span><span class=\"s1\">.bp3-transition-container:not([style*=\"display: none;\"]) .bp3-popover-content &gt; div &gt; ul<\/span><span class=\"dl\">'<\/span>\n      <span class=\"p\">);<\/span>\n      <span class=\"nb\">Array<\/span><span class=\"p\">.<\/span><span class=\"k\">from<\/span><span class=\"p\">(<\/span><span class=\"nx\">menu<\/span><span class=\"p\">?.<\/span><span class=\"nx\">children<\/span> <span class=\"o\">||<\/span> <span class=\"p\">[])<\/span>\n        <span class=\"p\">.<\/span><span class=\"nf\">find<\/span><span class=\"p\">((<\/span><span class=\"nx\">e<\/span><span class=\"p\">)<\/span> <span class=\"o\">=&gt;<\/span> <span class=\"nx\">e<\/span><span class=\"p\">.<\/span><span class=\"nx\">innerText<\/span> <span class=\"o\">===<\/span> <span class=\"dl\">\"<\/span><span class=\"s2\">Expand all<\/span><span class=\"dl\">\"<\/span><span class=\"p\">)<\/span>\n        <span class=\"p\">?.<\/span><span class=\"nx\">childNodes<\/span><span class=\"p\">[<\/span><span class=\"mi\">0<\/span><span class=\"p\">]?.<\/span><span class=\"nf\">click<\/span><span class=\"p\">();<\/span>\n    <span class=\"p\">});<\/span>\n  <span class=\"p\">};<\/span>\n     \n  <span class=\"kd\">const<\/span> <span class=\"nx\">run<\/span> <span class=\"o\">=<\/span> <span class=\"p\">()<\/span> <span class=\"o\">=&gt;<\/span> <span class=\"nf\">setTimeout<\/span><span class=\"p\">(<\/span><span class=\"nx\">expandRefs<\/span><span class=\"p\">,<\/span> <span class=\"mi\">800<\/span><span class=\"p\">);<\/span>\n     \n  <span class=\"nf\">run<\/span><span class=\"p\">();<\/span>\n  <span class=\"nb\">window<\/span><span class=\"p\">.<\/span><span class=\"nf\">addEventListener<\/span><span class=\"p\">(<\/span><span class=\"dl\">\"<\/span><span class=\"s2\">hashchange<\/span><span class=\"dl\">\"<\/span><span class=\"p\">,<\/span> <span class=\"nx\">run<\/span><span class=\"p\">);<\/span>\n<span class=\"p\">})();<\/span>\n<\/code><\/pre><\/div>    <\/div>\n  <\/li>\n<\/ol>\n\n<p>The script runs on page load and on every URL hash change (Roam\u2019s navigation mechanism). After an 800ms delay to let Roam finish rendering, it queries all reference item expand buttons and, for each one, simulates a right-click to trigger Roam\u2019s popover menu before programmatically clicking the \u201cExpand all\u201d item. It\u2019s a bit hacky, but it\u2019s been working well for me in Roam v0.13.7.<\/p>","author":{"name":"Milad Alizadeh"},"summary":"I have been using Roam Research for taking notes for years. One of the crucial features I like in Roam is linked references, also known as \u201cbacklinks\u201d: you create links to new or existing pages as you write by wrapping the page name in [[ ]], and along with creating the forward link, you get references back to your writing on each of those pages. This frees your mind from the \u201cWhere should I file this note?\u201d question \u2014 it doesn\u2019t really matter where you\u2019re taking the note. As long as you link relevant pages, your writing appears in all those places."},{"title":"Forking mods to add interactive mode","link":{"@attributes":{"href":"https:\/\/mil.ad\/blog\/2026\/interactive-mods.html","rel":"alternate","type":"text\/html","title":"Forking mods to add interactive mode"}},"published":"2026-04-04T00:00:00+02:00","updated":"2026-04-04T00:00:00+02:00","id":"https:\/\/mil.ad\/blog\/2026\/interactive-mods","content":"<p>Last year I <a href=\"https:\/\/mil.ad\/blog\/2025\/llmmenu.html\">wrote<\/a> about my simple set up for running <a href=\"https:\/\/github.com\/charmbracelet\/mods\">mods CLI<\/a> in a loop and turning it into a little windowed program I can invoke quickly for interacting with LLMs. I vastly prefer this to going to a website to interact with LLM chatbots. Having it instantly available with a simple keybinding (<code class=\"language-plaintext highlighter-rouge\">Super+g<\/code> in my case) makes all the difference \u2014 I use it all day, every day.<\/p>\n\n<p>I\u2019ve applied a few tweaks to it since then to add some clipboard integration \u2014 the final version of the script is <a href=\"https:\/\/github.com\/mil-ad\/dotfiles\/blob\/ff7434f4becc130d31e3fcedf76a7aaea42888e9\/linux\/.local\/bin\/mods_in_loop\">in my dotfiles<\/a>:<\/p>\n\n<video src=\"mods-in-loop.mp4\" controls=\"\" muted=\"\" playsinline=\"\" style=\"width: 100%;\"><\/video>\n\n<p>But over time I started wanting features that a bash wrapper couldn\u2019t provide:<\/p>\n\n<ul>\n  <li><strong>Dynamic width adjustment.<\/strong> I frequently resize the window, toggle between full-screen and floating, while the LLM is generating output. Vanilla mods didn\u2019t handle this \u2014 changing the terminal width mid-stream, or even at the end, would garble the output. I wanted it to detect size changes and re-render to fit the available width.<\/li>\n  <li><strong>Proper copy\/paste.<\/strong> The script already copied prompts to clipboard (handy for reusing them in other LLMs), but I also needed to copy from the output. I was doing this by mouse-highlighting, which introduced whitespace and line break artefacts. I wanted a native way to send individual prompts or completions to the clipboard cleanly.<\/li>\n  <li><strong>Conversation switching.<\/strong> I wanted to browse a list of recent conversations and jump into any of them to continue the chat.<\/li>\n  <li><strong>Voice input.<\/strong> I wanted ASR integration, similar to Claude Code\u2019s <code class=\"language-plaintext highlighter-rouge\">\/voice<\/code> command.<\/li>\n<\/ul>\n\n<h2 id=\"forking-mods\">Forking mods<\/h2>\n\n<p>I could use Claude Code or OpenCode or similar tools in the terminal and get all these features \u2014 and I do, for actual agentic coding. But I still reach for this simple mods integration dozens of times a day. It\u2019s super fast, minimal, and has basically replaced search engines for me to a large extent.<\/p>\n\n<p>Mods itself has been sunset by <a href=\"https:\/\/charm.land\/\">Charm<\/a> in favour of <a href=\"https:\/\/github.com\/charmbracelet\/crush\">Crush<\/a>, their new agentic coding tool. But mods isn\u2019t exactly a complicated program, and I think I can maintain a fork with relatively little effort. I\u2019ve been slowly working on <a href=\"https:\/\/github.com\/mil-ad\/mods\">my own fork<\/a> and it\u2019s now in a usable state.<\/p>\n\n<p>The main addition is an interactive mode (enabled with <code class=\"language-plaintext highlighter-rouge\">-i\/--interactive<\/code>) that turns mods into a proper chat interface. It supports:<\/p>\n\n<ul>\n  <li>\ud83d\udd04 <strong>Continuous conversations<\/strong> without needing the bash loop wrapper \u2014 mods handles the prompt input and conversation flow itself. It also handles window size changes dynamically.<\/li>\n  <li>\ud83d\udccb <strong>Selection mode.<\/strong> Pressing <code class=\"language-plaintext highlighter-rouge\">Esc<\/code> enters a selection mode where you can navigate between prompts and completions with <code class=\"language-plaintext highlighter-rouge\">j<\/code>\/<code class=\"language-plaintext highlighter-rouge\">k<\/code>. Pressing <code class=\"language-plaintext highlighter-rouge\">y<\/code> copies the selected block to the clipboard, with a brief highlight flash to confirm the copy \u2014 similar to neovim\u2019s <code class=\"language-plaintext highlighter-rouge\">vim.highlight.on_yank()<\/code> feature.<\/li>\n  <li>\ud83d\uddc3\ufe0f <strong>Conversation history.<\/strong> <code class=\"language-plaintext highlighter-rouge\">Ctrl-R<\/code> opens a history view where you can browse recent conversations and switch to a different one.<\/li>\n  <li>\ud83c\udf99\ufe0f <strong>Voice input.<\/strong> Pressing and holding <code class=\"language-plaintext highlighter-rouge\">]<\/code> activates speech-to-text. This requires setting <code class=\"language-plaintext highlighter-rouge\">transcription-api-base-url<\/code> in the mods config and works with any OpenAI-compatible ASR API. I\u2019m self-hosting a <a href=\"https:\/\/github.com\/mil-ad\/parakeet-tdt-0.6b-v3-fastapi-openai\">CPU-optimised variant<\/a> of NVIDIA\u2019s excellent parakeet-tdt-0.6b-v3 model \u2014 I\u2019m impressed by how well the INT8 quantisation works for this.<\/li>\n<\/ul>\n\n<video src=\"mods-interactive.mp4\" controls=\"\" muted=\"\" style=\"width: 100%;\"><\/video>\n\n<p>If you\u2019d like to try it:<\/p>\n\n<div class=\"language-plaintext highlighter-rouge\"><div class=\"highlight\"><pre class=\"highlight\"><code>go install github.com\/mil-ad\/mods@latest\n<\/code><\/pre><\/div><\/div>","author":{"name":"Milad Alizadeh"},"summary":"Last year I wrote about my simple set up for running mods CLI in a loop and turning it into a little windowed program I can invoke quickly for interacting with LLMs. I vastly prefer this to going to a website to interact with LLM chatbots. Having it instantly available with a simple keybinding (Super+g in my case) makes all the difference \u2014 I use it all day, every day."},{"title":"Slide navigator in Marp \u2014 now official","link":{"@attributes":{"href":"https:\/\/mil.ad\/blog\/2026\/marp-slide-navigator-merged.html","rel":"alternate","type":"text\/html","title":"Slide navigator in Marp \u2014 now official"}},"published":"2026-03-27T00:00:00+01:00","updated":"2026-03-27T00:00:00+01:00","id":"https:\/\/mil.ad\/blog\/2026\/marp-slide-navigator-merged","content":"<p>I <a href=\"https:\/\/mil.ad\/blog\/2025\/marp-slide-navigator.html\">wrote previously<\/a> about vibe-coding a slide navigator into <a href=\"https:\/\/github.com\/marp-team\/marp-cli\">marp-cli<\/a> \u2014 a thumbnail overview for the <a href=\"https:\/\/github.com\/marp-team\/marp-cli?tab=readme-ov-file#bespoke-template-default\">default template<\/a> that lets you jump to any slide without cycling through them one by one. My initial version worked, but it was hacky and slow.<\/p>\n\n<p>I tried to turn it into a proper PR, and Marp\u2019s developer <a href=\"https:\/\/github.com\/yhatt\">Yuki Hattori<\/a> was kind enough to point me in the right direction. I reworked the implementation, and it has now landed in the <a href=\"https:\/\/github.com\/marp-team\/marp-cli\/releases\/tag\/v4.3.0\">v4.3.0 release<\/a> of marp-cli. The result is a lot simpler, much faster, and works in both the presenter view and the normal view:<\/p>\n\n<video src=\".\/marp_slide_navigator.mp4\" controls=\"\" muted=\"\" playsinline=\"\" style=\"width: 100%;\"><\/video>\n\n<p>If you\u2019re already using marp-cli, just update to v4.3.0 or later and you\u2019ll have it out of the box.<\/p>","author":{"name":"Milad Alizadeh"},"category":{"@attributes":{"term":"marp"}},"summary":"I wrote previously about vibe-coding a slide navigator into marp-cli \u2014 a thumbnail overview for the default template that lets you jump to any slide without cycling through them one by one. My initial version worked, but it was hacky and slow."},{"title":"How to toggle Waybar module visibility at runtime","link":{"@attributes":{"href":"https:\/\/mil.ad\/blog\/2026\/toggle-waybar-module-visibility.html","rel":"alternate","type":"text\/html","title":"How to toggle Waybar module visibility at runtime"}},"published":"2026-03-13T00:00:00+01:00","updated":"2026-03-13T00:00:00+01:00","id":"https:\/\/mil.ad\/blog\/2026\/toggle-waybar-module-visibility","content":"<p>On X11 I was using <a href=\"https:\/\/polybar.github.io\/\">Polybar<\/a> for my status bar and modules. One thing I liked about it was how easy it was to have modules that only appear when relevant. There are certain bar modules that I don\u2019t need visible at all times \u2014 for example, I have a script that lets me quickly record a section of my screen. I don\u2019t use this often enough to justify a permanent module for it. I can easily invoke the recording <a href=\"https:\/\/github.com\/mil-ad\/dotfiles\/blob\/main\/linux\/.local\/bin\/sysmenu\">in other ways<\/a>, but once it starts it would be useful to have a module that displays a \u201c\ud83d\udd34 REC\u201d indicator and lets me stop the recording with a click.<\/p>\n\n<p>Polybar modules have a <code class=\"language-plaintext highlighter-rouge\">hidden<\/code> parameter and a mechanism for changing module visibility at runtime:<\/p>\n\n<div class=\"language-plaintext highlighter-rouge\"><div class=\"highlight\"><pre class=\"highlight\"><code>polybar-msg action screen-capture module_show\n<\/code><\/pre><\/div><\/div>\n\n<p>where <code class=\"language-plaintext highlighter-rouge\">screen-capture<\/code> is a simple custom Polybar module:<\/p>\n\n<div class=\"language-ini highlighter-rouge\"><div class=\"highlight\"><pre class=\"highlight\"><code><span class=\"nn\">[module\/screen-capture]<\/span><span class=\"w\">\n<\/span><span class=\"py\">type<\/span><span class=\"w\"> <\/span><span class=\"p\">=<\/span><span class=\"w\"> <\/span><span class=\"s\">custom\/text<\/span>\n<span class=\"py\">format<\/span><span class=\"w\"> <\/span><span class=\"p\">=<\/span><span class=\"w\"> <\/span><span class=\"s\">&lt;label&gt;<\/span>\n<span class=\"py\">label<\/span><span class=\"w\"> <\/span><span class=\"p\">=<\/span><span class=\"w\"> <\/span><span class=\"s\">\ud83d\udd34<\/span>\n<span class=\"py\">hidden<\/span><span class=\"w\"> <\/span><span class=\"p\">=<\/span><span class=\"w\"> <\/span><span class=\"s\">true<\/span>\n<span class=\"py\">click-left<\/span><span class=\"w\"> <\/span><span class=\"p\">=<\/span><span class=\"w\"> <\/span><span class=\"s\">~\/.local\/bin\/record-screen-area-stop<\/span>\n<\/code><\/pre><\/div><\/div>\n\n<p>When I migrated to Wayland I started using <a href=\"https:\/\/github.com\/Alexays\/Waybar\">Waybar<\/a> as a Polybar replacement. I generally find it more feature-rich than Polybar, but it <a href=\"https:\/\/github.com\/Alexays\/Waybar\/issues\/564\">doesn\u2019t have<\/a> an explicit mechanism for toggling module visibility at runtime.<\/p>\n\n<p>What it does have, however, is support for signals. Each module can be assigned a signal number (<code class=\"language-plaintext highlighter-rouge\">SIGRTMIN+n<\/code>) and when Waybar receives that signal, it triggers the module to refresh. This means you can poke a specific module from the outside rather than relying on polling.<\/p>\n\n<p>With a little bit of hacking, this mechanism can be used to hide and show a module on demand. The trick is to back the module with a file: when the file exists and has content, the module displays it; when the file is empty or missing, the module produces no output and Waybar hides it. Each time the file changes, you send the signal to tell Waybar to re-read it. Instead of separate start\/stop scripts for my screen recording, I now have one script that handles everything:<\/p>\n\n<div class=\"language-bash highlighter-rouge\"><div class=\"highlight\"><pre class=\"highlight\"><code><span class=\"c\">#!\/usr\/bin\/env bash<\/span>\n\n<span class=\"nv\">geometry<\/span><span class=\"o\">=<\/span><span class=\"s2\">\"<\/span><span class=\"si\">$(<\/span>slurp<span class=\"si\">)<\/span><span class=\"s2\">\"<\/span> <span class=\"o\">||<\/span> <span class=\"nb\">exit <\/span>0\n\n<span class=\"nb\">echo<\/span> <span class=\"s1\">'{\"text\": \"\ud83d\udd34 REC\", \"class\": \"recording\", \"tooltip\": \"Click to stop\"}'<\/span> <span class=\"o\">&gt;<\/span> \/tmp\/waybar-recording\npkill <span class=\"nt\">-SIGRTMIN<\/span>+9 waybar   <span class=\"c\"># wake the module<\/span>\n\n<span class=\"nv\">filename<\/span><span class=\"o\">=<\/span><span class=\"s2\">\"screen-area-capture-<\/span><span class=\"si\">$(<\/span><span class=\"nb\">date<\/span> <span class=\"s1\">'+%Y-%m-%d-%H:%M:%S'<\/span><span class=\"si\">)<\/span><span class=\"s2\">.mp4\"<\/span>\nwf-recorder <span class=\"nt\">-g<\/span> <span class=\"s2\">\"<\/span><span class=\"nv\">$geometry<\/span><span class=\"s2\">\"<\/span> <span class=\"nt\">--file<\/span> ~\/Downloads\/<span class=\"s2\">\"<\/span><span class=\"nv\">$filename<\/span><span class=\"s2\">\"<\/span>\n\n<span class=\"c\"># Recording stopped (by on-click sending SIGINT to wf-recorder)<\/span>\n<span class=\"nb\">rm<\/span> \/tmp\/waybar-recording\npkill <span class=\"nt\">-SIGRTMIN<\/span>+9 waybar   <span class=\"c\"># wake again \u2192 empty output \u2192 module hides<\/span>\n\nnotify-send <span class=\"s2\">\"Saved to: <\/span><span class=\"nv\">$filename<\/span><span class=\"s2\">\"<\/span>\n<\/code><\/pre><\/div><\/div>\n\n<p>And the corresponding Waybar module:<\/p>\n\n<div class=\"language-json highlighter-rouge\"><div class=\"highlight\"><pre class=\"highlight\"><code><span class=\"nl\">\"custom\/screen-recording\"<\/span><span class=\"p\">:<\/span><span class=\"w\"> <\/span><span class=\"p\">{<\/span><span class=\"w\">\n    <\/span><span class=\"nl\">\"exec\"<\/span><span class=\"p\">:<\/span><span class=\"w\"> <\/span><span class=\"s2\">\"cat \/tmp\/waybar-recording 2&gt;\/dev\/null\"<\/span><span class=\"p\">,<\/span><span class=\"w\">\n    <\/span><span class=\"nl\">\"signal\"<\/span><span class=\"p\">:<\/span><span class=\"w\"> <\/span><span class=\"mi\">9<\/span><span class=\"p\">,<\/span><span class=\"w\">\n    <\/span><span class=\"nl\">\"return-type\"<\/span><span class=\"p\">:<\/span><span class=\"w\"> <\/span><span class=\"s2\">\"json\"<\/span><span class=\"p\">,<\/span><span class=\"w\">\n    <\/span><span class=\"nl\">\"on-click\"<\/span><span class=\"p\">:<\/span><span class=\"w\"> <\/span><span class=\"s2\">\"pkill -INT wf-recorder\"<\/span><span class=\"p\">,<\/span><span class=\"w\">\n    <\/span><span class=\"nl\">\"format\"<\/span><span class=\"p\">:<\/span><span class=\"w\"> <\/span><span class=\"s2\">\"{}\"<\/span><span class=\"w\">\n<\/span><span class=\"p\">}<\/span><span class=\"err\">,<\/span><span class=\"w\">\n<\/span><\/code><\/pre><\/div><\/div>\n\n<p>The same pattern works for any module you want to show conditionally \u2014 write to a file when the module should be visible, remove it when it shouldn\u2019t, and signal Waybar each time.<\/p>","author":{"name":"Milad Alizadeh"},"summary":"On X11 I was using Polybar for my status bar and modules. One thing I liked about it was how easy it was to have modules that only appear when relevant. There are certain bar modules that I don\u2019t need visible at all times \u2014 for example, I have a script that lets me quickly record a section of my screen. I don\u2019t use this often enough to justify a permanent module for it. I can easily invoke the recording in other ways, but once it starts it would be useful to have a module that displays a \u201c\ud83d\udd34 REC\u201d indicator and lets me stop the recording with a click."},{"title":"Popping and Locking theme for Zed","link":{"@attributes":{"href":"https:\/\/mil.ad\/blog\/2026\/zed-popping-and-locking.html","rel":"alternate","type":"text\/html","title":"Popping and Locking theme for Zed"}},"published":"2026-01-31T00:00:00+01:00","updated":"2026-01-31T00:00:00+01:00","id":"https:\/\/mil.ad\/blog\/2026\/zed-popping-and-locking","content":"<p>I\u2019m a big fan of Hedinn Eiriksson\u2019s <a href=\"https:\/\/github.com\/hedinne\/popping-and-locking-vscode\">Popping and Locking theme<\/a> for VS Code \u2014 it\u2019s the theme I use here on my website and in many other places.<\/p>\n\n<p>I\u2019ve moved away from VS Code\/Cursor to <a href=\"https:\/\/zed.dev\">Zed<\/a> in the last couple of months and have been missing the theme. There is <a href=\"https:\/\/github.com\/randoneering\/popping-and-locking-zed-theme\">an existing port<\/a> to Zed but I haven\u2019t been happy with it, so I ended up doing my own:<\/p>\n\n<p><img src=\"rust.png\" alt=\"Rust\" \/><\/p>\n\n<p><img src=\"go.png\" alt=\"Go\" \/><\/p>\n\n<p><img src=\"css.png\" alt=\"CSS\" \/><\/p>\n\n<p>I\u2019m <a href=\"https:\/\/github.com\/zed-industries\/extensions\/pull\/4513\">in the process<\/a> of getting this merged into official Zed extensions, but in the meantime you can save it into <code class=\"language-plaintext highlighter-rouge\">~\/.config\/zed\/themes<\/code>:<\/p>\n\n<div class=\"language-plaintext highlighter-rouge\"><div class=\"highlight\"><pre class=\"highlight\"><code>curl -s https:\/\/raw.githubusercontent.com\/mil-ad\/zed-popping-and-locking\/main\/themes\/popping-and-locking.json &gt; ~\/.config\/zed\/themes\/popping-and-locking.json\n<\/code><\/pre><\/div><\/div>","author":{"name":"Milad Alizadeh"},"summary":"I\u2019m a big fan of Hedinn Eiriksson\u2019s Popping and Locking theme for VS Code \u2014 it\u2019s the theme I use here on my website and in many other places."},{"title":"Adding Supernote PDF Annotation Support to Sioyek","link":{"@attributes":{"href":"https:\/\/mil.ad\/blog\/2025\/supernote-in-sioyek.html","rel":"alternate","type":"text\/html","title":"Adding Supernote PDF Annotation Support to Sioyek"}},"published":"2025-12-26T00:00:00+01:00","updated":"2025-12-26T00:00:00+01:00","id":"https:\/\/mil.ad\/blog\/2025\/supernote-in-sioyek","content":"<p>One of the <a href=\"https:\/\/en.wikipedia.org\/wiki\/The_Free_Software_Definition#The_Four_Essential_Freedoms_of_Free_Software\">core FOSS principles<\/a> is the freedom to study how software works and adapt it to your needs. In practice, though, diving into a large, unfamiliar codebase in a domain you\u2019re not an expert in, using a programming language you\u2019re not necessarily proficient with, is hard.<\/p>\n\n<p>AI agents make this <em>much<\/em> easier. They help you understand how a project is structured, point you to the right places in the code, and apply fixes or new features whilst following the project\u2019s existing patterns and style.<\/p>\n\n<p>At work, I\u2019m reluctant to let AI agents loose because it feels like inheriting legacy code. For personal projects, I don\u2019t care. Without AI, many features and fixes I want would simply never happen.<\/p>\n\n<p>I now maintain a handful of mini-forks of programmes I care about, with tweaks that suit how I actually use them. I\u2019ve <a href=\"https:\/\/mil.ad\/blog\/2025\/marp-slide-navigator.html\">written<\/a> about one feature I added to <a href=\"https:\/\/marp.app\/\">Marp<\/a>. I also use a tweaked version of <a href=\"https:\/\/swaywm.org\/\">Sway<\/a> that I should probably write about. Here\u2019s how I added a feature I\u2019ve been missing for ages to <a href=\"https:\/\/sioyek.info\/\">Sioyek<\/a>, my PDF reader of choice.<\/p>\n\n<h2 id=\"the-annotation-sync-problem\">The Annotation Sync Problem<\/h2>\n\n<p>I use a combination of <a href=\"https:\/\/supernote.com\/\">Supernote e-ink tablets<\/a> and Sioyek on my computers to read and annotate academic PDFs. I enjoy jotting down thoughts on Supernote with <a href=\"https:\/\/supernote.com\/pages\/hom-gen-2\">a pen<\/a>. Sioyek has also recently improved its free-form annotation features, which I use regularly.<\/p>\n\n<p>The problem is that my two annotation systems aren\u2019t synchronised. I have sideloaded <a href=\"https:\/\/syncthing.net\/\">syncthing<\/a> on my Supernote, so file synchronisation between devices happens seamlessly. However, Supernote doesn\u2019t embed annotations directly into the PDF file, so Sioyek can\u2019t display them. Instead, Supernote stores annotations in a separate <code class=\"language-plaintext highlighter-rouge\">.mark<\/code> file alongside the PDF and overlays them when viewing on the device.<\/p>\n\n<p>Supernote does allow manual export of PDFs with annotations baked in, but that adds an extra step to my workflow. Ratta (Supernote\u2019s maker) is aware of this limitation, and there\u2019s an <a href=\"https:\/\/trello.com\/c\/RIMBXfRi\/48-f643-merge-handwritten-annotations-into-pdf\">open issue<\/a> for auto-merging annotations into PDFs.<\/p>\n\n<p>Originally I thought that\u2019s what I was waiting for. But I\u2019ve since realised I actually <em>prefer<\/em> storing annotations separately. This aligns better with how Sioyek works anyway. Sioyek stores annotations and highlights in a database and doesn\u2019t modify the PDF directly. Storing Supernote annotations in the PDF would likely break my Sioyek setup because it uses a hash of the PDF\u2019s <em>content<\/em> as the document key in the database, and modifying the PDF would create database duplicates.<\/p>\n\n<p>What I actually want is for Sioyek to understand <code class=\"language-plaintext highlighter-rouge\">.mark<\/code> files and overlay the annotations. Sioyek already has support for something similar: it can read <code class=\"language-plaintext highlighter-rouge\">.sioyek.drawings<\/code> files placed alongside PDFs. These files contain a <a href=\"https:\/\/github.com\/ahrm\/sioyek\/blob\/51a51a15999e5eee4ca40023e96726bc9ee4cde7\/pdf_viewer\/document.cpp#L3595\">JSON structure<\/a> that stores drawing data organised by page number, with each drawing defined by coordinates, timestamps, and styling properties.<\/p>\n\n<h2 id=\"adding-mark-support-to-sioyek\">Adding .mark Support to Sioyek<\/h2>\n\n<p>My ultimate goal was to make Sioyek understand and overlay <code class=\"language-plaintext highlighter-rouge\">.mark<\/code> files. Unfortunately, this is a proprietary format. There\u2019s a <a href=\"https:\/\/www.reddit.com\/r\/Supernote\/comments\/kv7ccz\/the_spec_for_the_notyyyyy_file_format\/\">thread<\/a> on <a href=\"https:\/\/www.reddit.com\/r\/Supernote\/\">\/r\/Supernote<\/a> where Ratta mentioned plans to open-source the format, but that thread is now five years old.<\/p>\n\n<p>Fortunately, the file format isn\u2019t entirely unknown. A Python library called <a href=\"https:\/\/github.com\/jya-dev\/supernote-tool\">supernote-tool<\/a> converts <code class=\"language-plaintext highlighter-rouge\">.note<\/code> and <code class=\"language-plaintext highlighter-rouge\">.mark<\/code> files into PNGs. I thought overlaying PNGs on PDFs could be a good intermediate step. I used this library to generate example PNGs from my <code class=\"language-plaintext highlighter-rouge\">.mark<\/code> files, then pointed my AI agent, Claude Opus 4.5, to Sioyek\u2019s <code class=\"language-plaintext highlighter-rouge\">.sioyek.drawings<\/code> mechanism. With these examples, the agent added PNG overlaying support easily. Even if direct <code class=\"language-plaintext highlighter-rouge\">.mark<\/code> support proved difficult, I could run a background task to generate PNGs from <code class=\"language-plaintext highlighter-rouge\">.mark<\/code> files and display those.<\/p>\n\n<p>I then pointed the agent to <code class=\"language-plaintext highlighter-rouge\">supernote-tool<\/code> and asked it to generate specifications for the <code class=\"language-plaintext highlighter-rouge\">.mark<\/code> file format. The format includes both a compressed layer bitmap (which can be extracted into PNG) and vector path data that isn\u2019t fully decoded yet. Ideally I\u2019d use the vector data, but PNG bitmaps would suffice for now.<\/p>\n\n<p>I fed this specification sheet into the agent along with sample PDFs and <code class=\"language-plaintext highlighter-rouge\">.mark<\/code> files. After a few iterations to iron out positioning and scaling issues, it successfully extracted the bitmap and overlaid it directly on the PDF. The quality isn\u2019t quite as crisp as what I see on Supernote, but it\u2019s close enough:<\/p>\n\n<div style=\"display: flex; gap: 1rem; align-items: center;\">\n  <figure style=\"flex: 1; margin: 0;\">\n    <a href=\"supernote.jpg\" target=\"_blank\">\n      <img src=\"supernote.jpg\" alt=\"Annotations displayed on Supernote device\" style=\"width: 100%; cursor: pointer;\" \/>\n    <\/a>\n  <\/figure>\n  <figure style=\"flex: 1; margin: 0;\">\n    <a href=\"sioyek.png\" target=\"_blank\">\n      <img src=\"sioyek.png\" alt=\"Annotations displayed in Sioyek\" style=\"width: 100%; cursor: pointer;\" \/>\n    <\/a>\n  <\/figure>\n<\/div>\n\n<p>Now I can seamlessly annotate on my Supernote, and thanks to syncthing, the annotations are automatically synced and visible in Sioyek on my computers. It doesn\u2019t work the other way around, but that\u2019s fine for my workflow.<\/p>\n\n<h2 id=\"how-can-i-get-it\">How Can I Get It!?<\/h2>\n\n<p>If you\u2019re on Arch Linux, you can get this build from the AUR package I\u2019ve put together:<\/p>\n\n<pre><code class=\"language-\/dev\/null\/shell.sh#L1-2\">yay -S sioyek-supernote\n<\/code><\/pre>\n\n<p>Otherwise, grab the latest build for your OS from the releases page (https:\/\/github.com\/mil-ad\/sioyek\/releases\/latest). These are built automatically from the fork, rebased on Sioyek\u2019s latest <code class=\"language-plaintext highlighter-rouge\">development <\/code>branch.<\/p>\n\n<p>Note that I\u2019ve only tested this with Supernote A5X on Arch Linux, and I don\u2019t know if it works on <code class=\"language-plaintext highlighter-rouge\">.mark<\/code> files generated on the newer <a href=\"https:\/\/supernote.com\/pages\/supernote-manta\">Manta<\/a> and <a href=\"https:\/\/supernote.com\/pages\/supernote-nomad\">Nomad<\/a> devices. I also haven\u2019t run extensive tests. I had several issues with scaling and positioning of annotations. They seem to work well now with standard A4 and letter page sizes, but I wouldn\u2019t be surprised if positions are off with some other page sizes.<\/p>\n\n<h2 id=\"whats-next\">What\u2019s Next?<\/h2>\n\n<p>The ideal solution would be to decode the vector data (embedded in the <code class=\"language-plaintext highlighter-rouge\">TOTALPATH<\/code> field) directly, which would give much better quality than the current PNG-based approach. In the meantime, I\u2019d like to get this merged upstream into Sioyek. The developer is great and has been receptive to new ideas in the few interactions I\u2019ve had with them, so hopefully this could happen soon.<\/p>\n\n<blockquote class=\"callout\">\n  <p><strong>Update (October 2026)<\/strong>: download links now point to permanent releases.<\/p>\n<\/blockquote>","author":{"name":"Milad Alizadeh"},"summary":"One of the core FOSS principles is the freedom to study how software works and adapt it to your needs. In practice, though, diving into a large, unfamiliar codebase in a domain you\u2019re not an expert in, using a programming language you\u2019re not necessarily proficient with, is hard."}]}