Skip to content

Repository files navigation

PaperPal

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.


Screenshots

Landing Page

Landing Page

Format Selection

Format Selection

Upload Your Paper

Upload

Split-Pane Editor with Live Preview

Editor

PDF Download

Download PDF


Table of Contents


Why PaperPal?

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.


Supported Formats

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.


Two Pipelines

Standard Pipeline

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.

Pro Pipeline (PDF-to-LaTeX)

Upload a PDF research paper. The system:

  1. Extracts content β€” text, images, tables, and equations using unpdf + pdfjs-dist
  2. Analyzes structure with AI β€” sends extracted text to an LLM to identify title, authors, abstract, sections, references, and metadata as structured JSON
  3. 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)
  4. 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.


Architecture

                               β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                               β”‚     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 β”‚
    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Key Design Decisions

  • 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/convert and /api/pro/extract routes 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.


Tech Stack

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

Getting Started

Prerequisites

Installation

git clone https://github.com/davesohamm/PaperPal_Hack.git
cd PaperPal_Hack
npm install

Environment Variables

cp .env.example .env.local

Edit .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-here

HuggingFace token setup:

  1. Go to huggingface.co/settings/tokens
  2. Create a Fine-grained token
  3. Check "Make calls to Inference Providers"
  4. 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:

  1. Create a free cluster at mongodb.com/atlas
  2. Add a database user with read/write access
  3. Whitelist your IP (or 0.0.0.0/0 for dev)
  4. Copy the connection string, replace <db_password>, append /paperpal

Running Locally

# 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 dev

Open http://localhost:3000.

For production build:

npm run build
npm start

How It Works

Standard Pipeline

  1. Pick a format β€” Choose from 10 citation styles on the formats page
  2. Upload your document β€” Drag and drop a .docx, .txt, or .tex file
  3. AI conversion β€” Text is chunked and sent to HuggingFace LLMs via SSE streaming with real-time progress
  4. LaTeX assembly β€” Preamble is generated first, body chunks are converted, references are formatted by code (not LLM)
  5. Preview and download β€” Split-pane editor with raw LaTeX on the left, rendered preview on the right

Pro Pipeline (PDF input)

  1. Upload PDF at /pro/upload β€” select target format, upload your source PDF
  2. PDF parsing β€” unpdf + pdfjs-dist extracts text per page, detects images (with pixel data), tables (heuristic column alignment), and equations (regex pattern matching)
  3. AI structure extraction β€” Extracted text is sent to the LLM to produce a compact structured JSON: title, authors, abstract, keywords, sections, references, metadata
  4. Section enrichment β€” The LLM's compact summaries are enriched with full text from the original extraction by matching section headings back to the source
  5. 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
  6. Compilation β€” LaTeX is sent to TeXLive.net's free API, which returns a compiled PDF
  7. Editor β€” Split view with editable LaTeX code, PDF preview, download buttons for both .tex and .pdf

Project Structure

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

Deployment

Vercel (Recommended)

  1. Push to GitHub
  2. Import the repository on vercel.com
  3. Add environment variables in Project Settings β†’ Environment Variables:
    • HF_TOKEN_1 through HF_TOKEN_5
    • MONGODB_URI
    • JWT_SECRET
  4. 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.


Roadmap

  • 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

Team

Built during a hackathon by a team of 5.


License

This project is for academic and educational use. See LICENSE for details.

About

HackMINEd submission

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages