Skip to main content

Extract LaTeX fenced blocks from literate Markdown files.

Project description

tangle-md2tex

Extract LaTeX fenced code blocks from literate Markdown files.

中文文档见 README.zh-CN.md.

What It Does

tangle-md2tex reads Markdown files ending in .lit.md, extracts fenced code blocks whose info string is exactly latex, and writes the extracted LaTeX to a sibling .tex file.

For example:

```latex
First paragraph.

Second paragraph.
```

This prose explains why the LaTeX above is written this way.

becomes:

First paragraph.

Second paragraph.

Literate Markdown Format

Use .lit.md as the source file extension:

paper.lit.md -> paper.tex
sections/intro.lit.md -> sections/intro.tex

Only latex fenced code blocks are extracted:

```latex
\section{Introduction}

This is the manuscript text.
```

Explanation, notes, outlines, TODOs, or review comments can live here. They are
not copied into the generated `.tex` file.

Fence contents are copied as-is from markdown-it-py's token content. Leading blank lines, paragraph-separating blank lines, and trailing blank lines inside a latex fence are preserved because LaTeX uses blank lines to separate paragraphs.

Install

pip install tangle-md2tex

For local development:

python -m pip install -e .

Usage

Process one file:

tanglemd2tex paper.lit.md

Process every .lit.md file under a directory:

tanglemd2tex sections/

If no path is given, the current directory is scanned recursively:

tanglemd2tex

You can also run it as a module:

python -m tanglemd2tex paper.lit.md

Python API

from pathlib import Path

from tanglemd2tex import tangle_file, tangle_text

tex_text = tangle_text(markdown_text)
tex_path = tangle_file(Path("paper.lit.md"))

Rules

  • Source files must end with .lit.md.
  • Output files are written next to the source file with the .tex extension.
  • Only fenced code blocks with info string latex are extracted.
  • Non-LaTeX Markdown prose is treated as explanation and ignored by the output.
  • The tool does not parse or validate LaTeX.

License

MIT

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

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

tangle_md2tex-0.2.0-py3-none-any.whl (5.4 kB view details)

Uploaded Python 3

File details

Details for the file tangle_md2tex-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: tangle_md2tex-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 5.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for tangle_md2tex-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4ee19ec786a551a599b4198751af70068738c90644d4c06b983b107869d771ee
MD5 6ac9a7289c584639910af6d2300603b3
BLAKE2b-256 8555daba75d2d50be59679d3b8ec2d97ef78979b3bf8d1e203a4116c2504bc7a

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