tex2markdown converts a LaTeX document or project to one Markdown string. It
preserves LaTeX math and fragile formal content, converts suitable data tables,
expands local inputs and macros, and removes figures, captions, image commands,
and bibliographies.
The package is self-contained and has no runtime dependencies.
pip install tex2markdownConvert one in-memory document:
from tex2markdown import convert
markdown = convert(r"""
\documentclass{article}
\title{A Small Example}
\begin{document}
\maketitle
\section{Result}
The value is $x^2$.
\end{document}
""")Strings passed to convert() are always interpreted as LaTeX source, never as
file paths. For a file or a multi-file project, use convert_path():
from tex2markdown import convert_path
markdown = convert_path("paper.tex")
markdown = convert_path("project/")
markdown = convert_path("project/", main_file="main.tex")A directory is scanned recursively. Hidden and version-control paths, common
binary formats, non-UTF-8 files, and files larger than 20 MB are skipped. The
main TeX document is selected automatically unless main_file is supplied.
Nested \input and \include files and referenced local style macros are
expanded before conversion.
Both functions return str. Titles and abstracts come only from LaTeX source;
documents without a title use # Untitled. The \today command is preserved
literally, so repeated conversion is deterministic.
tex2markdown paper.tex
tex2markdown paper.tex -o paper.md
tex2markdown project/ --main-file main.tex
cat paper.tex | tex2markdown -Markdown is written to standard output unless -o is supplied. Standard input
and individual files do not accept --main-file.
Conversion failures derive from tex2markdown.ConversionError. More specific
types are available for invalid filesystem input, unsupported formats, and main
source selection: InputError, UnsupportedFormatError, and
SourceSelectionError.
uv sync
uv run pytest
uv run ruff check .
uv build