package mhchem

Import Path
	github.com/d2lang/mathjax-go/internal/mhchem (on go.dev)

Dependency Relation
	imports 8 packages, and imported by one package

Involved Source Files actions.go Package mhchem ports mhchemparser 4.1.1, the parser used by MathJax 3.2.2. ToTeX converts \ce and \pu source into a TeX expansion for a host parser. data.go engine.go error.go jsregexp.go Package mhchem is a native Go port of mhchemparser 4.1.1, the exact parser used by MathJax 3.2.2. It expands chemistry and physical-unit notation into ordinary TeX for a host TeX parser to consume. patterns.go texify.go
Package-Level Type Names (total 12)
/* sort by: | */
Option json.RawMessage Type string
Buffer mirrors the mhchemparser buffer object used by the action handlers in actions.go. Slots a..rm are typed as *string so we can distinguish "unset" from "empty string". A *string B *string BeginsWithBond bool D *string DType *string O *string P *string ParenthesisLevel int Q *string R *string Rd *string Rdt *string Rm *string Rq *string Rqt *string Sb bool Text *string ClearAll resets the buffer to its zero value. ClearSoft clears all slots except ParenthesisLevel/BeginsWithBond. func NewBuffer() *Buffer
Machines Machines Regexes map[string]*jsRegexp func LoadData() (*Data, error) func MustData() *Data
Error preserves the identifier and message pair thrown by mhchemparser. TeX integrations can pass these fields directly to their native TexError. ID string Message string (*Error) Error() string *Error : error
HasLocalActions bool Transitions map[string][]Transition
type Machines (map)
MatchToken is the result of matching one mhchem transition pattern. Either a single string (S) or an ordered tuple of substrings (A). A []string IsArray distinguishes the two variants. Using a bool keeps the type comparable and lets callers branch without a tagged union. S string
Mode selects one of mhchemparser's three source state machines. func ToTeX(input string, mode Mode) (string, error) const ModeCE const ModePU const ModeTeX
PatternHit is one successful pattern match: the captured token plus whatever input remained after it. Remainder string Token MatchToken
Action []ActionSpec NextState *string Revisit bool ToContinue bool
Pattern string Task Task
Output value: a polymorphic JSON-like list. Either a string (a TeX fragment) or a tagged map ({type_: "...", ...}).
Package-Level Functions (total 6)
IsSlotEmpty reports whether s is nil or points to an empty string.
func LoadData() (*Data, error)
func MustData() *Data
NewBuffer returns a fresh, zeroed Buffer.
SetSlot writes v to *slot, allocating if nil.
ToTeX returns the exact TeX expansion produced by mhchemparser 4.1.1.
Package-Level Constants (total 3)
ModeCE parses the argument of \ce.
ModePU parses the argument of \pu.
ModeTeX scans ordinary TeX and expands nested \ce and \pu commands.