Feynman Sun

Holograph

Does your handwritten homework for you. A neural network writes your LaTeX solution out stroke by stroke; it is not a font with noise.

替你写作业:LaTeX 解答交给它,神经网络一笔一笔写成手写稿,不是字体加扰动。

Feynman724/holographStar点 Star
  1. 1

    Source输入

    Markdown with LaTeX formulas (the format used by Typora, Obsidian and most AI assistants), with figures in TikZ or circuitikz. .tex files are also accepted.

    Markdown 加 LaTeX 公式(Typora、Obsidian 和多数 AI 助手输出的格式),图用 TikZ、circuitikz 等宏包编写。也接受 .tex 文件。

  2. 2

    Typeset by TeXTeX 排版

    XeLaTeX typesets each formula. Every glyph keeps the box TeX assigned to it, so the structure matches the printed version.

    每条公式由 XeLaTeX 排版,每个字形保留 TeX 给出的位置和大小,结构与印刷版一致。

  3. 3

    Handwritten glyphs换成手写字形

    Each box is filled with a pen trajectory rather than a font glyph: Chinese characters and letters are written stroke by stroke by a neural network (SDT), math symbols come from real MathWriting strokes. Each occurrence uses a different draft. Lines in figures are redrawn as freehand strokes.

    每个框填入一段笔迹轨迹,而不是字体字形:汉字和字母由神经网络(SDT)一笔一笔写出,数学符号取自 MathWriting 的真人笔迹。同一字形每次出现取不同的稿。图中的线条重绘为手画笔画。

  4. 4

    The hand’s habits书写习惯

    A page-style layer adds the irregularities of real handwriting: variation in size, baseline, spacing and slant, and slightly off-centre fractions.

    整页风格层加入真人书写的不规整:字的大小、基线、字距、倾斜有变化,分式略微偏离中心。

  5. 5

    Pen and paper笔和纸

    A pen model (gel, ballpoint, fountain or pencil) sets the width and ink of every stroke, on one of 26 paper templates.

    笔模型(签字笔、圆珠笔、钢笔、铅笔)决定每一笔的粗细和墨色,纸张有 26 种模板。

  6. 6

    Output输出

    An iPad-style PNG or vector PDF, a photo of paper, a scan-app capture or a flatbed scan.

    iPad 风格的 PNG 或矢量 PDF,或纸张照片、扫描 App、扫描仪效果。

20
university courses in the test set门大学课程的测试作业
453
math symbols across 14 fields, all from handwriting种数学符号,覆盖 14 个领域,均有手写来源
15
preset hands, or your own套预设字迹,也可以用自己的
5
figure packages supported: TikZ, pgfplots, circuitikz, tikz-cd, chemfig种画图宏包:TikZ、pgfplots、circuitikz、tikz-cd、chemfig
0
GPUs needed with a preset hand (4–10 s per page on CPU)用预设字迹不需要 GPU(CPU 每页 4–10 秒)

37 s

The pipeline in 37 seconds37 秒看完整个流程

One formula from a homework page: typeset by TeX, written into TeX’s boxes, loosened into the hand’s own layout, then the whole page in its four layers. Every stroke in the film is drawn from the system’s own output, in the preset hand “neat”.

作业里的一条公式:TeX 排版,手写字形填进 TeX 的字框,再按这套字迹的习惯松开,最后是整页和它的四层。片中每一笔都来自系统的实际输出,字迹是预设的“工整”。

01

Why not just a handwriting font?为什么不直接用手写字体?

The same solution rendered four ways, with one character written eight times below each. A font repeats the same glyph and leaves formulas printed; adding noise to a font does not change that. Holograph’s strokes are written by a neural network.

同一道题的四种渲染方式,每种下方是同一个字连写八遍。字体每次给出相同的字形,公式仍是印刷体,加扰动也改变不了这一点。Holograph 的笔画由神经网络一笔一笔写出。

