A LaTeX flattening utility for academic paper submission
Project description
flatexpy
A LaTeX flattening utility for academic paper submission that recursively processes \input and \include commands, copies referenced graphics, and produces a single consolidated LaTeX file.
Features
- Flattens LaTeX documents by recursively processing
\inputand\includecommands - Copies graphics files referenced by
\includegraphicsto the output directory - Supports
\graphicspathcommand for flexible graphics organization - Preserves document structure with clear include markers
- Handles circular dependencies gracefully
- Configurable graphics extensions (PDF, PNG, JPG, EPS, etc.)
- Comment handling with preservation options
- Cross-platform support (Windows, macOS, Linux)
- Type-safe with full type annotations
- Comprehensive testing with high coverage
Installation
From PyPI (Recommended)
pip install flatexpy
From conda-forge
conda install -c conda-forge flatexpy
From Source
git clone https://github.com/ToAmano/flatexpy.git
cd flatexpy
pip install -e .
Quick Start
Command Line Usage
# Basic usage
flatexpy input.tex
# Specify output directory
flatexpy input.tex -o output_directory/
# Overwrite existing output directory
flatexpy input.tex -o output_directory/ -f
# Verbose output
flatexpy input.tex -v
Python API Usage
from flatexpy.flatexpy_core import LatexExpander, LatexExpandConfig
import os
# Basic usage
os.makedirs("output")
expander = LatexExpander()
result = expander.flatten_latex("input.tex", "output/flattened.tex")
# Custom configuration
config = LatexExpandConfig(
graphic_extensions=[".png", ".jpg", ".pdf"],
ignore_commented_lines=True,
root_directory=".",
output_encoding="utf-8"
)
expander = LatexExpander(config)
result = expander.flatten_latex("input.tex", "output/flattened.tex")
Use Cases
Academic Paper Submission
Many academic journals require submission of a single LaTeX file. flatexpy helps by:
- Combining multiple files: Merges your modular LaTeX project into one file
- Including graphics: Copies all referenced images to the output directory
- Maintaining structure: Keeps track of original file organization with markers
Example Workflow
# Original project structure
paper/
├── main.tex
├── sections/
│ ├── introduction.tex
│ ├── methodology.tex
│ └── results.tex
├── figures/
│ ├── diagram1.pdf
│ └── plot1.png
└── bibliography.bib
# Flatten the document
flatexpy main.tex -o submission/
# Result
submission/
├── main_flattened.tex # Single file with all content
├── diagram1.pdf # Copied graphics
└── plot1.png
Configuration Options
Command Line Arguments
input_file: Input LaTeX file to flatten-o, --output: Output directory (default:flat/)--graphics-exts: Graphics file extensions to search for--ignore-comments: Ignore commented lines (default: True)-v, --verbose: Enable verbose logging
Python Configuration
from flatexpy.flatexpy_core import LatexExpandConfig
config = LatexExpandConfig(
graphic_extensions=[".pdf", ".png", ".jpg", ".jpeg", ".eps"],
ignore_commented_lines=True,
root_directory=".",
output_encoding="utf-8"
)
Advanced Features
Graphics Path Handling
flatexpy automatically processes \graphicspath commands:
\graphicspath{{figures/}{images/}}
\includegraphics{plot1} % Finds figures/plot1.png or images/plot1.png
Include Markers
The flattened output includes markers showing original file structure:
% >>> input{sections/introduction} >>>
\section{Introduction}
This is the introduction content.
% <<< input{sections/introduction} <<<
Circular Dependency Detection
flatexpy detects and handles circular includes gracefully, preventing infinite loops.
Development
Setting Up Development Environment
git clone https://github.com/ToAmano/flatexpy.git
cd flatexpy
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
pip install -e .[dev]
pre-commit install
Running Tests
# Run all tests
pytest
# Run with coverage
pytest --cov=flatexpy
# Run specific test file
pytest tests/test_integration.py
Code Quality
# Format code
black flatexpy tests
isort flatexpy tests
# Lint code
flake8 flatexpy tests
mypy flatexpy
# Run all quality checks
tox -e lint
Roadmap
- Feature for removing commented lines
- Support for standalone and import packages
- Support for bibtex
Contributing
We welcome contributions! Please see CONTRIBUTING.md for guidelines.
Types of Contributions
- Bug reports and fixes
- Feature requests and implementations
- Documentation improvements
- Test coverage improvements
License
This project is licensed under the MIT License - see the LICENSE file for details.
Changelog
See CHANGELOG.md for version history and changes.
Support
- Bug Reports: GitHub Issues
- Feature Requests: GitHub Discussions
- Documentation: GitHub README
Similar Projects
Examples
The following papers are submitted using the experimental version of this repository.
- T. Amano, T. Yamazaki, N. Matsumura, Y. Yoshimoto, S. Tsuneyuki, "Transferability of the chemical bond-based machine learning model for dipole moment: the GHz to THz dielectric properties of liquid propylene glycol and polypropylene glycol", Phys. Rev. B 111, 165149 (2025). [link][arXiv]
- T. Amano, T. Yamazaki, S. Tsuneyuki, "Chemical bond based machine learning model for dipole moment: Application to dielectric properties of liquid methanol and ethanol", Phys. Rev. B 110, 165159 (2024).[press] [link] [arXiv]
- T. Amano, T. Yamazaki, R. Akashi, T. Tadano, S. Tsuneyuki, "Lattice dielectric properties of rutile TiO2: First-principles anharmonic self-consistent phonon study", Phys. Rev. B 107, 094305 (2023). [link] [arXiv]
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file flatexpy-0.0.1.tar.gz.
File metadata
- Download URL: flatexpy-0.0.1.tar.gz
- Upload date:
- Size: 33.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e286d4f9b72b1b19e8c0f95119b52e70a56766981657d330faffbb7a26b4265d
|
|
| MD5 |
c4a6297e6da7ecfef6c7125f3fedee45
|
|
| BLAKE2b-256 |
df7068302f3ba4029acf43999a9c62ead1d201778789b7a02907ac16b3c87ea6
|
File details
Details for the file flatexpy-0.0.1-py3-none-any.whl.
File metadata
- Download URL: flatexpy-0.0.1-py3-none-any.whl
- Upload date:
- Size: 5.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c876719b4d14de0cf1f66d5482fb89e83fbcb1c1e48e3f99c129e67756dae6b0
|
|
| MD5 |
35eda0824266b3c5f13d73e8e01c6b6e
|
|
| BLAKE2b-256 |
03150887e59d6275fc3cb74ee7fe35fbdac261a0165bf92b0571c86d85fab5e8
|