Expand description
kakemono: convert scientific-paper PDFs (such as those on arXiv), Word
documents (.docx, .doc), Excel workbooks (.xlsx), PowerPoint
presentations (.pptx), EPUB books (.epub) and web pages (an .html file or an http(s) address:
Paper::from_path, Paper::from_url) into clean HTML, Word
documents, Markdown, LaTeX, Typst or EPUB books.
The pipeline is: PDF access -> layout analysis and structuring ->
structured document (model) -> HTML in one of four fidelity modes
(Mode), a Word document (Paper::to_docx), Markdown
(Paper::to_markdown), LaTeX (Paper::to_latex), Typst
(Paper::to_typst) or an EPUB book (Paper::to_epub). See
ARCHITECTURE.md in the repository.
The entry points are Paper (load, analyse and render step by step,
e.g. to produce several modes from one analysis) and convert (all in
one call with default options). Analysis thresholds live in
LayoutConfig, reachable through AnalyzeOptions. Any of these can
be stopped from another thread or after a time limit with a
CancelToken.
Re-exports§
pub use config::AnalyzeOptions;pub use config::LayoutConfig;
Modules§
- config
- Options and tuning parameters of the analysis. The config struct of each
analysis stage is re-exported here:
LayoutConfigholds one of each.ExcelConfigholds the thresholds of the reading of a workbook,WorkbookPdfConfigthose of its layout in pages. - model
- The structured document produced by the layout analysis and consumed by the HTML renderers.
- source
- Where documents come from, besides local files (which the CLI reads itself): arXiv, and any address of the Web.
Structs§
- Analysis
- Result of the analysis of a paper.
- Cancel
Token - A request to stop a conversion, shared by the thread that runs it and those that may stop it (clones share the same request).
- Chunk
- One chunk: its text and where it comes from.
- Chunk
Options - Everything that controls how a document is cut into chunks.
- Content
Report - What applying an edited JSON file did.
- Docx
Options - Everything that controls how a document is written as a Word file.
- Docx
Output - A Word document and its pictures as files of their own (see
[
render_docx_with_images]). - Epub
Options - Everything that controls how a document is written as an EPUB book.
- Html
Options - Everything that controls how a document is written as HTML.
- Html
Output - The result of the HTML output: the page itself and, when images are not inlined, the image files it refers to.
- Json
Options - Everything that controls how a document is written as JSON.
- Json
Output - The result of the JSON output: the text and, when pictures are not embedded, the picture files it refers to.
- Latex
Options - Everything that controls how a document is written as LaTeX.
- Latex
Output - The result of the LaTeX output: the source and the picture files it refers to.
- Markdown
Options - Everything that controls how a document is written as Markdown.
- Markdown
Output - The result of the Markdown output: the text and, when pictures are not embedded, the picture files it refers to.
- Page
Renderer - Draws pages and page regions of one PDF. Keeps the render caches between calls, so it should be reused for all the pictures a thread draws.
- Paper
- A loaded PDF, Word document, Excel workbook, EPUB book or web page, ready to be analysed and rendered.
- Token
Counter - How the chunks output counts tokens.
TokenCounter::defaultis the estimate;TokenCounter::loadreads a real tokenizer, andTokenCounter::customwraps any counting function. - Typst
Options - Everything that controls how a document is written as Typst.
- Typst
Output - The result of the Typst output: the source and the picture files it refers to.
Enums§
- Cancelled
- Why a conversion stopped before its end.
- Equations
- How the reflowing modes (
medium,friendly) show displayed formulas. - Input
Format - The format of the file a
Paperwas loaded from. More formats may be added: amatchon it needs a_arm. - Mode
- Fidelity mode of the HTML output: how closely it follows the look of the PDF versus how readable and reflowable it is.
- Page
Image - Image format of the page backgrounds in hard and hard-95 modes.
- PngCompression
- How hard the PNG pictures drawn from the PDF are compressed. Every
level keeps the pixels exactly; they differ in time and size only. On a
1185-page textbook, compressing its 651 pictures took 0.75 s with
Fast, 2.9 s withBalancedand 26 s withHigh, for 59, 46 and 42 MB of PNG. - Typst
Layout - The layout of a Typst document.
Constants§
- NAMED_
TOKENIZERS - Names of the byte-pair encodings that
--tokenizertakes by name. - VERSION
- The version of kakemono.
Functions§
- add_
font - Adds a TrueType or OpenType font (or a collection) to those kakemono
lays out documents with and draws the text of SVG pictures with,
besides the fonts installed on the computer and in
KAKEMONO_FONT_DIRS. For where no font is installed: WebAssembly, small containers. It applies to the documents converted after it, in the whole process, and cannot be undone: the fonts are kept until the process ends. Returns the number of faces indata. - chunks_
jsonl - The chunks as JSON Lines: one object per line, each line ending with a line break.
- convert
- One-shot conversion: loads the PDF, analyses it and renders it.