Skip to main content

Like HTML, but not LaTeX? HtmLaTeX compiles HTML code to LaTeX.

Project description

HtmLaTeX

Work in Progress

Like HTML, but not LaTeX? HtmLaTeX compiles HTML code to LaTeX.

For example, the following HTML code:

<!DOCTYPE html>
<html lang="de">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>My Paper</title>
    <meta name="date" content="2022-09-02">
    <meta name="author" content="Linus">
    <link rel="icon" type="image/png" href="logo.png">
</head>
<body>
<div>
    <a href="#">link</a>
</div>
<h1 id="section-1">Hello World</h1>
<p>This is a paragraph.</p>

<img src="a">

</body>
</html>

...compiles to the following LaTeX code:

%%%%%% HEAD START %%%%%%

	\title{My Paper}

	\date{2022-09-02}

	\author{Linus}

%%%%%% HEAD END %%%%%%

%%%%%% MAIN DOCUMENT START %%%%%%
\begin{document}
\maketitle

	\section{Hello World}
	\label{section-1}

	This is a paragraph.

	\includegraphics{a}

\end{document}
%%%%%% MAIN DOCUMENT END %%%%%%

Installation

$ pip install HtmLaTeX

Usage

As binary

$ python3 -m htmlatex paper.html

This will create a file called paper.tex in the current directory.

As library

import io
import bs4
from htmlatex import Handlers, htmlatex

# Declare handlers for HTML tags

# Collection of handlers for HTML tags
handlers = Handlers()


# Register a handler for the <h1> tag
@handlers.register()
def h1(node: bs4.element.Tag):
    section_name = node.string
    section_id = node.attrs['id']
    yield [
        r"\section{%s}" % section_name,
        r"\label{%s}" % section_id,
    ]


# ... more handlers ...

# Destination for generated LaTeX
generated_latex = io.StringIO()
# HTML to be converted
html = "..."
# And compile
htmlatex(html, generated_latex, handlers=handlers)

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

HtmLaTeX-0.1.0.tar.gz (3.3 kB view details)

Uploaded Source

Built Distribution

HtmLaTeX-0.1.0-py3-none-any.whl (3.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: HtmLaTeX-0.1.0.tar.gz
  • Upload date:
  • Size: 3.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.13 CPython/3.8.10 Linux/5.15.0-41-generic

File hashes

Hashes for HtmLaTeX-0.1.0.tar.gz
Algorithm Hash digest
SHA256 8f0bb482c0c4908e1491a6bfaf7a4219421f4b42725e7ddcf807bf8d2fe924c6
MD5 68e26329fe9276dfcf6ef081bbe4e8f1
BLAKE2b-256 4488f570cdd5b9b2c896fb5aa32b9350914019a0be342c4fef41b7c9de9e167c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: HtmLaTeX-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 3.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.13 CPython/3.8.10 Linux/5.15.0-41-generic

File hashes

Hashes for HtmLaTeX-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c2e5493ea813a3f24ee91cef86d6289a171379038cc65ba7cfba2de40fc3a7fd
MD5 81d50d2a59ad7393b3957c69f4499090
BLAKE2b-256 b7efa3a68259c5a6b99367de78c8190a299ff24f7b7b692b4600934ca9e8b93f

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page