Skip to main content

Wrap LaTeX table fragments into complete documents for research workflows

Project description

tabwrap

PyPI version Python License: MIT

Wrap LaTeX table fragments into complete documents for research workflows

A Python tool that transforms statistical programming output (LaTeX table fragments) into publication-ready PDFs and PNGs. Perfect for researchers who need to quickly inspect, share, and explore tables from Stata, R, Python, and other statistical tools.

What it does

tabwrap takes incomplete LaTeX table fragments like this:

\begin{tabular}{lcr}
\toprule
Variable & Coefficient & P-value \\
\midrule
Intercept & 1.23 & 0.045 \\
\bottomrule
\end{tabular}

And automatically wraps them into complete, compilable LaTeX documents with:

  • Auto-detected packages (booktabs, tabularx, siunitx, etc.)
  • Proper document structure and preambles
  • Smart table resizing to fit pages
  • Multi-file batch processing with error recovery
  • Combined PDFs with table of contents
  • PNG output with automatic cropping
  • Landscape orientation and custom formatting
  • Enhanced error reporting with suggestions

Quick Start

Prerequisites

LaTeX Distribution Required: tabwrap needs a LaTeX installation to compile documents.

  • Windows: MiKTeX or TeX Live
  • macOS: MacTeX or brew install --cask mactex
  • Linux: sudo apt-get install texlive-full or equivalent

Optional for PNG output: ImageMagick

Installation

Recommended (CLI tools):

pipx install tabwrap

Standard Python installation:

pip install tabwrap

With API support:

pip install tabwrap[api]

Basic Usage

# Compile a single table
tabwrap regression_table.tex

# Process all tables in a folder
tabwrap ./results_tables/

# Output PNG with landscape orientation  
tabwrap table.tex -p --landscape

# Batch process with combined PDF
tabwrap ./tables/ -r -c    # recursive + combine PDFs

# Show filename headers and keep intermediate files
tabwrap data/ --header --keep-tex

Features

Enhanced Error Handling

⚠️  1 of 3 files failed to compile:

📋 Failed files:
   • bad_table.tex
     Invalid tabular content: No tabular environment found

✅ Successfully compiled: table1.tex, table2.tex

Smart Package Detection

Automatically detects and includes required packages:

  • booktabs for \toprule, \midrule, \bottomrule
  • tabularx for \begin{tabularx}
  • siunitx for \SI{}{}, \num{}
  • multirow for \multirow
  • And many more...

Flexible Output Options

# Output formats
tabwrap table.tex                     # PDF output (default)
tabwrap table.tex -p                  # PNG output with auto-cropping
tabwrap table.tex --svg               # SVG output (vector graphics)

# Batch processing  
tabwrap folder/ -r                    # Process subdirectories recursively
tabwrap folder/ -j                    # Parallel processing (4-6x faster)
tabwrap folder/ -c                    # Combine into single PDF with TOC

# Layout and formatting
tabwrap table.tex --landscape         # Landscape orientation
tabwrap table.tex --no-resize         # Disable auto-resizing
tabwrap table.tex --header            # Show filename as header

Shell Completion

tabwrap supports shell completion for bash, zsh, and fish:

# Bash - add to ~/.bashrc
tabwrap --completion bash >> ~/.bashrc

# Zsh - add to ~/.zshrc  
tabwrap --completion zsh >> ~/.zshrc

# Fish - save to completions directory
tabwrap --completion fish > ~/.config/fish/completions/tabwrap.fish

CLI Reference

Usage: tabwrap [OPTIONS] [INPUT_PATH]

Arguments:
  INPUT_PATH               .tex file or directory to process [default: current directory]

Output Options:
  -o, --output PATH        Output directory [default: current directory]
  --suffix TEXT            Output filename suffix [default: _compiled]
  -p, --png                Output PNG instead of PDF
  --svg                    Output SVG instead of PDF

