Buckets:

Pranav2748's picture
download
raw
6.87 kB
"""REPORT.md -> results/report.pdf (reportlab; handles the markdown subset used in REPORT.md)."""
import re
import sys
from reportlab.lib import colors
from reportlab.lib.enums import TA_LEFT
from reportlab.lib.pagesizes import A4
from reportlab.lib.styles import ParagraphStyle, getSampleStyleSheet
from reportlab.lib.units import mm
from reportlab.lib.utils import ImageReader
from reportlab.platypus import (Image, KeepTogether, ListFlowable, ListItem, Paragraph, Preformatted, SimpleDocTemplate,
Spacer, Table, TableStyle)
SRC = "/workspace/think-decide/REPORT.md"
OUT = "/workspace/think-decide/results/report.pdf"
BASE = "/workspace/think-decide/"
INK, INK2, RULE, BLUE = colors.HexColor("#0b0b0b"), colors.HexColor("#52514e"), colors.HexColor("#d9d8d4"), colors.HexColor("#2a78d6")
ss = getSampleStyleSheet()
body = ParagraphStyle("body", parent=ss["BodyText"], fontName="Helvetica", fontSize=9.2, leading=12.6, textColor=INK,
spaceAfter=5, alignment=TA_LEFT)
small = ParagraphStyle("small", parent=body, fontSize=7.6, leading=9.6, spaceAfter=0)
cap = ParagraphStyle("cap", parent=body, fontSize=8, leading=10.5, textColor=INK2, spaceAfter=8)
h1 = ParagraphStyle("h1", parent=body, fontName="Helvetica-Bold", fontSize=17, leading=21, spaceAfter=8, spaceBefore=2)
h2 = ParagraphStyle("h2", parent=body, fontName="Helvetica-Bold", fontSize=12.5, leading=16, spaceBefore=10, spaceAfter=5)
h3 = ParagraphStyle("h3", parent=body, fontName="Helvetica-Bold", fontSize=10.5, leading=14, spaceBefore=8, spaceAfter=4)
code = ParagraphStyle("code", parent=body, fontName="Courier", fontSize=7.8, leading=9.8, backColor=colors.HexColor("#f3f2ef"),
borderPadding=5, spaceBefore=3, spaceAfter=8)
def inline(t):
t = t.replace("&", "&amp;").replace("<", "&lt;").replace(">", "&gt;")
t = re.sub(r"`([^`]+)`", r'<font name="Courier">\1</font>', t)
t = re.sub(r"\*\*([^*]+)\*\*", r"<b>\1</b>", t)
t = re.sub(r"(?<![\w*])\*([^*\s][^*]*?)\*(?![\w*])", r"<i>\1</i>", t)
t = t.replace("\\*", "*")
return t
def table(lines, width):
rows = [[c.strip() for c in l.strip().strip("|").split("|")] for l in lines]
rows = [r for r in rows if not all(re.fullmatch(r":?-{2,}:?", c) for c in r)]
ncol = max(map(len, rows))
lens = [max(len(r[i]) if i < len(r) else 0 for r in rows) for i in range(ncol)]
weights = [min(max(l, 6), 60) for l in lens]
cw = [width * w / sum(weights) for w in weights]
data = []
for ri, r in enumerate(rows):
st = ParagraphStyle("c", parent=small, fontName="Helvetica-Bold" if ri == 0 else "Helvetica")
data.append([Paragraph(inline(r[i]) if i < len(r) else "", st) for i in range(ncol)])
t = Table(data, colWidths=cw, repeatRows=1)
t.setStyle(TableStyle([("LINEBELOW", (0, 0), (-1, 0), 0.8, INK2), ("LINEBELOW", (0, 1), (-1, -1), 0.3, RULE),
("VALIGN", (0, 0), (-1, -1), "TOP"), ("TOPPADDING", (0, 0), (-1, -1), 2.5),
("BOTTOMPADDING", (0, 0), (-1, -1), 2.5), ("LEFTPADDING", (0, 0), (-1, -1), 3),
("RIGHTPADDING", (0, 0), (-1, -1), 3)]))
return t
def build():
doc = SimpleDocTemplate(OUT, pagesize=A4, leftMargin=17 * mm, rightMargin=17 * mm, topMargin=15 * mm, bottomMargin=15 * mm,
title="Can diffusion steps replace token thinking in a decision model?", author="think-decide")
W = A4[0] - 34 * mm
lines = open(SRC).read().splitlines()
story, i = [], 0
while i < len(lines):
l = lines[i]
if not l.strip():
i += 1
continue
if l.startswith("```"):
j = i + 1
while not lines[j].startswith("```"):
j += 1
story.append(Preformatted("\n".join(lines[i + 1:j]), code))
i = j + 1
continue
if l.startswith("# "):
story.append(Paragraph(inline(l[2:]), h1))
elif l.startswith("## "):
story.append(Paragraph(inline(l[3:]), h2))
elif l.startswith("### "):
story.append(Paragraph(inline(l[4:]), h3))
elif l.startswith("!["):
m = re.match(r"!\[([^\]]*)\]\(([^)]+)\)", l)
path = BASE + m.group(2)
iw, ih = ImageReader(path).getSize()
w = min(W, iw * 0.36)
story.append(Spacer(1, 3))
story.append(Image(path, width=w, height=w * ih / iw))
story.append(Spacer(1, 3))
elif l.startswith("|"):
j = i
while j < len(lines) and lines[j].startswith("|"):
j += 1
story.append(table(lines[i:j], W))
story.append(Spacer(1, 7))
i = j
continue
elif re.match(r"^(\s*)(- |\d+\. )", l):
items, j = [], i
numbered = bool(re.match(r"^\d+\. ", l))
while j < len(lines) and (re.match(r"^(- |\d+\. )", lines[j]) or (lines[j].startswith(" ") and lines[j].strip())):
if re.match(r"^(- |\d+\. )", lines[j]):
items.append(re.sub(r"^(- |\d+\. )", "", lines[j]))
elif lines[j].strip().startswith("- "):
items[-1] += " QQBRQQ " + lines[j].strip()[2:]
else:
items[-1] += " " + lines[j].strip()
j += 1
fix = lambda t: inline(t).replace(" QQBRQQ ", "<br/>&nbsp;&nbsp;&nbsp;&#8211; ")
story.append(ListFlowable([ListItem(Paragraph(fix(t), body), leftIndent=12) for t in items],
bulletType="1" if numbered else "bullet", start="1" if numbered else None,
leftIndent=12, bulletFontSize=7 if not numbered else 9, bulletColor=INK2))
i = j
continue
else:
j, para = i, []
while j < len(lines) and lines[j].strip() and not re.match(r"^(#|\||!\[|```|- |\d+\. )", lines[j]):
para.append(lines[j].strip())
j += 1
text = " ".join(para)
if text.startswith("*Figure") and text.endswith("*"):
story.append(Paragraph("<i>%s</i>" % inline(text[1:-1]), cap))
else:
story.append(Paragraph(inline(text), body))
i = j
continue
i += 1
def footer(canvas, doc_):
canvas.saveState()
canvas.setFont("Helvetica", 7.5)
canvas.setFillColor(INK2)
canvas.drawString(17 * mm, 9 * mm, "think-decide · diffusion steps vs token thinking · 2026-11-06")
canvas.drawRightString(A4[0] - 17 * mm, 9 * mm, "%d" % doc_.page)
canvas.restoreState()
doc.build(story, onFirstPage=footer, onLaterPages=footer)
print("wrote", OUT)
if __name__ == "__main__":
build()

Xet Storage Details

Size:
6.87 kB
·
Xet hash:
57e633a68e0800c24987d61f72c867d5ce499ba23727471d22dd908f7a9c484b

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.