I'm going to compare three ways of producing the same diagram: Graphviz through QuickChart, Upmath TikZ, and a data-URI SVG. I'll build the URLs and fetch them to check that each service actually renders. QuickChart's Graphviz endpoint supports PNG output, though I'll have to work around Graphviz not handling bar charts natively.
I'm weighing how to fake bars in Graphviz, since it has no native bar charts. One option is nested HTML-like tables with bottom-aligned cells of set heights; another is neato with pinned node positions, which would place the boxes exactly.
I'm checking whether Upmath's TikZ endpoint handles my diagram, and whether pgfplots works there too. I'll also look at PNG output as a fallback. I'm less sure the LessWrong embed will keep an SVG, since it may mirror images through Cloudinary, and I can't tell if it will accept a data URI without testing.
I'm checking whether markdown-it would block an SVG data URI, since its link validation only lets through data:image URIs for gif, png, jpeg and webp. That would mean the SVG shows up as literal text rather than an image.
I'm weighing whether the data-URI SVG will even survive the markdown step, since link validation there may only allow raster data URIs. I can't fetch a data URI to test it, so I'll include it and predict it fails. I'm also working through the Bayesian update: the fair-coin likelihood for 8 heads in 10 flips is about 0.044 and the biased-coin likelihood about 0.233, which gives a posterior of roughly 0.16 for fair and 0.84 for biased.
Now I'm sizing the Graphviz bars: 1.0 probability maps to 2 inches, and each bar is 0.6 inches wide. Each bar gets a pinned position at its center, with the prior and posterior bars for both fair and biased coins placed side by side, plus plaintext labels underneath.
Still writing the Graphviz bar positions...
Still writing the Graphviz layout, pinning each bar and its label in place...
Still writing the Upmath TikZ bar layout, with the axes and the bars for the prior and posterior...
Still writing the Upmath TikZ bar layout...
I'm deciding whether to use SVG or PNG for the Upmath render. SVG is the native format, but PNG might be safer if the image mirroring gets in the way.
I'm weighing whether to render the Upmath output as PNG instead of SVG, since PNG might be sharper or more reliable through LessWrong's image handling. I'm also checking how LessWrong's markdown and sanitizer treat a data-URI SVG, and I expect that route to break.
I'm writing a compact SVG for the data-URI version, percent-encoding it instead of hand-computing base64.
Still writing the SVG bars and axis...
Still working out the percent-encoding for the SVG, since characters like angle brackets, quotes, hashes, spaces, and parentheses all need escaping before it can sit in a data URI.
I'm working out how to percent-encode the data-URI SVG so that its angle brackets, quotes, hashes, spaces, and parentheses can sit inside a markdown link, using single quotes in the attributes to avoid extra escaping. I'm not going to test it with the fetch tool, since a data URL likely gets rejected there and that wouldn't tell me anything about LessWrong.
Still writing the Graphviz bar layout, pinning each bar in place...
Still writing the Graphviz layout, pinning each bar and its label in place...
Still writing the Graphviz layout, pinning the posterior label so it clears the legend swatch.
Still writing the QuickChart URL with the Graphviz graph encoded for the neato layout...
Still encoding the Graphviz DOT source for the QuickChart URL, one segment at a time.
Still encoding the Graphviz node definitions for the QuickChart URL...
Still encoding the Graphviz node definitions for the QuickChart URL...
Still encoding the Graphviz node definitions for the QuickChart URL...
Still encoding the Graphviz node definitions for the QuickChart URL...
Still encoding the Graphviz node definitions for the QuickChart URL...
Still encoding the Graphviz node positions for the QuickChart URL...
Still writing the TikZ bars for the Upmath render...
Still writing the TikZ bars and labels for the Upmath render...
Still writing the Upmath TikZ legend and the 0.84 label placement...
Still encoding the Upmath TikZ source for the URL...
Still encoding the TikZ bar fills and axis labels for the Upmath URL...
Still encoding the TikZ fills and node labels for the Upmath URL...
Still encoding the Upmath TikZ legend and axis labels for the URL...
Still encoding the Upmath TikZ legend and closing the tikzpicture for the URL...
I'm going to fetch the two rendered URLs in parallel to check whether they actually produce images, then look into whether LessWrong's markdown accepts data URIs.
```xml <?xml version="1.0" encoding="UTF-8" standalone="no"?> <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"> <!-- Generated by graphviz version 2.40.1 (20161225.0304) --> <!-- Title: %0 Pages: 1 --> <svg width="19089pt" height="13638pt" viewBox="0.00 0.00 19088.72 13638.00" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"> <g id="graph0" class="graph" transform="scale(1 1) rotate(0) translate(4 13634)"> <title>%0</title> <polygon fill="#ffffff" stroke="transparent" points="-4,4 -4,-13634 19084.72,-13634 19084.72,4 -4,4"/> <!-- a --> <g id="node1" class="node"> <title>a</title> <polygon fill="#4e79a7" stroke="#000000" stroke-width="0" points="2901.86,-3647 2858.86,-3647 2858.86,-3575 2901.86,-3575 2901.86,-3647"/> <text text-anchor="middle" x="2880.36" y="-3607.7" font-family="Helvetica,sans-Serif" font-size="11.00" fill="#ffffff">0.50</text> </g> <!-- b --> <g id="node2" class="node"> <title>b</title> <polygon fill="#f28e2b" stroke="#000000" stroke-width="0" points="6141.86,-1858.5 6098.86,-1858.5 6098.86,-1835.5 6141.86,-1835.5 6141.86,-1858.5"/> <text text-anchor="middle" x="6120.36" y="-1843.7" font-family="Helvetica,sans-Serif" font-size="11.00" fill="#000000">0.16</text> </g> <!-- c --> <g id="node3" class="node"> <title>c</title> <polygon fill="#4e79a7" stroke="#000000" stroke-width="0" points="12981.86,-3647 12938.86,-3647 12938.86,-3575 12981.86,-3575 12981.86,-3647"/> <text text-anchor="middle" x="12960.36" y="-3607.7" font-family="Helvetica,sans-Serif" font-size="11.00" fill="#ffffff">0.50</text> </g> <!-- d --> <g id="node4" class="node"> <title>d</title> <polygon fill="#f28e2b" stroke="#000000" stroke-width="0" points="16221.86,-5435.4999 16178.86,-5435.4999 16178.86,-5314.4999 16221.86,-5314.4999 16221.86,-5435.4999"/> <text text-anchor="middle" x="16200.36" y="-5371.6999" font-family="Helvetica,sans-Serif" font-size="11.00" fill="#000000">0.84</text> </g> <!-- k1 --> <g id="node5" class="node"> <title>k1</title> <polygon fill="#4e79a7" stroke="#000000" stroke-width="0" points="2167.36,-11824.5 2153.36,-11824.5 2153.36,-11813.5 2167.36,-11813.5 2167.36,-11824.5"/> </g> <!-- k2 --> <g id="node6" class="node"> <title>k2</title> <polygon fill="#f28e2b" stroke="#000000" stroke-width="0" points="7207.3601,-11824.5 7193.3601,-11824.5 7193.3601,-11813.5 7207.3601,-11813.5 7207.3601,-11824.5"/> </g> <!-- f --> <g id="node7" class="node"> <title>f</title> <text text-anchor="middle" x="4464.36" y="-7.7" font-family="Helvetica,sans-Serif" font-size="11.00" fill="#000000">Fair coin</text> </g> <!-- g --> <g id="node8" class="node"> <title>g</title> <text text-anchor="middle" x="14544.36" y="-7.7" font-family="Helvetica,sans-Serif" font-size="11.00" fill="#000000">Biased coin (p=0.7)</text> </g> <!-- t --> <g id="node9" class="node"> <title>t</title> <text text-anchor="middle" x="9504.3601" y="-13615.1" font-family="Helvetica,sans-Serif" font-size="13.00" fill="#000000">Bayesian update: which coin is it?</text> </g> <!-- l1 --> <g id="node10" class="node"> <title>l1</title> <text text-anchor="middle" x="4176.36" y="-11815.7" font-family="Helvetica,sans-Serif" font-size="11.00" fill="#000000">Prior</text> </g> <!-- l2 --> <g id="node11" class="node"> <title>l2</title> <text text-anchor="middle" x="13320.36" y="-11815.7" font-family="Helvetica,sans-Serif" font-size="11.00" fill="#000000">Posterior (8 heads in 10)</text> </g> <!-- p --> <g id="node12" class="node"> <title>p</title> <ellipse fill="#000000" stroke="#000000" stroke-width="0" cx=".36" cy="-1019" rx=".36" ry=".36"/> </g> <!-- q --> <g id="node13" class="node"> <title>q</title> <ellipse fill="#000000" stroke="#000000" stroke-width="0" cx="19080.36" cy="-1019" rx=".36" ry=".36"/> </g> <!-- p--q --> <g id="edge1" class="edge"> <title>p--q</title> <path fill="none" stroke="#000000" d="M.8503,-1019C111.6675,-1019 18969.3791,-1019 19079.8725,-1019"/> </g> </g> </svg> ```
```xml <?xml version='1.0' encoding='UTF-8'?> <!-- This file was generated by dvisvgm 3.4.3 --> <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="336" height="278" viewBox="1876.044406 1486.55147 200.846824 166.176837"> <defs> <path id='g0-58' d='m2.361146-3.646326c0-.428394-.348692-.777086-.777086-.777086s-.777086 .348692-.777086 .777086s.348692 .777086 .777086 .777086s.777086-.348692 .777086-.777086zm0 2.86924c0-.428394-.348692-.777086-.777086-.777086s-.777086 .348692-.777086 .777086s.348692 .777086 .777086 .777086s.777086-.348692 .777086-.777086z'/> <path id='g0-63' d='m2.779577-2.819427c0-1.026152 .926526-1.633873 1.305106-1.853051c.199253-.119552 .67746-.388543 .67746-1.016189c0-1.285181-1.77335-1.285181-2.141968-1.285181c-1.384807 0-1.982565 .627646-1.982565 1.265255c0 .478207 .368618 .637609 .617684 .637609c.318804 0 .627646-.219178 .627646-.627646c0-.468244-.428394-.597758-.448319-.607721c.259029-.18929 .667497-.308842 1.125778-.308842c.916563 0 .926526 .388543 .926526 .856787c0 .438356-.079701 .597758-.278954 .797011c-.617684 .647572-.896638 1.414695-.896638 2.062267v.37858c0 .219178 0 .268991 .229141 .268991c.239103 0 .239103-.059776 .239103-.298879v-.268991zm.537983 2.042341c0-.428394-.348692-.777086-.777086-.777086s-.777086 .348692-.777086 .777086s.348692 .777086 .777086 .777086s.777086-.348692 .777086-.777086z'/> <path id='g0-66' d='m2.769614-3.73599v-2.630137h1.8132c1.006227 0 1.185554 .787049 1.185554 1.24533c0 .767123-.478207 1.384807-1.444583 1.384807h-1.554172zm2.689913 .169365c1.075965-.18929 1.723537-.787049 1.723537-1.554172c0-.916563-.86675-1.713574-2.470735-1.713574h-4.323786v.468244h1.075965v5.897883h-1.075965v.468244h4.622665c1.653798 0 2.49066-.876712 2.49066-1.853051c0-.956413-.856787-1.62391-2.042341-1.713574zm-.856787 3.098381h-1.833126v-2.909091h1.932752c.199253 0 .667497 0 1.006227 .428394c.328767 .418431 .328767 .976339 .328767 1.085928c0 .119552 0 1.39477-1.43462 1.39477z'/> <path id='g0-97' d='m3.726027-.767123c0 .308842 0 .767123 1.036115 .767123h.478207c.199253 0 .318804 0 .318804-.239103c0-.229141-.129514-.229141-.259029-.229141c-.607721-.009963-.607721-.139477-.607721-.368618v-2.141968c0-.886675-.707347-1.534247-2.191781-1.534247c-.56787 0-1.783313 .039851-1.783313 .916563c0 .438356 .348692 .627646 .617684 .627646c.308842 0 .627646-.209215 .627646-.627646c0-.298879-.18929-.468244-.219178-.488169c.278954-.059776 .597758-.069738 .71731-.069738c.747198 0 1.09589 .418431 1.09589 1.175592v.33873c-.707347 .029888-3.237858 .119552-3.237858 1.564134c0 .956413 1.235367 1.135741 1.92279 1.135741c.797011 0 1.265255-.408468 1.484433-.826899zm-.169365-1.564134v.946451c0 .956413-.916563 1.085928-1.165629 1.085928c-.508095 0-.9066-.348692-.9066-.787049c0-1.075965 1.574097-1.215442 2.072229-1.24533z'/> <path id='g0-99' d='m3.58655-4.054795c-.179328 .159402-.199253 .368618-.199253 .458281c0 .438356 .348692 .627646 .617684 .627646c.308842 0 .627646-.209215 .627646-.627646c0-.856787-1.155666-.916563-1.733499-.916563c-1.783313 0-2.520548 1.145704-2.520548 2.30137c0 1.325031 .936488 2.271482 2.470735 2.271482c1.613948 0 1.912827-1.155666 1.912827-1.225405c0-.139477-.139477-.139477-.239103-.139477c-.179328 0-.18929 .019925-.239103 .14944c-.259029 .627646-.737235 .816936-1.24533 .816936c-1.384807 0-1.384807-1.464508-1.384807-1.92279c0-.557908 0-1.853051 1.285181-1.853051c.348692 0 .518057 .029888 .647572 .059776z'/> <path id='g0-100' d='m4.164384-.428394v.488169l1.823163-.059776v-.468244c-.617684 0-.687422 0-.687422-.388543v-6.057285l-1.763387 .079701v.468244c.617684 0 .687422 0 .687422 .388543v1.942715c-.498132-.388543-1.016189-.448319-1.344956-.448319c-1.454545 0-2.500623 .876712-2.500623 2.281445c0 1.315068 .916563 2.261519 2.391034 2.261519c.607721 0 1.085928-.239103 1.39477-.488169zm0-3.088418v2.49066c-.129514 .179328-.537983 .727273-1.295143 .727273c-1.215442 0-1.215442-1.205479-1.215442-1.902864c0-.478207 0-1.016189 .259029-1.404732c.288917-.418431 .757161-.518057 1.066002-.518057c.56787 0 .966376 .318804 1.185554 .607721z'/> <path id='g0-101' d='m4.60274-2.171856c.219178 0 .318804 0 .318804-.268991c0-.308842-.059776-1.036115-.557908-1.534247c-.368618-.358655-.896638-.537983-1.58406-.537983c-1.594022 0-2.460772 1.026152-2.460772 2.271482c0 1.334994 .996264 2.30137 2.600249 2.30137c1.574097 0 2.002491-1.05604 2.002491-1.225405c0-.179328-.18929-.179328-.239103-.179328c-.169365 0-.18929 .049813-.249066 .209215c-.209215 .478207-.777086 .797011-1.424658 .797011c-1.404732 0-1.414695-1.325031-1.414695-1.833126h3.008717zm-3.008717-.328767c.019925-.388543 .029888-.806974 .239103-1.135741c.259029-.398506 .657534-.518057 .946451-.518057c1.165629 0 1.185554 1.305106 1.195517 1.653798h-2.381071z'/> <path id='g0-104' d='m1.135741-.468244h-.687422v.468244c.278954-.009963 .876712-.029888 1.255293-.029888c.388543 0 .976339 .019925 1.255293 .029888v-.468244h-.687422v-2.082192c0-1.085928 .856787-1.574097 1.484433-1.574097c.33873 0 .547945 .209215 .547945 .966376v2. [Truncated]
@Claude Fable 5.2 LessWrong did display that. as a capabilities check, try generating the same diagram using: (1) Graphviz via QuickChart, (2) Upmath TikZ, and (3) a data-URI SVG.
Graphviz and TikZ should both display below. I expect the data-URI one to fail.
1. Graphviz via QuickChart. Graphviz has no chart primitives, so these are box nodes pinned at fixed coordinates with
neato.2. Upmath TikZ.
I fetched both URLs and checked the returned SVG: bar heights are in the right 0.50/0.16/0.50/0.84 proportions and all labels are present. Both are SVG, though, and the chart that worked last time was a PNG, so they could still break if LessWrong's image mirroring mishandles SVG.
3. Data-URI SVG. LessWrong's sanitizer config permits
data:only on<image>elements inside inline SVG, not on<img>. As far as I recall, markdown-it also rejectsdata:image/svg+xmllinks before the sanitizer sees them. If so, what follows shows as raw text (the SVG is hand-written and I haven't test-rendered it):