Processing Options:
  -r, --recursive          Process subdirectories recursively
  -j, --parallel           Process files in parallel for faster batch compilation
  --max-workers INTEGER    Maximum number of parallel workers [default: CPU cores]
  -c, --combine            Combine multiple PDFs with table of contents

Formatting Options:
  --landscape              Use landscape orientation
  --no-resize              Disable automatic table resizing
  --header                 Show filename as header in output
  --packages TEXT          Comma-separated LaTeX packages (auto-detected if empty)

Advanced Options:
  --keep-tex               Keep generated LaTeX files and compilation logs for debugging
  --completion [bash|zsh|fish]  Generate shell completion script
  --help                   Show this message and exit

Common Usage Patterns

# Basic compilation
tabwrap table.tex                     # PDF output
tabwrap table.tex -p                  # PNG output
tabwrap table.tex --svg               # SVG output

# Batch processing
tabwrap folder/                       # All .tex files in folder
tabwrap folder/ -r                    # Include subdirectories
tabwrap folder/ -j                    # Parallel processing (faster)
tabwrap folder/ -c                    # Combined PDF with TOC

# Formatting options
tabwrap table.tex --landscape         # Landscape orientation
tabwrap table.tex --no-resize         # No auto-resizing
tabwrap table.tex --header            # Show filename header

# Output control
tabwrap table.tex -o output/          # Custom output directory
tabwrap table.tex --suffix _final     # Custom filename suffix

API Usage

For programmatic access:

from tabwrap import TabWrap

compiler = TabWrap()
result = compiler.compile_tex(
    input_path="table.tex",
    output_dir="output/",
    png=True,
    landscape=True
)
print(f"Compiled to: {result}")

Research Workflow Integration

Stata

esttab using "regression_results.tex", replace booktabs
! tabwrap regression_results.tex -p

R

library(xtable)
xtable(model) %>% 
  print(file = "model_table.tex", include.rownames = FALSE)
system("tabwrap model_table.tex --landscape")

Python

df.to_latex("data_summary.tex", index=False)
os.system("tabwrap data_summary.tex -p")

Development

Contributing

  1. Fork the repository
  2. Create a feature branch: git checkout -b feature-name
  3. Make changes and add tests
  4. Run tests: poetry run pytest
  5. Submit a pull request

Development Setup

git clone https://github.com/janfasnacht/tabwrap.git
cd tabwrap
poetry install
poetry run pytest  # Run tests

Building and Testing

poetry build                    # Build distribution packages
poetry run tabwrap --help      # Test CLI
make test                       # Run full test suite
make test-coverage              # Generate coverage report

License

MIT License - see LICENSE file for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tabwrap-1.0.0.tar.gz (20.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

tabwrap-1.0.0-py3-none-any.whl (23.7 kB view details)

Uploaded Python 3

File details

Details for the file tabwrap-1.0.0.tar.gz.

File metadata

  • Download URL: tabwrap-1.0.0.tar.gz
  • Upload date:
  • Size: 20.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.2.1 CPython/3.12.11 Linux/6.11.0-1018-azure

File hashes

Hashes for tabwrap-1.0.0.tar.gz
Algorithm Hash digest
SHA256 d527d9de45142f65cead429e404869cd6a0e447af4d8f6ee289a11afec9fdeaf
MD5 0d032d3047f5f3e0219533553e05b11a
BLAKE2b-256 04efe50ef1b45825863b516c0d599b27f5f8589b0fea2a9f023aaf5b47ff5b5a

See more details on using hashes here.

File details

Details for the file tabwrap-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: tabwrap-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 23.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.2.1 CPython/3.12.11 Linux/6.11.0-1018-azure

File hashes

Hashes for tabwrap-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8fb5488319322815a7d5197121862c6a7438d8eb57835d1a932df18f06d7c1b2
MD5 dae07003ee67bb944b98193179b52b10
BLAKE2b-256 19fa2ad1e230991384c09e61c6d6924fe9273322f85f1d16bcc0759f956d24f5

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page