Printed印刷体 LaTeX output, for reference.LaTeX 原样输出,作为参照。
Printed: the solution
Printed: one character written eight times
A handwriting font换手写字体 Text set in an open-source handwriting font (Xiaolai). Every 的 is identical, and the math stays printed.正文换成开源手写字体(小赖字体)。每个“的”完全相同,公式仍是印刷体。
A handwriting font: the solution
A handwriting font: one character written eight times
Font + jitter字体加扰动 Centrelines of a font (LXGW WenKai) with smooth noise and joins, laid out and inked by this system. The shapes are still the font’s and vary little between occurrences.取字体(霞鹜文楷)的笔画中线,加平滑扰动和连笔,由本系统排版和渲染。字形仍来自字体,多次出现之间差别很小。
Font + jitter: the solution
Font + jitter: one character written eight times
HolographHolograph Strokes written by a neural network trained on real handwriting, a different draft for every occurrence, laid out by TeX with a measured page-style layer.笔画由在真人手写上训练的神经网络写出,每次出现取不同的稿;由 TeX 排版,再经过按真人测量的整页风格层。
Holograph: the solution
Holograph: one character written eight times
Printed印刷体Handwriting font手写字体Font + jitter字体加扰动Holograph
Strokes come from pen trajectories (order, joins, width)笔画来自笔尖轨迹(笔顺、连笔、粗细)○○○●
The same character comes out different each time同一个字每次写得都不一样○○◐●
Formulas look handwritten too公式也是手写的○○●●
Chinese, letters and math look like one hand汉字、字母和公式像同一个人写的—○○●

● yes做到◐ partly部分做到○ no做不到

02

Hand-drawn figures手绘图

Figures written in TikZ, pgfplots, circuitikz, tikz-cd or chemfig are compiled by XeLaTeX; every vector path is then resampled and redrawn as a freehand stroke, and labels are written in the same hand as the text. Straight lines can also be drawn as if with a ruler. All figures below were generated directly from their source.

用 TikZ、pgfplots、circuitikz、tikz-cd、chemfig 编写的图先由 XeLaTeX 编译,再把每条矢量路径重新采样、重绘为手画笔画,标注与正文使用同一套字迹。直线也可以按尺规风格绘制。下列各图均由源码直接生成。

Two blocks over a pulley on an incline, with their forces斜面顶端的定滑轮和两个物体的受力
pulley.tex

03

Stroke-by-stroke replay逐笔回放

Input is Markdown with LaTeX, or a .tex file; output is an iPad-style PDF or a photo of paper. Formulas are typeset by TeX and every glyph is a pen trajectory, so repeated characters differ.

输入为 Markdown 加 LaTeX 公式,或 .tex 文件;输出为 iPad 风格的 PDF 或纸张照片。公式由 TeX 排版,每个字形都是笔迹轨迹,重复出现的字形状各不相同。

solution.md
Let $X$ follow an exponential
distribution with parameter $\lambda$.
Find $E(X)$.

Solution. By definition,

$$E(X) = \int_0^{\infty}
  x \lambda e^{-\lambda x}\,dx
  = \frac{1}{\lambda} .$$
设随机变量 $X$ 服从参数为 $\lambda$ 的指数分布,求 $E(X)$。

解:由定义,

$$E(X) = \int_0^{\infty}
  x \lambda e^{-\lambda x}\,dx
  = \frac{1}{\lambda} .$$
Select a hand to replay the same solution in it, stroke by stroke, in writing order. 选择一套字迹,用它按书写顺序逐笔重写同一段解答。

04

One solution, fifteen hands同一份解答,十五套字迹

Each preset blends several writers from a public dataset and is checked with a writer-identification model to ensure it does not match any one of them. Chinese, English and formulas on a page are written in one consistent hand.

每套预设由公开数据集中的多位书写者混合而成,并用书写者识别模型检查,不与其中任何一人对应。同一页中的中文、英文和公式字迹一致。

05

From neat to hurried从工整到潦草

Five preset hands, ordered from neatest to most hurried: strokes become looser and more joined, and rows less straight. Independently, --messy scales the layout irregularity of any hand (size, baseline, spacing, row starts) without changing glyph shapes; prose and formulas can be set separately.

五套预设字迹,按从工整到潦草排列:笔画逐渐松散、连笔增多,行也不再整齐。另外,--messy 可调节任一字迹的排版不规整程度(大小、基线、字距、行首位置),不改变字形;正文和公式可分别设置。

06

Same writing, on screen or on paper同一份笔迹,屏幕上或纸上

One page exported four ways. The strokes are identical; only the simulated display, camera or scanner differs.

