Skip to main content

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)

Release files for htmlatex 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for htmlatex 0.1.0
File Size Uploaded
HtmLaTeX-0.1.0.tar.gz 3.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for htmlatex 0.1.0
File Interpreter ABI Platform
HtmLaTeX-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 6.9 kB

Release files / HtmLaTeX-0.1.0.tar.gz

Download URL HtmLaTeX-0.1.0.tar.gz
Size 3.3 kB
Tags Source
SHA-256 checksum
How to use checksums
8f0bb482c0c4908e1491a6bfaf7a4219421f4b42725e7ddcf807bf8d2fe924c6
BLAKE2b-256 checksum
How to use checksums
4488f570cdd5b9b2c896fb5aa32b9350914019a0be342c4fef41b7c9de9e167c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.13 CPython/3.8.10 Linux/5.15.0-41-generic

Release files / HtmLaTeX-0.1.0-py3-none-any.whl

Download URL HtmLaTeX-0.1.0-py3-none-any.whl
Size 3.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c2e5493ea813a3f24ee91cef86d6289a171379038cc65ba7cfba2de40fc3a7fd
BLAKE2b-256 checksum
How to use checksums
b7efa3a68259c5a6b99367de78c8190a299ff24f7b7b692b4600934ca9e8b93f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.13 CPython/3.8.10 Linux/5.15.0-41-generic

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page