tex

package module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 9, 2026 License: BSD-3-Clause Imports: 4 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

tex — go-tex

License Go Coverage

A pure-Go (no cgo) processor for a practical subset of LaTeX documents. It does more than render math: it tokenizes with TeX category codes, expands user macros (\def, \newcommand/\renewcommand with mandatory and optional arguments, \let), parses document structure, and emits semantic HTML with math typeset to inline SVG by go-tex/math. No TeX engine binary, no cgo, no server; it compiles to GOOS=js/wasm.

html, _ := tex.RenderHTML(`\documentclass{article}
\newcommand{\R}{\mathbb{R}}
\title{Demo}\author{go-tex}
\begin{document}
\maketitle
\section{Intro}
A \textbf{bold} claim about $\R^n$ and a display:
\[ \int_0^\infty e^{-x^2}\,dx = \frac{\sqrt{\pi}}{2} \]
\begin{itemize}\item first \item second\end{itemize}
\end{document}`)

What it processes

  • Macros — \newcommand{\name}[n][opt]{body} (mandatory + one optional arg), \renewcommand, \providecommand, TeX \def\name#1#2{body}, and \let. Macros expand everywhere, including inside math.
  • Structure — \documentclass/\usepackage (consumed), \title/\author/ \date/\maketitle, \section/\subsection/\subsubsection/\paragraph, paragraphs (blank lines).
  • Inline formatting — \textbf, \textit/\emph, \texttt, \underline, \textsc, \\/\newline.
  • Lists & blocks — itemize, enumerate, \item, quote, center, verbatim.
  • Math — $…$, \(…\) (inline) and $$…$$, \[…\], equation, displaymath, align (display), typeset to SVG; a malformed formula degrades to an error span rather than failing the document.
  • Text niceties — \% \& \_ \$ \# \{ \}, ~, \ldots, and text accents (\'e→é, \"o→ö, …, precomposed to NFC).

Scope — honest limits

This is the front of a TeX engine (the "mouth" + a document builder), not a replacement for a TeX distribution (TeXLive). There is no page/line breaking, no float/table/figure model, no counters/cross-references/bibliography, no package ecosystem, and no PDF/DVI back-end — the output is HTML. Unknown commands are dropped best-effort. Full LaTeX (real line-breaking, packages, PDF) is the larger ongoing go-tex engine effort; this package is a working, useful foundation and a proof that processing documents (not just rendering math) is tractable in pure Go.

Install

go get github.com/go-tex/tex

Command

cmd/gotex reads a .tex file (or stdin) and writes an HTML document:

go run ./cmd/gotex paper.tex > paper.html

Tests

Statement coverage is held at 100% (tokenizer, macro expander, document processor, and every end-of-input guard), go vet clean, and green across the six 64-bit Go targets plus js/wasm and wasip1/wasm.

go test ./...

License

BSD-3-Clause — see LICENSE. Copyright the go-tex/tex authors. The embedded math font (via go-tex/math) is STIX Two Math, under the SIL OFL.

Documentation

Overview

Package tex is a pure-Go (CGO=0) processor for a practical subset of LaTeX *documents* — not just math. It tokenizes with TeX category codes, expands user macros (\def, \newcommand/\renewcommand with mandatory and optional arguments), parses document structure (sectioning, font commands, lists, inline and display math, paragraphs), and emits semantic HTML with math typeset to SVG by go-tex/math. There is no page/line breaking, no package ecosystem, and no PDF/DVI back-end: this is the front of the engine (the "mouth" and a document builder), a foundation for full LaTeX processing.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RenderHTML

func RenderHTML(src string) (string, error)

RenderHTML processes a LaTeX-subset document and returns a complete HTML document (with math typeset to inline SVG). The error result is reserved for future fatal-processing conditions; today it is always nil.

Types

This section is empty.

Directories

Path Synopsis
cmd
gotex command
Command gotex processes a LaTeX-subset document (file argument or stdin) and writes an HTML document to stdout.
Command gotex processes a LaTeX-subset document (file argument or stdin) and writes an HTML document to stdout.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
⌂ 换网址