Skip to main content

A simple library that translates LaTeX to Markdown.

Project description

texmd

A small library that converts LaTeX to Markdown. This package uses pylatexenc to parse the LaTeX expressions.

Currently, it supports converting inlined mathematical equations $...$, equation blocks (equation, equation*, align, align*, array, matrix, eqnarray, multline), title \title, sections (\section, \subsection, subsubsection); abstract content \abstract{...} (supported by Markdown block quote); in-text quotations ``...''; equation numbered labels are also supported. More will be introduced in later versions.

Installation

Run pip install texmd in the terminal.

Usage

This package allows you to load a .tex file directly.

from texmd import tex # Import the package

parser = tex.TexParser()
file_path = "<PATH_TO_TEX_FILE>"
tex_file = parser.load_file(file_path) # Load the file

The loaded file tex_file is type of texmd.texmd.TexDocument.

If you want to parse the LaTeX string directly you can also do

tex_expr = "<TEX_EXPR>"
tex_file = parser.parse(tex_expr)

We can convert then it to Markdown by

document = parser.to_md(tex_file)

The output document is type of texmd.md.MdDocument. To output the document as Markdown syntax we can do

md = document.to_str()

and you can write it to a .md file.

Add BibTeX support

In order for the package to also process BibTeX we will have to load the .bib file.

parser.load_citations("<BIB_FILE_PATH>")

Customization

If you don't like the way the package write the Markdown, or you want to support custom LaTeX expressions, you can use the API parser.set_converter with a specific sub-type of texmd.tex.TexNode.

For example you want to set a new converter for text node.

class TextNodeConverter(Converter):
    """ A converter for LaTeX text nodes. """

    def __init__(self):
        super().__init__(None)

    def convert(self, node: TexTextNode) -> Generator[MdNode]:
        def _():
            yield MdText(text=node.text)
        return _()

converter = TextNodeConverter()
parser.set_converter(TexTextNode, '', converter)

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

texmd-0.1.0.tar.gz (13.6 kB view details)

Uploaded Source

Built Distribution

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

texmd-0.1.0-py3-none-any.whl (15.7 kB view details)

Uploaded Python 3

File details

Details for the file texmd-0.1.0.tar.gz.

File metadata

  • Download URL: texmd-0.1.0.tar.gz
  • Upload date:
  • Size: 13.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.13.0

File hashes

Hashes for texmd-0.1.0.tar.gz
Algorithm Hash digest
SHA256 86e34b33f5947c3090ec767c288e0ee2f02396734ce80b5a7bfc97146ffba763
MD5 fe80e1ed00214411b475890fa930624d
BLAKE2b-256 41afe4624180cc036b3e18c88f4f479668236719316105e3b3eac09d8b3fd1a3

See more details on using hashes here.

File details

Details for the file texmd-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: texmd-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 15.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.13.0

File hashes

Hashes for texmd-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 553d735305fdd3a5773a7fc20ddf67e1b1706cc5582aa056ae80aa74695c466a
MD5 e6ad97dd2d59310020ec7fb4e06abd21
BLAKE2b-256 5cfcf4cd50c0fc4eefd1ff39e56a0107823d7a80daa04f8233287f10c1faf024

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