Skip to main content

Crate kakemono

Crate kakemono 

Source
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: LayoutConfig holds one of each. ExcelConfig holds the thresholds of the reading of a workbook, WorkbookPdfConfig those 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.
CancelToken
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.
ChunkOptions
Everything that controls how a document is cut into chunks.
ContentReport
What applying an edited JSON file did.
DocxOptions
Everything that controls how a document is written as a Word file.
DocxOutput
A Word document and its pictures as files of their own (see [render_docx_with_images]).
EpubOptions
Everything that controls how a document is written as an EPUB book.
HtmlOptions
Everything that controls how a document is written as HTML.
HtmlOutput
The result of the HTML output: the page itself and, when images are not inlined, the image files it refers to.
JsonOptions
Everything that controls how a document is written as JSON.
JsonOutput
The result of the JSON output: the text and, when pictures are not embedded, the picture files it refers to.
LatexOptions
Everything that controls how a document is written as LaTeX.
LatexOutput
The result of the LaTeX output: the source and the picture files it refers to.
MarkdownOptions
Everything that controls how a document is written as Markdown.
MarkdownOutput
The result of the Markdown output: the text and, when pictures are not embedded, the picture files it refers to.
PageRenderer
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.
TokenCounter
How the chunks output counts tokens. TokenCounter::default is the estimate; TokenCounter::load reads a real tokenizer, and TokenCounter::custom wraps any counting function.
TypstOptions
Everything that controls how a document is written as Typst.
TypstOutput
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.
InputFormat
The format of the file a Paper was loaded from. More formats may be added: a match on 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.
PageImage
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 with Balanced and 26 s with High, for 59, 46 and 42 MB of PNG.
TypstLayout
The layout of a Typst document.

Constants§

NAMED_TOKENIZERS
Names of the byte-pair encodings that --tokenizer takes 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 in data.
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.