同一页笔迹的四种导出方式。笔迹完全相同,只有模拟的屏幕、相机或扫描仪不同。

iPad-style exportiPad-style export
iPadPNG, or a vector PDFPNG,或矢量 PDF
Photo of paperPhoto of paper
Photo拍照desk, light, curl桌面、光照、卷边
Scan appScan app
Scan app扫描 Appcolour, grey or black & white彩色、灰度或黑白
Flatbed scanFlatbed scan
Scanner扫描仪flatbed, slightly skewed平板扫描,略有歪斜

26 paper templates26 种纸张模板

Photo output照片输出

The same page can be rendered as a phone photo of paper. Paper stock, lighting, camera angle, curl and creases are configurable. All sheets below are rendered; none was printed.

同一页也可以渲染成手机拍摄的纸张照片。纸张、光照、拍摄角度、卷边和折痕均可设置。下列纸张均为渲染结果,没有实际打印。

07

Course coverage课程覆盖

The test set covers 20 courses, mainly calculus, linear algebra and probability, plus physics, chemistry, circuits, signals and economics. It includes tables, piecewise functions, matrices, proofs, function plots and circuit diagrams; long homework is paginated automatically.

测试集覆盖 20 门课程,以微积分、线性代数、概率统计为主,另有物理、化学、电路、信号、经济等。内容包括表格、分段函数、矩阵、证明、函数图和电路图;较长的作业自动分页。

08

Your own handwriting使用自己的字迹

A profile can be built from homework you wrote on an iPad. Chinese needs at least a few hundred characters; more gives a closer match. This step requires an NVIDIA GPU.

可以用自己在 iPad 上手写的作业建立字迹档案。汉字至少需要几百个,越多越接近本人。这一步需要 NVIDIA 显卡。

  • Letters, digits and symbols that are rare in homework can be supplied with a glyph sheet, filled in on an iPad, on paper (photographed) or in a web page.
  • 作业中少见的字母、数字和符号可以用收集单补充,填写方式有 iPad、纸质打印后拍照、网页三种。
  • Your handwriting is used only to build your own profile. It is not used for training and can be deleted at any time.
  • 你的笔迹只用于建立你自己的字迹档案,不用于训练,可以随时删除。
  1. 1

    Provide homework PDFs提供作业 PDF

    Handwritten homework exported as PDF from GoodNotes, Notability, Notes or similar apps.

    在 iPad 上手写并导出为 PDF 的作业,支持 GoodNotes、Notability、备忘录等应用。

  2. 2

    Build a profile建立档案

    Characters are segmented and verified by two recognisers; size, spacing, slant and other page statistics are measured.

    切分出每个字并用两个识别器确认,同时测量字的大小、字距、倾斜等整页统计量。

  3. 3

    Render in your hand用自己的字迹渲染

    Characters absent from your samples are generated in your style.

    样本中没有的字按你的风格生成。

    holograph profile --pdfs my_homework/ --name me
    holograph render hw.md --hand me

09

Under the hood实现要点

Layout from real TeX版面由 TeX 决定

Formulas, tables and numbering are typeset by TeX. Handwriting replaces the glyphs but not their positions, so fractions, matrices and integrals keep the printed structure.

公式、表格和编号由 TeX 排版。手写只替换字形,不改变位置,因此分式、矩阵、积分的结构与印刷版一致。

Written by a neural network神经网络写的字

The characters are not a font with noise added. Chinese characters, letters and digits are written stroke by stroke by SDT1, a Transformer handwriting generator trained on CASIA2: given 15 reference characters of a hand, it outputs pen trajectories with stroke order, joins and varying width. Our recognisers keep only drafts they read correctly. Math symbols are real handwritten strokes from MathWriting3.

字不是字体加扰动。汉字、字母和数字由 SDT1 一笔一笔写出。SDT 是在 CASIA2 上训练的 Transformer 手写生成网络,给它一套字迹的 15 个参考字,它输出带笔顺、连笔和粗细变化的笔迹轨迹。我们训练的识别网络只保留认得出的稿。数学符号取自 MathWriting3 的真人笔迹。

Two layers: glyphs and page两层:字形和整页

A glyph layer determines the shape of each character; a page-style layer determines size, spacing and alignment across the page. The page-style parameters are calibrated on real handwritten lines, so Chinese, letters and math share one hand.

字形层决定每个字的形状,整页风格层决定整页的大小、字距和对齐。整页风格的参数按真实手写文本行标定,因此汉字、字母和公式字迹一致。

Evaluation评测

Discriminators trained to separate generated pages from real handwriting reach AUC 0.45–0.56 (0.5 is chance). Legibility is measured with independent recognisers, separate from those used to filter glyphs. Final acceptance is by visual inspection.

用于区分生成页和真实手写页的判别器 AUC 为 0.45–0.56(0.5 为随机水平)。可读性由独立的识别器测量,与筛选字形用的识别器分开。最终由人工目视验收。

Open-source components用到的开源技术

Handwriting generation手写生成
SDT (CVPR 2023, MIT), Chinese and English models, run and fine-tuned with PyTorch.(CVPR 2023,MIT),中文和英文两个模型,用 PyTorch 运行和微调。
Datasets数据集
CASIA-OLHWDB (training SDT and our recognisers, research use); MathWriting (handwritten math symbols, CC BY-NC-SA 4.0).CASIA-OLHWDB(训练 SDT 和识别网络,仅限研究);MathWriting(数学符号笔迹,CC BY-NC-SA 4.0)。
Typesetting排版
XeLaTeX (TeX Live / MacTeX) with unicode-math and amsmath; pandoc reads Markdown and .tex.XeLaTeX(TeX Live / MacTeX)、unicode-math、amsmath;pandoc 读 Markdown 和 .tex。
Figures画图
TikZ / PGF、pgfplots、circuitikz、tikz-cd、chemfig
PDFPDF
PyMuPDF reads TeX’s output and homework PDFs and writes the vector PDF; fontTools measures glyph ink boxes.PyMuPDF 读 TeX 输出和作业 PDF、写矢量 PDF;fontTools 计算字形墨迹框。
Rendering渲染
NumPy、SciPy、OpenCV、Pillow、Matplotlib

Why为什么做这个

Much homework does not need to be written by hand: problems you can already solve get copied out again, and the handwriting requirement is a formality. Holograph does that part. Whether a generated copy may be handed in is set by each course; you are responsible for how you use it.

现在很多作业没必要自己一笔一笔写:会做的题要再抄一遍,要求手写也只是形式。这一步交给它。生成的手写作业能否提交由各门课自己规定,使用后果由使用者自行负责。

Data and licences数据和许可

Trained and evaluated only on public datasets (CASIA-OLHWDB2, research use only; MathWriting3, CC BY-NC-SA) and the author’s own handwriting. Nobody else’s handwriting was collected. Because of these licences the system is for non-commercial use.

训练和评测只用公开数据集(CASIA-OLHWDB2,仅限研究用途;MathWriting3,CC BY-NC-SA)和作者本人的字迹,没有采集任何其他人的字迹。受这些许可限制,整个系统只能非商业使用。

The name名字

holograph (n.): a document written entirely in its author’s own hand.

holograph(名词):完全由作者亲笔写成的文件。

Status现状

Open source on GitHub: the code is MIT, the preset hands CC BY-NC-SA 4.0. Every sample on this page was written by a preset hand; none is the author’s.

已在 GitHub 开源:代码 MIT,预设字迹 CC BY-NC-SA 4.0。本页所有样张都由预设字迹写成,没有作者本人的字迹。

pip install -e .
holograph download
holograph render hw.md --hand preset:neat --look pdf photo

Star on GitHub在 GitHub 上 Star

If the project is useful to you, a star helps others find it. Layout errors and malformed symbols can be reported as issues.

如果这个项目对你有用,欢迎点 Star,方便其他人找到它。排版错误或写得不对的符号请提 issue。

Star on GitHub在 GitHub 上 Star
  1. Gang Dai, Yifan Zhang, Qingfeng Wang, et al. Disentangling Writer and Character Styles for Handwriting Generation (SDT). CVPR 2023.
  2. Cheng-Lin Liu, Fei Yin, Da-Han Wang, Qiu-Feng Wang. CASIA Online and Offline Chinese Handwriting Databases. ICDAR 2011.
  3. Philippe Gervais, Anastasiia Fadeeva, Andrii Maksai. MathWriting: A Dataset for Handwritten Mathematical Expression Recognition. 2024.