katex

package module
v0.0.0-...-b6cc24c Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2026 License: MIT Imports: 13 Imported by: 2 modules, 2 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

Goldmark Katex

Go Reference

Goldmark Katex is a Goldmark extension providing math and equation support through KaTeX.

Usage

goldmark.New(goldmark.WithExtensions(&Extender{})).Convert(src, dst)

Wrap inline math with a pair of single $:

$A$

Wrap block math with a pair of double $:

$$
A = \pi \times r^2
$$

Example

Given the radius $r$ of a circle, the area $A$ is:

$$
A = \pi \times r^2
$$

And the circumference $C$ is:

$$
C = 2 \pi r
$$

More Goldmark Extensions

  • D2: diagram support through D2

Documentation

Index

Examples

Constants

This section is empty.

Variables

View Source
var KindBlock = ast.NewNodeKind("Block")
View Source
var KindInline = ast.NewNodeKind("Inline")

Functions

func Render

func Render(w io.Writer, src []byte, display bool) error
Example
b := bytes.Buffer{}
Render(&b, []byte(`Y = A \dot X^2 + B \dot X + C`), false)
fmt.Println(b.String())
Output:
<span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>Y</mi><mo>=</mo><mi>A</mi><msup><mover accent="true"><mi>X</mi><mo>˙</mo></mover><mn>2</mn></msup><mo>+</mo><mi>B</mi><mover accent="true"><mi>X</mi><mo>˙</mo></mover><mo>+</mo><mi>C</mi></mrow><annotation encoding="application/x-tex">Y = A \dot X^2 + B \dot X + C</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.6833em;"></span><span class="mord mathnormal" style="margin-right:0.22222em;">Y</span><span class="mspace" style="margin-right:0.2778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2778em;"></span></span><span class="base"><span class="strut" style="height:1.0035em;vertical-align:-0.0833em;"></span><span class="mord mathnormal">A</span><span class="mord"><span class="mord accent"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.9202em;"><span style="top:-3em;"><span class="pstrut" style="height:3em;"></span><span class="mord mathnormal" style="margin-right:0.07847em;">X</span></span><span style="top:-3.2523em;"><span class="pstrut" style="height:3em;"></span><span class="accent-body" style="left:-0.0556em;"><span class="mord">˙</span></span></span></span></span></span></span><span class="msupsub"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.8141em;"><span style="top:-3.063em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">2</span></span></span></span></span></span></span></span><span class="mspace" style="margin-right:0.2222em;"></span><span class="mbin">+</span><span class="mspace" style="margin-right:0.2222em;"></span></span><span class="base"><span class="strut" style="height:1.0035em;vertical-align:-0.0833em;"></span><span class="mord mathnormal" style="margin-right:0.05017em;">B</span><span class="mord accent"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.9202em;"><span style="top:-3em;"><span class="pstrut" style="height:3em;"></span><span class="mord mathnormal" style="margin-right:0.07847em;">X</span></span><span style="top:-3.2523em;"><span class="pstrut" style="height:3em;"></span><span class="accent-body" style="left:-0.0556em;"><span class="mord">˙</span></span></span></span></span></span></span><span class="mspace" style="margin-right:0.2222em;"></span><span class="mbin">+</span><span class="mspace" style="margin-right:0.2222em;"></span></span><span class="base"><span class="strut" style="height:0.6833em;"></span><span class="mord mathnormal" style="margin-right:0.07153em;">C</span></span></span></span>

Types

type Block

type Block struct {
	ast.BaseInline

	Equation []byte
}

func (*Block) Dump

func (n *Block) Dump(source []byte, level int)

func (*Block) IsBlank

func (n *Block) IsBlank(source []byte) bool

func (*Block) Kind

func (n *Block) Kind() ast.NodeKind

type Extender

type Extender struct {
	LatexDelimiters bool
	BlockOnly       bool
}

func (*Extender) Extend

func (e *Extender) Extend(m goldmark.Markdown)

type HTMLRenderer

type HTMLRenderer struct {
	html.Config
	// contains filtered or unexported fields
}

func (*HTMLRenderer) RegisterFuncs

func (r *HTMLRenderer) RegisterFuncs(reg renderer.NodeRendererFuncRegisterer)

type Inline

type Inline struct {
	ast.BaseInline

	Equation []byte
}

func (*Inline) Dump

func (n *Inline) Dump(source []byte, level int)

func (*Inline) Inline

func (n *Inline) Inline()

func (*Inline) IsBlank

func (n *Inline) IsBlank(source []byte) bool

func (*Inline) Kind

func (n *Inline) Kind() ast.NodeKind

type Parser

type Parser struct {
	LatexDelimiters bool
	BlockOnly       bool
}

Parser uses $$ .. $$ for block expressions and $ .. $ for inline by default. If LatexDelimiters is set then uses \[ .. \] and \( .. \) instead. If BlockOnly is set then skips inline expressions

func (*Parser) Parse

func (s *Parser) Parse(parent ast.Node, block text.Reader, pc parser.Context) ast.Node

func (*Parser) Trigger

func (s *Parser) Trigger() []byte

Jump to

Keyboard shortcuts

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