"The docs are done when the docs are done."
DonDocs is a browser-based naval correspondence and form generator that produces publication-quality documents compliant with SECNAV M-5216.5 (Department of the Navy Correspondence Manual) and MCO 5216.20B (Marine Corps Supplement).
All processing happens locally in your browser - no data is ever sent to any server.
- Key Features
- Getting Started
- Features
- Document Types
- Compliance Mode
- Security & Classification
- User Interface
- Keyboard Shortcuts
- Technology Stack
- Form Templates
- Development
- License
- LaTeX-based PDF generation via WebAssembly - pixel-perfect formatting impossible with typical web tools
- Professional typesetting that matches official military publications
- Consistent spacing, margins, and font handling per SECNAV specifications
- 3,139 military units with full addresses, MCC codes, and organizational data
- 2,240 SSIC codes from SECNAV M-5210.2 (August 2018)
- 107 regulatory references across 12 categories (MCO, SECNAVINST, NAVADMIN)
- 74 office codes (S-1, G-3, CO, XO, etc.) for signature blocks
- 50+ military ranks (USMC and Navy, all grades E1-O10 plus Warrant Officers)
- 100% client-side processing - nothing leaves your browser
- PII/PHI detection warns before download (SSN, EDIPI, DOB, medical info)
- Digital signature fields compatible with CAC/PIV cards and Adobe Acrobat
- Classification markings from Unclassified through TOP SECRET//SCI
- CUI handling with 10 categories and distribution statements
- Portion markings per-paragraph: (U), (CUI), (FOUO), (C), (S), (TS)
- NIST 800-171 compliant - works on air-gapped networks (SIPR/JWICS)
- 20 document types across letters, endorsements, memoranda, agreements, and executive formats
- Dynamic form adaptation — the editor automatically shows/hides and reconfigures sections based on document type (e.g., dual-command fields for MOA/MOU, executive memo layouts, business letter salutations)
- 11 pre-built templates for common correspondence (awards, appointments, investigations, personnel)
- Distribution lists and Copy To support per SECNAV Ch 8
- Continuation subject line toggle for page 2+ headers
- Custom classification markings for non-standard banners
- PDF - Full-featured with enclosures, signatures, and classification markings
- DOCX - Editable Microsoft Word format
- LaTeX - Source files for advanced customization
- Open the application in your browser
- Set up your letterhead and addressing
- Fill in required fields (From, To, Subject)
- Add paragraphs to the body
- Preview your document in real-time
- Download as PDF, DOCX, or LaTeX
- Click Profiles to create your unit profile
- Enter your unit information, rank, name, and signature image
- Save the profile for quick reuse
- Your information auto-fills on future documents
- Real-time PDF Preview - See your document as you type (1.5s debounce)
- 20 Document Types - All selectable from the document type dropdown with full SECNAV M-5216.5 compliance
- Dynamic UI Sections - Form panels adapt per document type: sections gray out with "Not used by this document type" indicators when inapplicable, and specialized panels appear for dual-command formats (MOA/MOU, Joint, Executive)
- SECNAV M-5216.5 Compliant - Automatic formatting per Navy/Marine Corps regulations
- PDF/DOCX Parity - Both export formats produce matching layouts with identical SECNAV-standard spacing
- PWA/Offline Mode - Install as an app and work offline with cached TeX Live packages
- Compliant vs Custom Modes - Strict regulation mode or customizable fonts and formatting (see Compliance Mode for details)
- Full Quality Preview - Optional toggle to include enclosures, hyperlinks, and signatures in the live preview (Settings > Preview)
- Profiles System - Save and reuse unit information and signature images
- Template Library - 11 auditor-approved letter templates for common correspondence
- Clear Fields - Reset all content while preserving letterhead for quick new document creation
- Reference Library - 107 searchable military references with one-click insert
- Unit Directory - 3,139 units searchable by name, abbreviation, MCC, or location
- Office Codes - 74 standard military position codes for signature blocks
- SSIC Lookup - 2,240 codes searchable by number or description
- Batch Generation - Generate multiple documents with 28 built-in placeholders and Insert Variable button
- Find & Replace - Search and replace text across your document
- Undo/Redo - 50-level history with keyboard shortcuts
- Document Statistics - Real-time word count, character count, paragraph count
- PII/PHI Detection - Pre-download warning for sensitive data:
- Social Security Numbers (SSN)
- DoD ID Numbers (EDIPI)
- Dates of Birth
- Phone numbers
- Personal email addresses
- 95+ medical/PHI keywords
- Digital Signature Fields - CAC/PIV compatible signature boxes in PDF
- Classification Markings - Unclassified through TOP SECRET//SCI
- CUI Handling - 10 categories with distribution statements (A-F)
- Portion Markings - Per-paragraph classification indicators
- Hierarchical Paragraphs - 8 levels with automatic labeling (1., a., (1), (a), etc.)
- References - Auto-lettered with optional hyperlinks
- Enclosures - PDF attachments with cover pages and 3 page styles
- Copy To - Distribution list for information recipients
- Distribution - Action addressee list per SECNAV Ch 8
- Continuation Subject - Optional subject line on page 2+ headers
- Signature Images - Upload and embed your signature
- Drag & Drop - Reorder paragraphs, references, and enclosures
- Welcome Modal - Interactive onboarding with feature highlights and rotating tips
- Browser Compatibility Detection - Warns users in in-app browsers (Google, Facebook, Instagram, Twitter, LinkedIn) about limited functionality
- Mobile Responsive - Hamburger menu, touch-friendly controls, full-screen preview on mobile
- Installable PWA - Add to home screen for native app-like experience
Generate multiple personalized documents from a single template using the Insert Variable button or {{PLACEHOLDER}} syntax.
28 Built-in Placeholders across 6 categories:
| Category | Placeholders |
|---|---|
| Subject | NAME, LAST_NAME, FIRST_NAME, MI, RANK, RANK_NAME, EDIPI, MOS, BILLET |
| 2nd Person | NAME_2, RANK_2, RANK_NAME_2, BILLET_2 |
| 3rd Person | NAME_3, RANK_3, RANK_NAME_3, BILLET_3 |
| Dates | DATE, EVENT_DATE, START_DATE, END_DATE, TIME |
| Contact | EMAIL, PHONE, ADDRESS, UNIT, LOCATION |
| Document | SERIAL, CASE_NUM, AMOUNT, REASON, AWARD, COURSE, CHARGE |
Use Cases for S-1/Admin:
- Awards packages (NAME, RANK, AWARD, REASON)
- Counseling/disciplinary (NAME, CHARGE, EVENT_DATE, NAME_2 for witness)
- Training requests (NAME, COURSE, START_DATE, END_DATE)
- Mass notifications (NAME, RANK_NAME, EMAIL, UNIT)
- Multi-party documents (subject, witness, reviewing officer)
Preview Support: Placeholders display as highlighted yellow boxes in the PDF preview so you can see where variables will be inserted.
Excel/CSV Import: Upload a spreadsheet with columns matching placeholder names to generate documents for each row.
| Category | Types |
|---|---|
| Letters | Naval Letter, Standard Letter, Business Letter, Multiple Address Letter, Joint Letter |
| Endorsements | Same-Page Endorsement, New-Page Endorsement |
| Memoranda | MFR, Memorandum For, Plain Paper, Letterhead, Decision, Executive, Joint Memorandum |
| Agreements | MOA, MOU |
| Executive | Executive Correspondence, Standard Memorandum, Action Memorandum, Information Memorandum |
All 20 types are selectable in the document type dropdown with full SECNAV M-5216.5 compliance.
| Template | Category |
|---|---|
| PFT Waiver | Personnel |
| Humanitarian Transfer | Personnel |
| NAM Award | Awards |
| Letter of Appreciation | Awards |
| Command Interest | Leadership |
| Appointment: Collateral Duty | Administrative |
| Appointment: Board Member | Administrative |
| Appointment: Safety Officer | Administrative |
| Report of Findings | Investigations |
| Appointment: Investigating Officer | Investigations |
| Letter of Instruction | Operations |
DonDocs offers two modes for each document type:
Enforces strict SECNAV M-5216.5 formatting rules. Certain features are locked or restricted based on the document type to ensure regulation compliance.
Unlocks all features for non-official use, drafting, or situations where deviation from regulations is acceptable. Custom mode allows:
- Any font size (10pt, 11pt, 12pt, 14pt)
- Any font family (Times, Courier)
- Flexible formatting options
| Document Type | Numbered Paragraphs | References Section | Enclosures Section | Salutation | Complimentary Close | Date Format |
|---|---|---|---|---|---|---|
| Naval Letter | Yes | Yes | Yes | No | No | Military (4 Jan 26) |
| Standard Letter | Yes | Yes | Yes | No | No | Military |
| Business Letter | No | No* | No* | Required | Required | Spelled (January 4, 2026) |
| Multiple Address Letter | Yes | Yes | Yes | No | No | Military |
| Joint Letter | Yes | Yes | Yes | No | No | Military |
| Endorsements | No | Yes | Yes | No | No | Military |
| All Memoranda | Yes | Yes | Yes | No | No | Military |
| MOA/MOU | Yes | Yes | Yes | No | No | Military |
| Executive Correspondence | Yes | Yes | Yes | No | No | Military |
| Standard Memorandum | No | No | No | No | No | Spelled |
| Action Memorandum | No | No | No | No | No | Spelled |
| Information Memorandum | No | No | No | No | No | Spelled |
*Business Letters: References and enclosures must be mentioned in the body text rather than in formal sections (per SECNAV M-5216.5 Ch 11).
| Restriction | Description |
|---|---|
| Numbered Paragraphs | When enabled, paragraphs use hierarchical numbering (1., a., (1), (a), etc.). When disabled, paragraphs have no numbering. |
| References Section | When enabled, formal "Ref:" section appears. When disabled, references can only be mentioned in body text. |
| Enclosures Section | When enabled, formal "Encl:" section with attachments. When disabled, enclosures mentioned in body only. |
| Salutation | When required, document must include "Dear Mr./Ms./Dr.:" line per business letter format. |
| Complimentary Close | When required, document must include "Sincerely," or similar closing per business letter format. |
| Date Format | Military format "4 Jan 26" vs spelled format "January 4, 2026". |
The following document types require two signature blocks (one for each command/party):
- Joint Letter
- Joint Memorandum
- Memorandum of Agreement (MOA)
- Memorandum of Understanding (MOU)
Per SECNAV M-5216.5, dual-command documents position the Junior command on the LEFT (signs first) and the Senior command on the RIGHT (signs last). This convention applies consistently to both the ID symbols block (SSIC/Serial/Date) and the signature block in both PDF and DOCX output.
| Level | Description |
|---|---|
| Unclassified | No classification |
| CUI | Controlled Unclassified Information |
| CONFIDENTIAL | Could cause damage |
| SECRET | Could cause serious damage |
| TOP SECRET | Could cause grave damage |
| TOP SECRET//SCI | Sensitive Compartmented Information |
| Custom | User-defined classification banner text |
Privacy, Proprietary, Legal, Law Enforcement, Export Control, Financial, Intelligence, Critical Infrastructure, Defense, Other
Apply per-paragraph markings: (U), (CUI), (FOUO), (C), (S), (TS)
Before downloading, DonDocs scans for:
- Social Security Numbers (XXX-XX-XXXX)
- EDIPI/DoD ID Numbers (10-digit)
- Dates of Birth
- Phone numbers
- Personal email addresses (non-.mil)
- Medical keywords (patient, diagnosis, treatment, medication, etc.)
You'll receive a warning with the option to proceed or cancel.
PDF output includes empty signature fields compatible with:
- CAC (Common Access Card)
- PIV (Personal Identity Verification) cards
- Adobe Acrobat digital signatures
- Third-party PKI solutions
| Button | Function | Shortcut |
|---|---|---|
| Refresh | Force recompile preview | - |
| Save | Save/Load from browser storage | Ctrl+S |
| Download | PDF, DOCX, LaTeX export | Ctrl+D |
| Templates | Load pre-built templates | Ctrl+Shift+T |
| Batch | Generate multiple documents | - |
| Find & Replace | Search and replace text | Ctrl+H |
| Keyboard | View all shortcuts | - |
| Density | Compact / Comfortable / Spacious | - |
| Color | Default / Navy / USMC schemes | - |
| Theme | Toggle dark/light mode | - |
| Full Quality | Include enclosures/hyperlinks/signatures in preview | - |
- Profile Bar - Quick profile selector with unit lookup
- Mode Toggle - Switch between Compliant (strict SECNAV) and Custom (flexible) modes (see Compliance Mode)
- Document Type - Select from 20 document types; the entire form dynamically reconfigures per selection. Clear Fields resets content while preserving letterhead
- Letterhead - Unit name, address, seal type; shows "Not used" indicator for types without letterhead (e.g., MFR, Plain Paper)
- Addressing - From, To, Via, Subject, SSIC, Serial, Date — fields auto-show/hide per doc type (e.g., business letters show recipient address block instead of From/To, executive formats skip SSIC)
- Dual-Command Sections - MOA/MOU show Junior/Senior SSIC and signature fields; Joint Letter/Memo show dual From/To/Via
- Classification - Security markings, CUI settings, and custom classification text
- Paragraphs - Document body with 8-level hierarchy
- References - Auto-lettered with hyperlink support; grayed out with indicator for doc types that don't use formal references
- Enclosures - PDF attachments with cover pages; grayed out with indicator for doc types that don't use formal enclosures
- Copy To - Information distribution list
- Distribution - Action addressee list per SECNAV Ch 8
- Signature - Signatory information and image; dual signature blocks for MOA/MOU/Joint formats
- Document Statistics - Word/character/paragraph counts
- Real-time PDF preview
- Loading indicator during compilation
- Error messages for troubleshooting
- 3 Density Modes - Compact (power users), Comfortable (default), Spacious (touch/accessibility)
- 3 Color Schemes - Default (neutral), Navy (blue tones), USMC (red/gold accents)
- Dark/Light Mode - System-aware with manual toggle
- Persistent Preferences - Settings saved to browser localStorage
- Responsive header with hamburger menu
- Compact button layouts for small screens
- Full-screen preview modal on mobile devices
- Touch-friendly controls and spacing
| Shortcut | Action |
|---|---|
Ctrl+D / Cmd+D |
Download PDF |
Ctrl+P / Cmd+P |
Print PDF |
Ctrl+S / Cmd+S |
Save Draft |
Ctrl+H / Cmd+H |
Find & Replace |
Ctrl+E / Cmd+E |
Toggle Preview |
Ctrl+Shift+T |
Open Templates |
Ctrl+Shift+R |
Open Reference Library |
Ctrl+Z / Cmd+Z |
Undo |
Ctrl+Y / Cmd+Y |
Redo |
Escape |
Close Modals |
- React 19 with TypeScript
- Zustand 5 for state management
- Tailwind CSS 4 with shadcn/ui components
- dnd-kit for drag and drop
- Vite 7 for build tooling
- SwiftLaTeX - WebAssembly LaTeX compiler for publication-quality PDFs
- Pandoc WASM - In-browser LaTeX-to-DOCX conversion via WebAssembly (~58MB, cached by service worker)
- pdf-lib - PDF manipulation (enclosures, signatures, metadata)
- JSZip - DOCX post-processing (table widths, fonts, letterhead colors)
- react-pdf-viewer - In-browser PDF preview
- date-fns - Military date formatting (4 Jan 26)
- TipTap - Rich text editing
- react-day-picker - Date selection
- vite-plugin-pwa - Service worker for offline support
- Workbox - Intelligent caching for TeX Live packages
This application supports official military forms (NAVMC 10274, NAVMC 118(11), etc.) by overlaying text onto official PDF templates.
All form templates must be obtained from official sources:
- DoD Forms Management Program: https://forms.documentservices.dla.mil
- Navy Forms Online: https://www.mynavyhr.navy.mil/References/Forms/
⚠️ Important: Do not create new form templates from scratch. Only official, pre-approved forms should be used to ensure compliance with regulations.
Official military PDF forms are typically encoded using XFA (XML Forms Architecture), an Adobe technology for dynamic forms. XFA forms have special characteristics:
- They contain embedded XML data structures
- They support dynamic form features (calculations, validations)
- They are not compatible with most PDF libraries (including pdf-lib)
Before using a form template, it must be "flattened":
- What is flattening? Converting dynamic XFA form elements into static PDF content (text, lines, rectangles)
- Why flatten? pdf-lib and most JavaScript PDF libraries cannot read or modify XFA content
- How to flatten?
- Adobe Acrobat Pro: Print to PDF or use "Flatten Form Fields"
- Online tools: Various PDF flattening services (ensure no sensitive data)
- Command line:
pdftk input.pdf output output.pdf flatten
-
Obtain the official form from https://forms.documentservices.dla.mil
-
Flatten the PDF to remove XFA encoding:
pdftk official_form.pdf output flattened_form.pdf flatten
-
Extract box boundaries using the provided script:
pip install pdfplumber python scripts/extract-pdf-boxes.py public/templates/your_form.pdf --save-image
-
Review the annotated image to verify detected boxes
-
Create a generator in
src/services/pdf/using the smart box positioning system:import { calculateTextPosition, type BoxBoundary } from './extractFormFields'; const BOX_PADDING = { left: 3, top: 3 }; const PAGE_BOXES: Record<string, BoxBoundary> = { fieldName: { name: 'fieldName', left: 100, top: 500, width: 200, height: 30 }, // ... boxes from extract script }; function getFieldPosition(boxName: keyof typeof PAGE_BOXES) { return calculateTextPosition(PAGE_BOXES[boxName], BOX_PADDING, FONT_SIZE); }
The easiest way to define box coordinates is with the visual editor:
# Open in browser
open tools/box-editor.html- Load your PDF template
- Click "Draw Mode" and drag to create boxes
- Name each box (e.g.,
name,edipi,remarks) - Copy the TypeScript code or export as JSON
This is a one-time setup per form template.
The scripts/extract-pdf-boxes.py script can auto-detect boxes, but works best for forms with clear rectangles:
# Basic usage - auto-detect boxes
python scripts/extract-pdf-boxes.py template.pdf
# Save annotated image showing detected boxes
python scripts/extract-pdf-boxes.py template.pdf --save-image
# Adjust detection sensitivity
python scripts/extract-pdf-boxes.py template.pdf --min-size 5 --max-size 300
# Interactive mode for manual box definition
python scripts/extract-pdf-boxes.py template.pdf --interactive
# Save detected boxes as JSON config for manual editing
python scripts/extract-pdf-boxes.py template.pdf --save-config
# Load boxes from a JSON config file
python scripts/extract-pdf-boxes.py --config public/templates/NAVMC118.boxes.jsonOutput includes:
- Visual ASCII map of detected boxes
- JSON data with coordinates
- TypeScript code ready to paste into generators
For forms where auto-detection doesn't work well (forms drawn with lines instead of rectangles), use a JSON config file:
{
"template": "NAVMC118_template.pdf",
"description": "NAVMC 118(11) Administrative Remarks",
"pageSize": { "width": 612, "height": 792 },
"boxes": {
"name": {
"left": 148,
"top": 142,
"width": 206,
"height": 16,
"description": "Marine's name (LAST, FIRST MI)"
},
"edipi": {
"left": 465,
"top": 142,
"width": 106,
"height": 16,
"description": "DOD ID Number / EDIPI"
}
}
}Existing configs:
public/templates/NAVMC118.boxes.json- NAVMC 118(11) Administrative Remarkspublic/templates/NAVMC10274.boxes.json- NAVMC 10274 Administrative Action
Workflow for new forms:
- Run auto-detection:
python scripts/extract-pdf-boxes.py template.pdf --save-config - Edit the generated
template.boxes.jsonto fix field names and coordinates - Verify with:
python scripts/extract-pdf-boxes.py --config template.boxes.json - Copy the TypeScript output into your generator file
Understanding PDF coordinates is essential for accurate form filling:
- Origin: Bottom-left corner of the page (0, 0)
- X-axis: Increases to the right
- Y-axis: Increases upward
- Units: Points (72 points = 1 inch)
- Letter size: 612 × 792 points
(0, 792) -------- (612, 792) ← Top of page
| |
| |
| |
(0, 0) ---------- (612, 0) ← Bottom of page
- Node.js 18+
- npm or yarn
npm installnpm run devnpm run builddondocs/
├── tex/ # LaTeX format templates (advanced)
│ ├── main.tex # Main template
│ └── templates/ # Document format templates (naval_letter, mfr, etc.)
├── public/
│ ├── attachments/ # Seal images
│ └── lib/
│ ├── PdfTeXEngine.js # LaTeX engine
│ ├── latex-templates.js # Bundled LaTeX templates for SwiftLaTeX
│ ├── texlive/ # TeX Live files
│ └── pandoc/ # Pandoc WASM files for DOCX generation
│ ├── pandoc.js # WASM module loader
│ ├── pandoc.wasm # Pandoc binary (~58MB, cached by SW)
│ ├── dondocs.lua # Four-pass Lua filter for DOCX formatting
│ └── reference.docx # DOCX template with base styles
├── src/
│ ├── components/
│ │ ├── editor/ # Form components
│ │ ├── layout/ # Page layout
│ │ ├── modals/ # Modal dialogs
│ │ └── ui/ # shadcn/ui components
│ ├── data/
│ │ ├── templates/ # Content templates (TypeScript) - add new templates here
│ │ ├── units/ # Unit directory
│ │ ├── ssic/ # SSIC codes
│ │ └── references/ # Reference library
│ ├── hooks/ # Custom React hooks
│ ├── lib/ # Utility libraries
│ ├── services/
│ │ ├── docx/ # DOCX generation (pandoc WASM pipeline)
│ │ │ ├── pandoc-converter.ts # Pandoc WASM conversion + OOXML post-processing
│ │ │ └── layout-config.ts # Shared layout proportions (letterhead, columns)
│ │ ├── latex/ # LaTeX generation
│ │ │ ├── generator.ts # PDF LaTeX generator (multi-file, SwiftLaTeX)
│ │ │ ├── flat-generator.ts # DOCX flat LaTeX generator (single-file, pandoc)
│ │ │ └── escaper.ts # LaTeX character escaping utilities
│ │ ├── pdf/ # PDF processing
│ │ └── pii/ # PII detection
│ ├── stores/ # Zustand stores
│ └── types/ # TypeScript types
├── index.html # Entry point
├── package.json # Dependencies
├── vite.config.ts # Vite config
└── Makefile # Build commands
The application generates PDFs through a multi-stage pipeline from UI input to final PDF output:
┌─────────────────┐ ┌──────────────────┐ ┌─────────────────┐ ┌─────────────────┐
│ React UI │ --> │ Zustand Store │ --> │ Generator │ --> │ SwiftLaTeX │
│ (Components) │ │ (documentStore)│ │ (generator.ts) │ │ (WebAssembly) │
└─────────────────┘ └──────────────────┘ └─────────────────┘ └─────────────────┘
│ │
v v
┌─────────────────┐ ┌─────────────────┐
│ .tex Files │ --> │ Raw PDF │
│ (Virtual FS) │ │ │
└─────────────────┘ └─────────────────┘
│
v
┌─────────────────┐
│ Post-Process │
│ (pdf-lib) │
└─────────────────┘
│
v
┌─────────────────┐
│ Final PDF │
│ (with encl, │
│ hyperlinks, │
│ signatures) │
└─────────────────┘
1. React UI → Zustand Store
- User inputs data through form components in
src/components/editor/ - Data is stored in
documentStore(Zustand) with fields likeformData,paragraphs,references, etc.
2. Zustand Store → Generator
src/services/latex/generator.tsreads from the store- Generates multiple
.texfiles:document.tex- Document type, SSIC, date, from/to, subjectletterhead.tex- Unit name, address, seal configurationclassification.tex- CUI/classification markingssignatory.tex- Signature block informationreferences.tex- Reference listreference-urls.tex- Reference URL mappings for hyperlinksencl-config.tex- Enclosure list configurationcopyto-config.tex- Copy To list (information recipients)distribution-config.tex- Distribution list (action addressees)body.tex- Document body paragraphsflags.tex- Boolean flags for conditional sections
3. Template System
There are two types of templates:
Content Templates (src/data/templates/) - TypeScript files defining pre-filled document content:
- Award recommendations, personnel requests, administrative forms, etc.
- Define subject lines, paragraphs, references, and SSIC codes
- No LaTeX knowledge required - see
docs/CREATING_TEMPLATES.md
Format Templates (LaTeX) - Define document layouts:
src/lib/latex-templates.jscontains all LaTeX templates as a JavaScript objecttex/main.tex- Main document structure, package imports, base commandstex/templates/*.tex- Document format templates (17 types: naval_letter, mfr, etc.)- Each format defines:
\printDateAndTitle- How date/SSIC block is formatted\printAddressBlock- How From/To/Via/Subject appears\printSignature- How signature block is rendered\printLetterhead- Whether/how letterhead appears
4. Virtual Filesystem → SwiftLaTeX
useLatexEngine.tshook manages the WebAssembly LaTeX engine- Templates are written to a virtual filesystem (stripping
tex/andtemplates/prefixes) - Generated
.texfiles are written to the virtual FS main.texloads the appropriate template via\input{\DocumentType}
5. Compilation
- SwiftLaTeX (WebAssembly) compiles
main.tex - Fetches missing TeX Live packages from
/lib/texlive/as needed - Returns compiled PDF as
Uint8Array
6. Post-Processing (pdf-lib)
src/services/pdf/handles PDF post-processing:- Merge enclosure PDFs with cover pages and page scaling
- Add clickable hyperlinks for references and enclosures
- Insert digital signature fields (CAC/PIV compatible)
- Apply classification markings to enclosure pages (main letter markings handled by LaTeX)
Key Files:
| File | Purpose |
|---|---|
src/App.tsx |
Main app component, debounced preview (1.5s LaTeX, 500ms forms) |
src/services/latex/generator.ts |
Generates .tex files from store data |
src/services/latex/escaper.ts |
Escapes special LaTeX characters, wraps text |
src/lib/latex-templates.js |
All LaTeX templates (main + 20 document types) |
src/hooks/useLatexEngine.ts |
Manages SwiftLaTeX WebAssembly engine |
src/services/pdf/mergeEnclosures.ts |
Merges enclosures, adds hyperlinks and markings |
src/services/pdf/addSignatureField.ts |
Adds CAC/PIV digital signature fields |
Debugging Tips:
- Check browser console for LaTeX compilation errors
- Use
DONDOCS.texlive.summary()in console to see TeX Live file requests - Template loading issues: Verify file paths in virtual filesystem
- Content issues: Check
escapeLatex()output for special characters
DOCX export uses a completely separate pipeline from the PDF path. Instead of the multi-file SwiftLaTeX approach, it generates a single flat LaTeX file and converts it to DOCX via pandoc WASM running entirely in the browser.
┌─────────────────┐ ┌──────────────────┐ ┌──────────────────┐ ┌─────────────────┐
│ React UI │ --> │ Zustand Store │ --> │ Flat Generator │ --> │ Pandoc WASM │
│ (Components) │ │ (documentStore)│ │ (flat-generator) │ │ (pandoc.js) │
└─────────────────┘ └──────────────────┘ └──────────────────┘ └─────────────────┘
│ │
v v
┌──────────────────┐ ┌─────────────────┐
│ Single .tex │ │ Lua Filter │
│ (pandoc-safe │ │ (dondocs.lua) │
│ LaTeX only) │ │ │
└──────────────────┘ └─────────────────┘
│
v
┌─────────────────┐
│ Post-Process │
│ (JSZip/OOXML) │
└─────────────────┘
│
v
┌─────────────────┐
│ Final DOCX │
│ (fonts, colors,│
│ page layout) │
└─────────────────┘
1. Zustand Store → Flat Generator
src/services/latex/flat-generator.tsreads the same store data as the PDF generator- Produces a single self-contained
.texfile with no\input{}calls or custom macros - Uses only pandoc-compatible LaTeX constructs:
tabularxfor centered/right-aligned layouts (pandoc ignores\begin{center})\mbox{}to protect numbered labels from pandoc's list detection\vspace{}for precise spacing (converted to OOXMLw:beforeby the Lua filter)\includegraphics{}for seal images
2. Pandoc WASM Conversion
src/services/docx/pandoc-converter.tslazy-loads pandoc 3.9+ as a WASM module (~58MB, cached by service worker)- Conversion runs entirely in-browser with
+raw_texextension enabled - Input files provided to pandoc: flat
.tex,reference.docx(template),dondocs.lua(filter), seal image - Layout metadata (column proportions) passed via pandoc
--metadata
3. Lua Filter (dondocs.lua)
The Lua filter (public/lib/pandoc/dondocs.lua) runs a four-pass architecture inside pandoc:
- Meta pass — reads layout metadata (column widths, seal proportions)
- Table pass — classifies tables by structure (letterhead, SSIC, address, dual-signature, centered title) and applies precise column widths
- RawBlock pass — converts LaTeX spacing commands (
\vspace,\medskip,\rule) into OOXML spacing paragraphs - RawInline pass — converts inline commands (
\mbox,\textbf,\underline,\textcolor,\fcolorbox) into native pandoc elements
4. OOXML Post-Processing (JSZip)
After pandoc produces the DOCX, pandoc-converter.ts opens it with JSZip and fixes known pandoc writer limitations:
- Zeros out table cell margins (pandoc adds ~0.08in padding by default)
- Rescales
gridColwidths from pandoc's hardcoded 7920 twips (5.5in) to our 9360 twips (6.5in) - Forces exact symmetric letterhead column widths and vertical centering
- Constrains empty spacer rows to 12pt height (pandoc ignores
\\[12pt]row spacing in tabular environments, so explicit empty rows are emitted by the flat generator and fixed to exact SECNAV-standard height here) - Removes unwanted empty paragraphs between tables
- Injects page geometry (US Letter, 1in margins) into
sectPr - Applies letterhead color (PMS 288 navy blue or black) and font sizes (10pt/8pt)
- Sets document-wide font family and size in
styles.xml
Key Files:
| File | Purpose |
|---|---|
src/services/latex/flat-generator.ts |
Generates pandoc-compatible flat LaTeX from store data |
src/services/docx/pandoc-converter.ts |
Pandoc WASM loading, conversion, and OOXML post-processing |
src/services/docx/layout-config.ts |
Shared layout proportions (used by both flat-generator and converter) |
public/lib/pandoc/pandoc.js |
Pandoc 3.9+ WASM module loader |
public/lib/pandoc/pandoc.wasm |
Pandoc WASM binary (~58MB) |
public/lib/pandoc/dondocs.lua |
Four-pass Lua filter for DOCX formatting |
public/lib/pandoc/reference.docx |
DOCX template with base styles |
Why Two LaTeX Generators?
The PDF and DOCX pipelines require fundamentally different LaTeX:
- PDF (
generator.ts) produces multiple.texfiles with custom macros,\input{}chains, and amain.texentry point — compiled by SwiftLaTeX into a pixel-perfect PDF - DOCX (
flat-generator.ts) produces a single flat file using only standard LaTeX that pandoc's reader can parse — no custom commands, no file includes, no format-specific macros
Both generators read from the same Zustand store and produce equivalent output, but through completely different LaTeX dialects.
DonDocs is designed for information security:
- Local Processing - All data stays in your browser
- No Server Communication - Documents never leave your device
- No Telemetry - No tracking or analytics
- Air-Gap Compatible - Works on isolated networks (SIPR/JWICS)
- CUI Support - Proper marking for Controlled Unclassified Information
- PWA Offline Mode - Install as an app; TeX Live packages cached locally for offline use
Note: Users are responsible for handling classified information according to their organization's security policies.
Q: Does this work on NMCI computers? A: Yes. It's a standard webpage that works in any modern browser. No installation required.
Q: Can I install this as an app? A: Yes. DonDocs is a Progressive Web App (PWA). Click "Install" in your browser or use "Add to Home Screen" on mobile. Once installed, it works offline.
Q: Does it work offline? A: Yes. After the first visit, the app caches all necessary files including the TeX Live packages. You can generate documents without an internet connection.
Q: Can I use this for classified correspondence? A: The tool formats documents but does not provide security controls for classified data. Use appropriate systems for classified information.
Q: Is my data saved anywhere? A: Everything runs in your browser. Nothing is transmitted to any server. Data can be saved to browser localStorage.
Q: Why LaTeX instead of jsPDF? A: LaTeX produces publication-quality output with proper kerning, ligatures, and typography that matches official military publications.
Q: Why does it warn me about my browser? A: If you're viewing in an in-app browser (Google App, Facebook, Instagram, etc.), some features like PDF downloads may not work. Open in Safari, Chrome, Firefox, or Edge for full functionality.
This project is licensed under the MIT License - see the LICENSE file for details.
Contributions welcome! Please open an issue or submit a pull request on the Marine Coders GitHub.
See CONTRIBUTING.md for detailed guidelines.
- Bug Reports - GitHub Issues
- Feature Requests - GitHub Issues
Built for Marines, by Marines. Semper Fidelis.