Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Editable JSON

kakemono convert paper.pdf -o paper.json (or --format json) writes the content of the document for other programs: search, language models, data extraction, or your own reader. The blocks come in reading order; formulas whose structure is clear also come as LaTeX and MathML, figures and the other formulas as pictures in paper_assets/:

{
  "format": "kakemono-content", "version": 1, "generator": "kakemono 0.10.0",
  "source": { "format": "pdf", "name": "1602.03837v1.pdf", "sha256": "e5e864c2…" },
  "meta": { "title": "Observation of Gravitational Waves from a Binary Black Hole Merger" },
  "pages": [[612.0, 792.0], …],
  "blocks": [
    { "id": 7, "type": "heading", "level": 1, "anchor": "sec-I", "text": "I. INTRODUCTION",
      "layout": { "page": 0, "bbox": [127.67, 308.36, 221.39, 318.86] } },
    { "id": 5, "type": "paragraph", "abstract": true, "section": 4,
      "text": "… a peak gravitational-wave strain of 1.0 × <m id=\"1\">10^{-21}</m>. It matches …" },
    { "id": 20, "type": "equation", "latex": "…", "mathml": "<math …>", "image": "paper_assets/002-eq.png" }
  ]
}
  • type is title, authors, note, heading (with its level and the parent heading), paragraph (abstract when it is part of the abstract), list_item, list_continuation, equation, figure (with its float kind, label, image, the figure_text found inside it and a rebuilt table), footnote, reference, code (its lines) or contents_entry. section is the id of the heading a block is under; layout is its page (from 0) and box in points.
  • text is one string, so that a paragraph can be edited (or translated) as a whole: <b>, <i>, <code>, <sup>, <sub>, <sf> (sans-serif), <sc> (small capitals), <mf> (math font), <a href> and <font color> keep the styles and links; <m id="n">…</m> stands for the n-th formula of the block, with its LaTeX inside. <note>…</note> is a note added to the text when it is edited (a translator’s note, an editor’s or a reviewer’s, say), attached at that point of the text, for example “<i>Mon ami</i><note>French: <i>my friend</i>.</note> Hastings!”: it may hold the style tags and links, but no formula and no other note. (This tag is unrelated to a block of type note.)
  • plain is the same text without tags, formulas as $LaTeX$ ($$…$$ for a displayed formula), for search indexes and language models; table cells have one too.

Bibliographic fields. For data extraction the file also has what could be read with confidence from the front matter and the reference list (a field that could not be read is left out):

"meta": {
  "title": "Attention Is All You Need", "arxiv_id": "1706.03762v7",
  "arxiv_category": "cs.CL", "date": "2023-08-02", "doi": "…", "keywords": ["…"],
  "authors": [{ "name": "Ashish Vaswani", "affiliations": [0], "emails": ["avaswani@google.com"], "notes": [0] }, …],
  "affiliations": ["Google Brain", "Google Research", "University of Toronto"],
  "author_notes": ["Equal contribution. Listing order is random. …", …],
  "abstract": "The dominant sequence transduction models are …"
}
{ "id": 160, "type": "reference", "label": "32", "text": "[32] Noam Shazeer, … <i>arXiv preprint </i>…",
  "citation": { "authors": ["Noam Shazeer", "Azalia Mirhoseini", …, "Jeff Dean"],
                "title": "Outrageously large neural networks: The sparsely-gated mixture-of-experts layer",
                "venue": "arXiv", "year": 2017, "arxiv": "1701.06538" } }
  • authors come from the author block: names (told apart by commas, “and”, or the gaps between names printed side by side), the affiliations below them or pointed to by a raised mark (Jane Doe¹), the e-mail addresses ({a, b}@example.com gives two) and notes (∗ Equal contribution). date is that of the arXiv version (from its stamp), else the date printed with the authors.
  • citation gives authors (given names first, et_al when the list is cut), title, venue, year, volume, pages, doi, arxiv and url. It knows the usual styles (IEEE with a quoted title, ACL/APA with the year after the authors, the astronomy and physics styles without titles, books in italics); on the papers of the test suite most references give authors, title and year. A reference with no year written gets the year of its arXiv identifier.
  • These fields, like plain, are read-only: they are derived from the text and not read back.

