tex_document 0.1.0
tex_document: ^0.1.0 copied to clipboard
A Flutter package for rendering TeX documents as native widgets. Supports academic papers with math, figures, tables, citations, and bibliography.
tex_document #
A Flutter package for rendering TeX documents as native widgets. Designed for academic papers with support for math equations, figures, tables, citations, and bibliography.
Features #
- TeX Parsing: Recursive descent parser with macro expansion and
\inputresolution - Math Rendering: Inline and display math via flutter_math_fork
- Document Elements: Sections, paragraphs, figures, tables, lists, footnotes
- Academic Features: Citations, cross-references, bibliography, theorem environments
- PDF Figures: Runtime PDF-to-image rendering via pdfrx
Installation #
Add to your pubspec.yaml:
dependencies:
tex_document: ^0.1.0
Quick Start #
import 'package:tex_document/tex_document.dart';
// Parse TeX source
final parser = TexParser((filename) => null);
final document = parser.parse(r'''
\title{My Document}
\author{Author Name}
\begin{abstract}
This is the abstract.
\end{abstract}
\section{Introduction}
Hello, this is inline math: $E = mc^2$.
''');
// Render as widgets
DocumentRenderer(
document: document,
assetBasePath: 'assets/',
)
Multi-file Documents #
For documents with \input{} commands:
// Load all input files into a map
final files = {
'intro.tex': await loadFile('intro.tex'),
'methods.tex': await loadFile('methods.tex'),
};
// Parser resolves \input{} via callback
final parser = TexParser((name) => files[name]);
final document = parser.parse(mainTexSource);
Bibliography Support #
For BibTeX-style bibliographies:
final parser = TexParser(
(name) => files[name],
bblFiles: ['references.bbl'], // List of .bbl files
);
Customizing Typography #
Use TexTextTheme to customize fonts and sizes:
DocumentRenderer(
document: document,
textTheme: TexTextTheme(
body: TextStyle(fontFamily: 'Georgia', fontSize: 16, height: 1.7),
title: TextStyle(fontFamily: 'Georgia', fontSize: 28, fontWeight: FontWeight.bold),
// ... other styles
),
)
Supported TeX Elements #
Block Elements #
- Sections:
\section,\subsection,\subsubsection,\paragraph - Math:
\begin{equation},\begin{align},\[...\],$$...$$ - Figures:
\begin{figure}with\includegraphics - Tables:
\begin{table}with\begin{tabular} - Lists:
\begin{itemize},\begin{enumerate} - Theorems:
theorem,lemma,proposition,corollary,definition,remark,proof - Algorithms:
\begin{algorithm}with\begin{algorithmic}
Inline Elements #
- Math:
$...$,\(...\) - Formatting:
\textbf,\textit,\emph - Citations:
\cite,\citep,\citet - References:
\ref,\eqref - Footnotes:
\footnote - URLs:
\url
Preprocessing #
- Comments:
%line comments stripped - Macros:
\newcommandwith arguments - Includes:
\input{file}resolution - Bibliography:
\bibliography{file}→.bblloading
PDF Figure Support #
PDF figures are rendered at runtime using PDFium. Initialize in your app:
import 'package:pdfrx/pdfrx.dart';
void main() {
WidgetsFlutterBinding.ensureInitialized();
pdfrxFlutterInitialize();
runApp(MyApp());
}
Example #
See the example directory for a complete demo app that renders academic papers including "Attention Is All You Need", "Neural Tangent Kernel", and "Auto-Encoding Variational Bayes".
cd example
flutter run
Limitations #
- No equation numbering
- Complex TeX (TikZ, custom environments) may not parse
- Some LaTeX packages not supported
License #
MIT License - see LICENSE for details.