βββ ββββββββ βββββββ ββββββββββββ βββ ββββββββββββββββ ββββββββββββ βββ ββββββ βββ βββββββ βββ βββ ββββββ βββ ββββββ βββ ββββββββββββββββββββββββββββ βββ ββββββββββββββββ βββββββ βββ βββ
Transform markdown into beautiful PDFs with multiple templates
This repository contains a powerful document conversion system that automatically transforms markdown files into professionally formatted PDF documents using multiple customizable templates. The system integrates with GitHub Actions to provide continuous delivery of beautifully formatted scientific papers, academic documents, and technical reports οΏ½οΏ½οΏ½ all from a single markdown source.
The only bug bounty program where YOU pay US
| π Find Bug | π³ Pay $5/month | β‘ Get Priority Fix |
Why? Because nothing motivates faster bug fixes like paying customers who found the bugs themselves.
Legit makes it easy to write content once in markdown format and automatically generate multiple professionally formatted PDFs using different templates. With a single markdown source, you can produce documents that follow traditional scientific paper styling, academic formatting, or custom templates of your own design. The system:
- Watches for changes to markdown files in your repository
- Converts them to PDF using Pandoc and LaTeX with scientific and academic formatting
- Uploads the generated PDFs to your S3 bucket
- Maintains both versioned copies and "latest" references
- Supports both portrait and landscape images with proper formatting
π― The core power of Legit: Transform a single markdown file into 5 professional PDF formats, each optimized for different academic and professional contexts.
See our format showcase document that demonstrates the dramatic differences between templates. From one markdown source, Legit generates:
- Scientific Format (2-column, 73KB): Traditional journal-style layout with tight spacing, perfect for conference papers and research articles
- Academic Format (single-column, 150KB): Clean, readable layout ideal for dissertations, theses, and detailed technical reports
- Technical Report Format (135KB): Corporate styling with professional branding, perfect for R&D reports and consulting documents
- Preprint Format (128KB): Optimized for online reading on arXiv, bioRxiv, and other preprint servers
- Thesis Format (130KB): Formal university formatting with comprehensive front matter for PhD dissertations
| Feature | Scientific | Academic | Technical Report | Preprint | Thesis |
|---|---|---|---|---|---|
| Layout | 2-column | Single-column | Single + sidebar | Single-column | Chapter-based |
| Page Size | 73KB | 150KB | 135KB | 128KB | 130KB |
| Target | Journals | Papers | Corporate | Online | Universities |
| Spacing | Compact 1.1x | Standard 1.5x | Standard 1.5x | Relaxed 1.4x | Double spacing |
| Styling | Minimal | Traditional | Corporate branding | Clean/minimal | Formal academic |
| Colors | Black/white | Black/white | Blue/gray theme | Blue accents | Traditional |
| Headers | Simple | Detailed | Corporate style | Minimal | Chapter-based |
| Best For | Conference papers | Academic papers | R&D reports | Research sharing | Dissertations |
Our showcase paper demonstrates:
- Complex mathematical equations with proper LaTeX rendering
- Syntax-highlighted Python code showing neural network architectures
- Professional scientific content with abstracts, citations, and references
- Identical markdown source producing distinctly different PDF outputs
All formats support the same advanced features:
- Mathematical equations with full LaTeX support and physics notation
- Syntax-highlighted code blocks with professional formatting
- Tables, figures, and cross-references with automatic numbering
- Citation management and bibliographies with multiple styles
- Professional styling optimized for each format's target audience
- Cross-platform compatibility with consistent rendering
The repository is organized into a modular structure for better maintainability:
legit/
βββ .github/workflows/ # GitHub Actions workflow files
βββ configs/ # Configuration files for the workflow
β βββ workflow-config.yml # Main configuration settings
βββ content/ # Markdown papers to be converted
β βββ example-paper.md # Example scientific paper template
β βββ demo-paper.md # Climate science ML demo paper
β βββ format-showcase.md # Comprehensive format showcase document
βββ figures/ # Image files for papers
β βββ portrait images # Images in portrait orientation
β βββ landscape images # Images in landscape orientation
βββ scripts/ # Utility scripts for the workflow
β βββ convert-markdown.sh # Markdown to PDF conversion script
β βββ generate-all-formats.sh # Generate PDFs in all available formats
βββ templates/ # LaTeX templates for styling
β βββ scientific-paper.tex # Scientific paper LaTeX template (2-column)
β βββ academic-paper.tex # Academic paper LaTeX template (single-column)
β βββ technical-report.tex # Technical report LaTeX template (corporate)
β βββ preprint.tex # Preprint LaTeX template (online-optimized)
β βββ thesis.tex # Thesis LaTeX template (formal university)
βββ README.md # This documentation file
To develop and test the PDF generation locally, you'll need to install several dependencies. This section provides installation instructions for different operating systems.
- Pandoc: Document conversion system that transforms markdown to LaTeX/PDF
- LaTeX: Typesetting system required for PDF generation
- Additional LaTeX packages: For scientific formatting, math equations, and images
- Inkscape (or alternative): For converting SVG images to PDF format for LaTeX inclusion
- Git: Version control for repository management
-
Pandoc:
brew install pandoc
-
LaTeX:
# Full installation (>4GB) brew install --cask mactex # OR Minimal installation (~100MB) brew install --cask basictex # If using BasicTeX, you'll need to install additional packages: sudo tlmgr update --self sudo tlmgr install collection-latex collection-fontsrecommended collection-pictures collection-bibtexextra sudo tlmgr install latexmk fncychap titlesec tabulary varwidth framed wrapfig capt-of needspace xcolor
-
Inkscape and Additional Tools:
brew install inkscape librsvg python imagemagick
-
Pandoc:
sudo apt update sudo apt install pandoc
-
LaTeX:
# Full installation (>4GB) sudo apt install texlive-full # OR Minimal installation (~500MB) sudo apt install texlive texlive-latex-extra texlive-fonts-recommended texlive-science
-
Inkscape and Additional Tools:
sudo apt install inkscape librsvg2-bin python3 imagemagick
-
Pandoc:
- Download the installer from pandoc.org/installing.html
- Run the installer and follow the prompts
-
LaTeX (MiKTeX):
- Download from miktex.org/download
- Run the installer
- During setup, choose to automatically install required packages
-
Additional Tools:
- Install Git for Windows
- Install Python
- Install Inkscape for SVG to PDF conversion
- Optionally install ImageMagick
Once dependencies are installed, you can test the conversion process:
-
Clone the repository:
git clone git@github.com:TinkerTanked/legit.git cd legit -
Make the conversion script executable (Unix-based systems):
chmod +x scripts/convert-markdown.sh
-
Run a test conversion on the showcase paper:
# Generate all 5 formats at once (recommended) ./scripts/generate-all-formats.sh content/format-showcase.md # Or generate individual formats ./scripts/convert-markdown.sh --format=scientific --input=content/format-showcase.md ./scripts/convert-markdown.sh --format=academic --input=content/format-showcase.md ./scripts/convert-markdown.sh --format=technical-report --input=content/format-showcase.md ./scripts/convert-markdown.sh --format=preprint --input=content/format-showcase.md ./scripts/convert-markdown.sh --format=thesis --input=content/format-showcase.md
On Windows (using Git Bash or WSL):
# Generate all 5 formats at once (recommended) bash scripts/generate-all-formats.sh content/format-showcase.md # Or generate individual formats bash scripts/convert-markdown.sh --format=scientific --input=content/format-showcase.md bash scripts/convert-markdown.sh --format=academic --input=content/format-showcase.md bash scripts/convert-markdown.sh --format=technical-report --input=content/format-showcase.md bash scripts/convert-markdown.sh --format=preprint --input=content/format-showcase.md bash scripts/convert-markdown.sh --format=thesis --input=content/format-showcase.md
-
Verify the PDF was generated in the
pdfsdirectory
-
Missing LaTeX packages:
- Error messages will indicate missing packages
- On macOS/Linux:
sudo tlmgr install <package-name> - On Windows with MiKTeX: The package manager should install them automatically
-
Pandoc conversion errors:
- Ensure your markdown syntax is compatible with Pandoc
- Check LaTeX template for compatibility issues
- Run pandoc with the
--verboseflag for detailed error messages
-
Image conversion issues:
- Ensure images are in supported formats (PNG, JPEG, SVG)
- For SVG support, ensure that librsvg is installed
- Verify file paths are correct relative to the markdown file
-
SVG conversion issues:
- For proper SVG handling, Inkscape is the preferred tool
- If Inkscape is not available, the system will fall back to librsvg2-bin (rsvg-convert)
- SVG files with complex elements (gradients, filters, etc.) may require Inkscape for proper conversion
- If you see LaTeX errors with
\endcsnamerelated to images, check that your SVG files are being properly converted to PDF - You can manually pre-convert SVG files to PDF with:
inkscape --export-filename=output.pdf input.svg
-
Line ending issues:
- Scripts may fail with "bad interpreter" errors on Unix systems if they have Windows line endings
- Fix with:
tr -d '\r' < scripts/convert-markdown.sh > scripts/fixed.sh && mv scripts/fixed.sh scripts/convert-markdown.sh && chmod +x scripts/convert-markdown.sh
The GitHub workflow (markdown-to-pdf.yml) performs the following steps:
- Trigger: Activates when markdown files are pushed to the main branch or when manually triggered
- Configuration Loading: Reads settings from
configs/workflow-config.yml - Environment Setup: Uses a Docker container with pre-installed Pandoc, LaTeX, and other required dependencies to speed up execution time
- Template Application: Applies the appropriate LaTeX template (scientific or academic) from the templates directory
- PDF Generation: Converts the markdown to properly formatted PDFs in all configured formats using Pandoc
- S3 Upload: Securely uploads the PDFs to your configured S3 bucket
- Versioning: Creates both timestamped versions and a "latest" version for easy reference
The generated PDFs include proper formatting for:
- Title, authors, and affiliations
- Abstract
- Section headings and numbering
- Mathematical equations
- Tables and figures with captions
- Citations and references
- Page numbers and headers
- Both portrait and landscape images with proper orientation
- Custom styling through configurable templates
You need to configure the following secrets in your GitHub repository:
AWS_ACCESS_KEY_ID: Your AWS access key with S3 permissionsAWS_SECRET_ACCESS_KEY: Your AWS secret keyAWS_REGION: The AWS region where your S3 bucket is located (e.g.,us-east-1)S3_BUCKET: The name of your S3 bucket where PDFs will be stored
Your S3 bucket should be configured with:
- Appropriate permissions for the AWS credentials used
- Public read access if you want the PDFs to be publicly accessible
- CORS configuration if needed for web access
Example bucket policy for public read access (optional):
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": "*",
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::YOUR-BUCKET-NAME/*"
}
]
}- Place your markdown files in the
content/directory - Create your scientific paper with YAML frontmatter, for example:
---
title: "Your Paper Title"
author: "Author Name"
date: "2023-09-22"
abstract: "This is the abstract of your paper."
keywords: ["keyword1", "keyword2"]
bibliography: references.bib
---
## Introduction
Your content here...See the content/example-paper.md file in this repository for a complete example with advanced features like equations, tables, and citations.
You can also specify which format you prefer in the YAML frontmatter:
---
title: "Your Paper Title"
author: "Author Name"
date: "2023-09-22"
abstract: "This is the abstract of your paper."
format: "academic" # or "scientific"
---- Place your images in the
figures/directory - Reference images in your markdown with proper paths:
{width=80%}
{width=100% orientation=landscape}- Portrait images: Standard image inclusion, no special attributes needed
- Landscape images: Add the
orientation=landscapeattribute to properly rotate the image
Example:
{width=100% orientation=landscape}You can customize the workflow by editing the configs/workflow-config.yml file:
# Main configuration controls which files to process
input:
content_dir: "content" # Directory containing markdown files
default_files: ["example-paper.md"] # Default files to process if none specified
# Output settings
output:
pdf_dir: "pdfs" # Directory for generated PDFs
s3:
prefix: "papers" # S3 prefix/folder for uploaded PDFs
make_public: true # Whether to make PDFs publicly accessible
# Template settings
templates:
dir: "templates" # Directory containing LaTeX templates
scientific: "scientific-paper.tex" # Scientific paper template file
academic: "academic-paper.tex" # Academic paper template file
# Format settings - enable/disable specific formats
formats:
scientific: true # Enable scientific format generation
academic: true # Enable academic format generationThe workflow runs automatically when:
-
You push changes to the
mainbranch that include modifications to:- Markdown (
.md) files in thecontent/directory or its subdirectories - Any files in the
templates/directory (LaTeX templates) - Any files in the
configs/directory (workflow configuration files)
- Markdown (
-
You manually trigger the workflow from the GitHub Actions tab
Note that changes to other files (such as scripts, images, or documentation) will NOT automatically trigger the workflow. This is controlled by the paths configuration in the GitHub workflow file.
To manually trigger the workflow:
- Go to the "Actions" tab in your GitHub repository
- Select the "Markdown to PDF" workflow
- Click "Run workflow"
- Optionally specify a particular markdown file to process
- Click the "Run workflow" button
When manually triggering the workflow, you can also choose to regenerate all markdown files in the content directory by selecting the "Regenerate all markdown files" option.
Once the workflow completes successfully, your PDFs will be available at:
Scientific Format:
- Latest version:
https://YOUR-BUCKET-NAME.s3.amazonaws.com/papers/scientific/FILENAME-latest.pdf - Versioned:
https://YOUR-BUCKET-NAME.s3.amazonaws.com/papers/scientific/FILENAME-TIMESTAMP.pdf
Academic Format:
- Latest version:
https://YOUR-BUCKET-NAME.s3.amazonaws.com/papers/academic/FILENAME-latest.pdf - Versioned:
https://YOUR-BUCKET-NAME.s3.amazonaws.com/papers/academic/FILENAME-TIMESTAMP.pdf
An index of all available PDFs is also generated and available at:
https://YOUR-BUCKET-NAME.s3.amazonaws.com/papers/index.html
To customize the PDF formatting:
- Modify the LaTeX templates:
- For scientific format:
templates/scientific-paper.tex - For academic format:
templates/academic-paper.tex
- For scientific format:
- Adjust Pandoc options in
scripts/convert-markdown.shorconfigs/workflow-config.yml - For advanced users, create custom templates with different styling options
The LaTeX template supports customization of:
- Font styles and sizes
- Margin settings
- Header and footer styles
- Citation styles
- Figure and table formatting
You can control image appearance with markdown attributes:
{width=70% height=auto}
{width=100% orientation=landscape}
{width=30% .right}Supported attributes:
widthandheight: Control image dimensions (percentage or absolute)orientation: Set tolandscapefor landscape images.left,.right,.center: Control image alignment
SVG images require special handling when included in LaTeX documents. The workflow supports several methods:
- Automatic conversion: SVG files are automatically converted to PDF during the workflow
- Manual conversion: You can pre-convert SVG files to PDF using Inkscape
- Fallback conversion: If Inkscape is not available, the system uses librsvg2-bin (rsvg-convert)
Common parameters for SVG conversion:
# Using Inkscape (best quality)
inkscape --export-filename=output.pdf input.svg
# Using rsvg-convert (fallback)
rsvg-convert -f pdf -o output.pdf input.svgWhen referencing SVG images in markdown, use the SVG filename - the conversion will happen automatically:
{width=80%}The workflow:
- Uses cached LaTeX and Pandoc installations when possible
- Installs only required LaTeX packages for faster setup
- Provides detailed logs for debugging
- Uses a modular script architecture for maintainability
To ensure fast and efficient workflow execution:
- Docker Container: The workflow uses a pre-built Docker container with Pandoc, LaTeX, and all required dependencies already installed, eliminating installation time
- Dependency Caching: When not using containers, the workflow caches dependencies to speed up subsequent runs
- Optimized LaTeX Installation: Only installs the specific packages needed rather than the full distribution
- Parallel Processing: Where possible, operations are parallelized for faster execution
The conversion process:
- Parses the YAML frontmatter from markdown files
- Applies the appropriate LaTeX template
- Processes figures with proper orientation handling
- Compiles citations if a bibliography is provided
- Generates a clean, professionally formatted PDF
If the workflow fails:
- Check the GitHub Actions logs for specific error messages
- Ensure your AWS credentials are correct and have appropriate permissions
- Verify your markdown syntax is compatible with Pandoc
- Check that your LaTeX equations are properly formatted
- Validate image paths and ensure images exist in the figures directory
- Check the configuration file for correct settings
Legit includes a comprehensive test suite to ensure the system works correctly. The test suite validates:
- Markdown to PDF conversion
- SVG image handling
- Multi-format template processing
- Command-line functionality
To run the test suite locally:
# Run all tests
./tests/run-tests.shTests run automatically on every pull request and push to the main branch via GitHub Actions.
For detailed information about the testing system, see TESTING.md.
Legit provides a Docker container for consistent development and testing environments, especially useful for ARM64 architectures.
A helper script is provided to build and run the Docker container:
# Build and run the container
./build-and-run.sh --run
# Just build the container
./build-and-run.sh
# Show all options
./build-and-run.sh --helpYou can push the built image to Amazon ECR for use in CI/CD pipelines:
./build-and-run.sh --push --aws-region=us-east-1 --aws-account=123456789012 --ecr-repo=legitThe repository includes a GitHub workflow that automatically builds and pushes the ARM64 container to ECR on:
- Pushes to the main branch that modify the Dockerfile
- Manual triggers using the "Actions" tab in GitHub
- Weekly builds every Sunday
To use this workflow, configure the following GitHub secrets:
AWS_ACCESS_KEY_IDAWS_SECRET_ACCESS_KEYAWS_REGIONAWS_ACCOUNT_ID
You can specify which format to use for your document in several ways:
-
In the YAML frontmatter:
--- title: "Document Title" format: "academic" # or "scientific" template: "custom-template.tex" # optional, overrides default for the format ---
-
Command line when running scripts:
./scripts/convert-markdown.sh --input=content/paper.md --format=academic
-
Create additional custom templates:
- Add new template files to the
templates/directory - Reference them directly:
- Add new template files to the
---
title: "Document Title"
template: "alternative-template.tex"
---
---For proper citations:
- Create a BibTeX file (e.g.,
references.bib) with your citations - Reference it in your markdown frontmatter
- Cite in the paper using
[@citation-key]format
This project is licensed under the MIT License - see the LICENSE file for details.
Found a bug? Congratulations! You just earned yourself a subscription.
Most projects pay you for finding bugs. We've flipped the script. When you discover a bug in Legit, you get the exclusive privilege of joining our Reverse Bounty Club for just $5/month.
- Quality Assurance Premium: You're investing in the reliability of your own workflow
- Bug Hunter's Badge: Wear it with pride - you found something we missed
- Exclusive Access: Members get priority support and early access to new features
- Skin in the Game: Nothing motivates faster bug fixes like paying customers who found the bugs themselves
- Reverse Psychology: The fear of subscription prevents casual "this doesn't work" reports (detailed reproductions only, please)
- Discover a legitimate bug (not user error, not feature requests)
- Submit a detailed issue with reproduction steps, environment details, and expected vs actual behavior
- Get verified by our team (we're picky about what counts as a "bug")
- Join the club with your $5/month subscription via https://checkout.tinkertank.rocks/b/aFa6oHbMj64B7LueMKbQY1Q
- Watch us fix it with the urgency that only comes from paying customers
β Counts as a bug:
- PDF generation fails with valid markdown
- Template formatting breaks with specific content
- Docker container crashes on supported platforms
- Security vulnerabilities (get free lifetime membership)
β Doesn't count:
- "This should work differently" (that's a feature request)
- User environment issues (install LaTeX properly)
- "It's slow" without performance benchmarks
- Markdown syntax errors causing failures
- Subscription auto-renews monthly until you cancel
- One subscription per person, regardless of bugs found
- Bug must be reproducible and verified by core team
- We reserve the right to reject frivolous bug reports
- Subscription includes: priority support, beta access, eternal bragging rights
Pro tip: The best way to avoid the subscription? Help us write better tests. Pull requests that prevent bugs are always free and welcomed with gratitude.
"If you're not paying for the product, you are the product. If you found a bug and now you're paying for the product... well, you're still kind of the product, but at least you're a premium product."
Contributions to improve Legit are welcome! Please feel free to submit pull requests with:
- Template improvements
- Additional features
- Documentation enhancements
- Bug fixes (but remember the subscription rule above π)