Applying an edited file. --content writes any output with the text of an edited JSON file:

kakemono convert paper.pdf -o paper.json
# edit paper.json (translate it, ...) into paper.vi.json
kakemono convert paper.pdf --content paper.vi.json -m hard-95 -o paper.vi.html
kakemono convert paper.pdf --content paper.vi.json -o paper.vi.docx   # or .md, .tex, .epub, friendly, medium

The PDF provides the frame (pictures, formulas, page layout), the JSON the text. What can be edited is the text of blocks and table cells and the rows of author groups; formulas stay what they are wherever their <m> tag is put, whatever is written inside it. The rest is read-only. Blocks left out of the file, or left unchanged, keep their text, so an unedited file changes nothing. Extra fields are ignored, so a file can keep the original next to the edited text. The file must come from the same PDF (its sha256) and the same analysis options (--tables). A block whose markup cannot be read (an unknown tag) keeps its text, with a warning.

Added notes (<note>) are printed as they are written and numbered in reading order: in friendly and medium a raised number links to the note, listed in a small aside after its block; in hard-95 the number opens the note in a popup; Word gets real footnotes, LaTeX \footnotes, Typst footnotes (numbered again in each chapter of a book), Markdown [^n1] footnotes and EPUB popup footnotes at the end of each chapter (numbered again in each chapter). plain and the chunks leave the notes out. A <note> that is not closed, or that holds a formula or another note, is read with a warning.

Translating the text inside a figure. A figure whose picture has text in the PDF (labels, legends, the boxes of a diagram) lists it in figure_lines, as runs: a label, or the lines of one paragraph inside a box, each {"text": "…", "box": [x0, y0, x1, y1], "size": pt}, the text editable like a block’s. An edited run is written in place: the figure is drawn again without the glyphs of the old text, and the new text is written in its box, in a sans-serif (or monospaced) font of the run’s size and weight, broken into lines that fit the box (made smaller, down to 75%, when it needs more lines than the run had; a one-line label may grow to 1.6 times its width). The figure then becomes an SVG, as with replace_image below, which wins when both are given. Rotated text (an axis title written upwards) comes after the other runs, with its rotation in degrees, and is written back along the same line, centred on the old text. A tick label never joins the words of a label next to it.

Replacing a figure’s picture. A figure block may also get "replace_image": a PNG, JPEG or SVG file, named by a path relative to the JSON file, or a data URI. Every output then draws it in place of the figure’s picture (a translated or redrawn figure, say). An SVG stays an SVG in the HTML modes, EPUB, Markdown and JSON, with its text turned into paths so that it looks the same without its fonts; Word, LaTeX and Typst get it as a PNG at --scale. In hard-95 the picture covers the figure’s box on the page, and the figure’s old text layer is left out. In every output a picture of another shape than the figure is fitted into its box and centred, never stretched, and the pictures an SVG names (relative to the SVG) are kept inside it. A picture whose shape differs from the figure’s box, a file that cannot be read, or replace_image on a block that is not a figure with a picture is a warning; the figure then keeps its picture (except for the shape, where the new picture is still used). A JSON written again after --content has the new picture in image and no replace_image. With the library, Paper::apply_content_in(&mut analysis, &json, folder) reads relative paths from the JSON’s folder; Paper::apply_content, which has no folder, takes only data URIs and absolute paths.

In hard-95 an edited block flows inside the box of its lines, its type made smaller when the new text is longer (down to 62%), and a paragraph that runs over columns or pages runs over them again. The hard mode shows the pages themselves and cannot show edited text. In LaTeX output, pdfLaTeX prints Vietnamese (with vntex); for scripts its fonts lack (Chinese, say), use XeLaTeX or LuaLaTeX.