@mkbabb/latex-paper
v0.2.1
Published
LaTeX in, navigable paper data out.
Readme
latex-paper
LaTeX in, navigable paper data out.
latex-paper parses .tex and .bib, resolves labels and citations, builds a typed section tree, and can expose the result as a Vite virtual module. The Vue entry point adds the rendering and windowing primitives used by the paper view in fourier-analysis.
See docs/virtual-paper.md for the end-to-end path.
Install
npm install @mkbabb/latex-paperEntry points
| Export | Purpose |
| --- | --- |
| @mkbabb/latex-paper | Pure parser types and helpers |
| @mkbabb/latex-paper/transform | AST → PaperSectionData[] transform |
| @mkbabb/latex-paper/vite | Build-time virtual module for paper content |
| @mkbabb/latex-paper/vue | Vue components and virtual-window composables |
| @mkbabb/latex-paper/theme | Base paper styles |
Core path
parseLatex()builds the AST.Transformerturns that AST intoPaperSectionData[], interleaving prose, display math, theorems, and figures ascontentblocks.flattenPaperSections()derives a stable depth-first list with hierarchy metadata and height estimates.useVirtualSectionWindow()turns that flat list into a bounded render window with top and bottom spacers.latexPaperPlugin()emitspaperSections,labelMap,pageMap,totalPages, andextractedMacrosthroughvirtual:paper-content.
The page map is ordered, not title-matched. It is built from LaTeX TOC artifacts, so math-heavy headings no longer fall back to page 1.
Quick start
import latexPaperPlugin from "@mkbabb/latex-paper/vite";
export default {
plugins: [
latexPaperPlugin({
texPath: "paper/main.tex",
bibPath: "paper/refs.bib",
}),
],
};import { paperSections, labelMap, pageMap, totalPages, extractedMacros } from "virtual:paper-content";Vue primitives
Components—PaperSection, PaperSectionBlocks, PaperSectionContent, MathBlock, MathInline, Theorem, CodeBlock. These cover headings, section bodies, display/inline math, theorems, and code listings.
Composables—usePaperReader, useVirtualSectionWindow, useSidebarFollow, useKatex, flattenPaperSections. Reader setup, virtual windowing, sidebar scroll tracking, KaTeX rendering, and tree flattening.
Tracking primitives—useLazyLoader, useTreeIndex, useScrollTracker, useScrollTo, useClickDelegate. Generic scroll and intersection utilities used by the composables above.
Context—PAPER_CONTEXT and createRenderTitle for dependency injection across the component tree.
Output shape
interface PaperSectionData {
id: string;
number: string;
title: string;
sourceLevel?: number;
starred?: boolean;
content: ContentBlock[];
theorems?: PaperTheoremData[];
figures?: PaperFigureData[];
codeBlocks?: PaperCodeBlockData[];
proofs?: PaperProofData[];
subsections?: PaperSectionData[];
callout?: { text: string; link: string };
summary?: string;
}ContentBlock is one of:
- paragraph HTML string
MathBlockData—display equationTheoremBlock—theorem, definition, lemma, etc.FigureBlock—figure with captionCodeBlock—code listingProofBlock—proof body
Development
npm test
npm run build
npm packNotes
- KaTeX is optional at the package level and used by the Vue entry point.
