A command-line tool to convert Markdown files to LaTeX.
md2latex/
├── src/md2latex/
│ ├── __init__.py # Package exports
│ ├── cli.py # Command-line interface
│ └── converter.py # Markdown to LaTeX conversion logic
├── tests/
│ ├── conftest.py # Shared test fixtures
│ ├── unit/ # Unit tests
│ ├── integration/ # Integration tests
│ └── system/ # End-to-end CLI tests
├── pyproject.toml # Package configuration
├── README.md
├── CONTRIBUTING.md
└── LICENSE
# Install in development mode
pip install -e .
# Or install directly
pip install .
# Install with development dependencies (for testing)
pip install -e ".[dev]"# Convert a Markdown file and print to stdout
md2latex input.md
# Convert and save to a file
md2latex input.md -o output.tex
# Read from stdin
cat input.md | md2latex -
# Pipe to a file
md2latex input.md > output.tex-o, --output FILE- Write output to a file instead of stdout--no-preamble- Omit the LaTeX document preamble (useful for including in larger documents)-v, --version- Show version information-h, --help- Show help message
Generate a complete LaTeX document:
md2latex document.md -o document.texGenerate LaTeX content without preamble (for inclusion in another document):
md2latex chapter.md --no-preamble -o chapter.tex- Headings (h1-h6) →
\section,\subsection, etc. - Bold (
**text**) →\textbf{text} - Italic (
*text*) →\textit{text} - Inline code (
`code`) →\texttt{code} - Code blocks (with language support) →
lstlistingenvironment - Links (
[text](url)) →\href{url}{text} - Images (
) →\includegraphicsin figure environment - Ordered lists →
enumerateenvironment - Unordered lists →
itemizeenvironment - Block quotes →
quoteenvironment - Horizontal rules →
\hrulefill
The converter automatically includes only the packages needed for your content:
hyperref- for linksgraphicx- for imageslistings- for code blocksulem- for strikethrough text
You can also use md2latex as a Python library:
from md2latex import convert_markdown_to_latex, MarkdownToLatexConverter
# Simple conversion
latex = convert_markdown_to_latex("# Hello World\n\nThis is **bold**.")
# Without preamble
latex = convert_markdown_to_latex("# Hello", include_preamble=False)
# Using the converter class
converter = MarkdownToLatexConverter(include_preamble=True)
latex = converter.convert(markdown_text)
converter.convert_file("input.md", "output.tex")The project includes a comprehensive test suite with unit, integration, and system tests.
# Run all tests
pytest tests -v
# Run specific test categories
pytest tests/unit -v # Unit tests only
pytest tests/integration -v # Integration tests only
pytest tests/system -v # System/CLI tests only
# Run with coverage (requires pytest-cov)
pytest tests --cov=md2latex --cov-report=term-missingMIT License