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.




