Instant academic paper formatting — powered by LLMs and rule-based LaTeX generation.
Upload a research paper, pick a citation style, and get a publication-ready LaTeX PDF. Two pipelines: a fast LLM-driven converter for .docx/.txt/.tex files, and a Pro pipeline that parses PDFs with layout-aware extraction and generates LaTeX through pure rule-based code — zero hallucination.
- Why PaperPal?
- Supported Formats
- Two Pipelines
- Architecture
- Tech Stack
- Getting Started
- How It Works
- Project Structure
- Deployment
- Roadmap
- Team
Every researcher has been there — the paper is done, the content is solid, but reformatting for APA, IEEE, or Vancouver eats hours. Adjusting margins, citation styles, heading levels, and reference lists manually is tedious work that has nothing to do with actual research.
PaperPal automates this entirely. Drop in your document, select a format, and the system produces LaTeX output that follows the exact typographic and structural rules of your chosen style. The generated PDF is ready to submit.
| Format | Full Name | Typical Fields |
|---|---|---|
| APA | American Psychological Association (7th ed.) | Psychology, Education, Social Sciences |
| MLA | Modern Language Association (9th ed.) | Humanities, Literature, Arts |
| Chicago | Chicago Manual of Style (Notes & Bibliography) | History, Publishing, General Academic |
| Harvard | Harvard Referencing | Business, Social Sciences, General Use |
| IEEE | IEEE Conference / Journal | Engineering, Computer Science, Electronics |
| AMA | American Medical Association | Medicine, Health, Biological Sciences |
| Vancouver | Vancouver (ICMJE) | Biomedical Journals, Clinical Research |
| ACS | American Chemical Society | Chemistry, Biochemistry, Materials Science |
| CSE | Council of Science Editors | Biology, Earth Sciences, Natural Sciences |
| Custom | User-Defined | Any — define your own rules |
Each format has a dedicated master prompt describing the exact visual and structural expectations — fonts, spacing, heading hierarchy, citation mechanics, reference list formatting.
Upload .docx, .txt, or .tex files. The LLM converts your content into LaTeX for the selected format via Server-Sent Events with real-time progress tracking.
Upload a PDF research paper. The system:
- Extracts content — text, images, tables, and equations using
unpdf+pdfjs-dist - Analyzes structure with AI — sends extracted text to an LLM to identify title, authors, abstract, sections, references, and metadata as structured JSON
- Generates LaTeX with rules — passes the structured JSON to one of 9 format-specific rule-based LaTeX generators (pure TypeScript, zero LLM calls, zero hallucination)
- Compiles to PDF — sends the LaTeX to TeXLive.net's free API and returns a compiled PDF
The Pro pipeline is completely isolated from the standard pipeline — separate routes, separate pages, separate code.
┌───────────────────────────┐
│ Next.js Frontend │
│ (React 19 + SSR) │
└─────────────┬─────────────┘
│
┌────────────────────────────┼────────────────────────────┐
│ STANDARD │ PRO │
▼ │ ▼ │
┌───────────────────┐ │ ┌─────────────────┐ │
│ /api/parse │ │ │ /api/pro/parse │ │
│ Mammoth (.docx) │ │ │ unpdf (PDF) │ │
│ + .txt / .tex │ │ │ Images + Tables │ │
└────────┬──────────┘ │ │ + Equations │ │
│ │ └────────┬────────┘ │
▼ │ ▼ │
┌───────────────────┐ │ ┌─────────────────┐ │
│ /api/convert │ │ │ /api/pro/extract │ │
│ SSE streaming │ │ │ LLM → JSON │ │
│ LLM → LaTeX │ │ │ (Edge, SSE) │ │
│ (Edge runtime) │ │ └────────┬────────┘ │
└────────┬──────────┘ │ ▼ │
│ │ ┌─────────────────┐ │
│ │ │ Rule-Based │ │
│ │ │ LaTeX Generators │ │
│ │ │ (9 formats, TS) │ │
│ │ └────────┬────────┘ │
│ │ ▼ │
│ │ ┌─────────────────┐ │
│ │ │ /api/pro/compile │ │
│ │ │ TeXLive.net API │ │
│ │ │ LaTeX → PDF │ │
│ │ └────────┬────────┘ │
▼ │ ▼ │
┌──────────────────────────────────────────────────────────────────┐
│ Browser Preview + PDF Download │
└──────────────────────────────────────────────────────────────────┘
┌───────────────┐ ┌──────────────────────────────────┐
│ Token Pool │ │ HuggingFace Inference API │
│ 5 HF tokens │───▶│ Qwen 72B → Llama 70B → Mixtral │
│ Round-robin │ │ → Qwen Coder 32B → Gemma 2B │
└───────────────┘ └──────────────────────────────────┘
┌───────────────┐ ┌───────────────┐
│ MongoDB Atlas │ │ JWT + bcrypt │
│ User accounts │ │ httpOnly auth │
└───────────────┘ └───────────────┘
-
Token round-robin — 5 HuggingFace API tokens rotate to avoid per-token rate limits. Rate-limited (429) or unavailable (503) tokens automatically cycle to the next.
-
Model fallback chain — Qwen 72B → Llama 3.3 70B → Qwen Coder 32B → Mixtral 8x7B → Gemma 2 2B. Best quality is tried first, with automatic fallback.
-
Rule-based LaTeX generation (Pro) — Each of the 9 citation formats has a dedicated TypeScript generator (150–340 lines each) encoding the exact formatting rules. No LLM is involved in LaTeX code generation — eliminating hallucinated citations, duplicate content, and formatting errors.
-
Code-based references — References and bibliography entries are parsed and formatted programmatically in both pipelines.
-
Anti-hallucination guards — Strict grounding rules are injected into every LLM prompt. The LLM reformats existing content without inventing text, fake authors, or placeholder references.
-
Edge runtime for streaming — The
/api/convertand/api/pro/extractroutes use the Vercel Edge runtime, enabling SSE streaming without the 10-second Node.js timeout limit. -
JSON repair — The Pro pipeline includes a
repairTruncatedJSON()function that can fix common LLM output issues (unclosed strings, unbalanced braces) and a full fallback parser for when JSON parsing fails entirely.
| Layer | Technology |
|---|---|
| Framework | Next.js 15 (App Router, React 19) |
| Language | TypeScript 5.7 |
| Styling | Tailwind CSS 4 |
| Animations | Framer Motion |
| Icons | Lucide React |
| Document Parsing | Mammoth (DOCX), unpdf (PDF) |
| PDF Content Extraction | unpdf + pdfjs-dist (text, images, tables, equations) |
| LLM Inference | HuggingFace Inference API |
| LaTeX Compilation | TeXLive.net (free, no API key) |
| Database | MongoDB Atlas via Mongoose |
| Auth | JWT + bcryptjs |
| Deployment | Vercel |
- Node.js >= 18.x (download)
- npm >= 9.x (comes with Node)
- HuggingFace API tokens — free tier works (create tokens here)
- MongoDB Atlas cluster — free tier works (create one here)
git clone https://github.com/davesohamm/PaperPal_Hack.git
cd PaperPal_Hack
npm installcp .env.example .env.localEdit .env.local:
# HuggingFace tokens (1-5, more = fewer rate limits)
HF_TOKEN_1=hf_your_first_token
HF_TOKEN_2=hf_your_second_token
HF_TOKEN_3=hf_your_third_token
HF_TOKEN_4=hf_your_fourth_token
HF_TOKEN_5=hf_your_fifth_token
# MongoDB connection string
MONGODB_URI=mongodb+srv://user:password@cluster.mongodb.net/paperpal
# JWT secret (any random string, 32+ characters)
JWT_SECRET=your-secret-key-hereHuggingFace token setup:
- Go to huggingface.co/settings/tokens
- Create a Fine-grained token
- Check "Make calls to Inference Providers"
- Copy and paste into
.env.local
The system works with as few as 1 token, but rate limits will be hit more often.
MongoDB Atlas setup:
- Create a free cluster at mongodb.com/atlas
- Add a database user with read/write access
- Whitelist your IP (or
0.0.0.0/0for dev) - Copy the connection string, replace
<db_password>, append/paperpal
# On Windows, increase memory for large builds:
$env:NODE_OPTIONS="--max-old-space-size=4096"; npm run dev
# On macOS/Linux:
NODE_OPTIONS="--max-old-space-size=4096" npm run devOpen http://localhost:3000.
For production build:
npm run build
npm start- Pick a format — Choose from 10 citation styles on the formats page
- Upload your document — Drag and drop a
.docx,.txt, or.texfile - AI conversion — Text is chunked and sent to HuggingFace LLMs via SSE streaming with real-time progress
- LaTeX assembly — Preamble is generated first, body chunks are converted, references are formatted by code (not LLM)
- Preview and download — Split-pane editor with raw LaTeX on the left, rendered preview on the right
- Upload PDF at
/pro/upload— select target format, upload your source PDF - PDF parsing —
unpdf+pdfjs-distextracts text per page, detects images (with pixel data), tables (heuristic column alignment), and equations (regex pattern matching) - AI structure extraction — Extracted text is sent to the LLM to produce a compact structured JSON: title, authors, abstract, keywords, sections, references, metadata
- Section enrichment — The LLM's compact summaries are enriched with full text from the original extraction by matching section headings back to the source
- Rule-based LaTeX generation — The appropriate format generator (e.g.,
ieee.ts,apa.ts) converts the structured features into complete, compilable LaTeX — no LLM involved - Compilation — LaTeX is sent to TeXLive.net's free API, which returns a compiled PDF
- Editor — Split view with editable LaTeX code, PDF preview, download buttons for both
.texand.pdf
PaperPal_Hack/
├── public/
│ └── favicon.svg
├── images/ # Demo screenshots
├── src/
│ ├── app/
│ │ ├── api/
│ │ │ ├── auth/ # Authentication routes
│ │ │ │ ├── route.ts # Unified auth endpoint
│ │ │ │ ├── signin/route.ts # Sign in
│ │ │ │ ├── signup/route.ts # Sign up
│ │ │ │ ├── me/route.ts # Token verification
│ │ │ │ └── logout/route.ts # Cookie clear
│ │ │ ├── parse/route.ts # Document parsing (Mammoth)
│ │ │ ├── convert/route.ts # LLM LaTeX generation (Edge, SSE)
│ │ │ └── pro/ # Pro pipeline API
│ │ │ ├── parse/route.ts # PDF extraction (Node runtime)
│ │ │ ├── extract/route.ts # LLM feature extraction (Edge, SSE)
│ │ │ └── compile/route.ts # LaTeX → PDF via TeXLive.net (Edge)
│ │ ├── auth/page.tsx # Sign in / Sign up
│ │ ├── formats/page.tsx # Format selection grid
│ │ ├── upload/page.tsx # File upload (standard)
│ │ ├── custom-format/page.tsx # Custom format builder
│ │ ├── editor/page.tsx # LaTeX editor + preview (standard)
│ │ ├── pro/
│ │ │ ├── upload/page.tsx # PDF upload + format selection (Pro)
│ │ │ └── editor/page.tsx # LaTeX editor + compiled PDF (Pro)
│ │ ├── page.tsx # Landing page
│ │ ├── layout.tsx # Root layout + AuthProvider
│ │ └── globals.css # Global styles
│ ├── components/
│ │ ├── Navbar.tsx # Navigation with Pro badge + user menu
│ │ ├── GlowCard.tsx # Animated card component
│ │ ├── PageTransition.tsx # Route transition wrapper
│ │ └── TextReveal.tsx # Animated text reveal
│ ├── context/
│ │ └── AuthContext.tsx # Auth state + JWT management
│ └── lib/
│ ├── constants.ts # Format definitions + UI config
│ ├── db.ts # MongoDB connection (lazy init)
│ ├── jwt.ts # JWT sign/verify helpers
│ ├── models.ts # LLM model configs + format prompts
│ ├── token-pool.ts # HF token rotation + fallback
│ ├── user.ts # User schema + bcrypt
│ └── pro/ # Pro pipeline library
│ ├── types.ts # Shared interfaces
│ ├── pdf-extractor.ts # PDF → text/images/tables/equations
│ ├── llm-prompts.ts # Structured extraction prompts
│ └── latex-generators/ # Rule-based LaTeX generators
│ ├── base.ts # Shared utilities (escapeTeX, tables, figures, equations)
│ ├── index.ts # Generator registry
│ ├── apa.ts # APA 7th Edition
│ ├── mla.ts # MLA 9th Edition
│ ├── ieee.ts # IEEE Conference
│ ├── chicago.ts # Chicago Manual of Style
│ ├── harvard.ts # Harvard Referencing
│ ├── ama.ts # AMA
│ ├── vancouver.ts # Vancouver
│ ├── acs.ts # ACS
│ └── cse.ts # CSE
├── .env.example # Environment variable template
├── .gitignore
├── next.config.ts
├── package.json
├── tsconfig.json
└── README.md
- Push to GitHub
- Import the repository on vercel.com
- Add environment variables in Project Settings → Environment Variables:
HF_TOKEN_1throughHF_TOKEN_5MONGODB_URIJWT_SECRET
- Deploy — Vercel handles the build automatically
The Edge runtime routes (/api/convert, /api/pro/extract, /api/pro/compile) bypass Vercel's 10-second Node.js timeout, enabling long-running SSE streams.
- Multi-model LLM pipeline with round-robin token distribution
- 10 citation formats (APA, MLA, Chicago, Harvard, IEEE, AMA, Vancouver, ACS, CSE, Custom)
- Format-specific master prompts for accurate LaTeX generation
- Real-time SSE progress tracking
- Anti-hallucination grounding rules
- Code-based reference formatting (no LLM for bibliography)
- Split-pane LaTeX editor with live preview
- MongoDB + JWT authentication with bcrypt
- Pro pipeline: PDF input with layout-aware extraction
- Rule-based LaTeX generators (9 formats, zero LLM hallucination)
- TeXLive.net integration for server-side PDF compilation
- PDF image, table, and equation extraction
- Section enrichment from full extracted text
- Truncated JSON repair + fallback parser
- Vercel deployment with Edge runtime for streaming
- Batch conversion (multiple papers)
- Custom format builder UI
- Full image embedding in compiled PDFs
- Export to Overleaf with one click
Built during a hackathon by a team of 5.
This project is for academic and educational use. See LICENSE for details.




