Documentation
¶
Index ¶
- Constants
- Variables
- func GetNextExpr(tokens []Token, idx int) ([]Token, int, ExprKind)
- func StringifyTokens(toks []Token) string
- type CommandSpec
- type ExprKind
- type MMLNode
- func (n *MMLNode) AddClass(class string) *MMLNode
- func (n *MMLNode) AppendChild(child ...*MMLNode) *MMLNode
- func (n *MMLNode) AppendNew(opt ...string) *MMLNode
- func (n *MMLNode) SetAttr(name, value string) *MMLNode
- func (n *MMLNode) SetFalse(name string) *MMLNode
- func (n *MMLNode) SetProps(p NodeProperties) *MMLNode
- func (n *MMLNode) SetTrue(name string) *MMLNode
- func (n *MMLNode) Write(w *strings.Builder)
- type MathMLConverter
- func (converter *MathMLConverter) ConvertDisplay(tex string) (string, error)
- func (converter *MathMLConverter) ConvertInline(tex string) (string, error)
- func (converter *MathMLConverter) DisplayStyle(tex string) (string, error)
- func (converter *MathMLConverter) OriginalString(b *TokenBuffer) string
- func (converter *MathMLConverter) ParseTex(b *TokenBuffer, context parseContext, parent ...*MMLNode) *MMLNode
- func (converter *MathMLConverter) ProcessCommand(context parseContext, tok Token, b *TokenBuffer) *MMLNode
- func (converter *MathMLConverter) TextStyle(tex string) (string, error)
- type MismatchedBraceError
- type NodeClass
- type NodeProperties
- type Token
- type TokenBuffer
- func (b *TokenBuffer) Advance()
- func (b *TokenBuffer) Empty() bool
- func (b *TokenBuffer) GetNextExpr() (*TokenBuffer, error)
- func (b *TokenBuffer) GetNextN(n int, skipWhitespace ...bool) (*TokenBuffer, error)
- func (b *TokenBuffer) GetNextToken(skipWhitespace ...bool) (Token, error)
- func (b *TokenBuffer) GetOptions(skipWhitespace ...bool) (*TokenBuffer, error)
- func (b *TokenBuffer) GetUntil(f func(Token) bool) *TokenBuffer
- func (b *TokenBuffer) Unget()
- type TokenBufferError
- type TokenKind
Constants ¶
const MaxParseDepth = 64
MaxParseDepth is the maximum recursion depth of the TeX parser. Deeper expressions fail to convert.
Variables ¶
Functions ¶
func GetNextExpr ¶
Get the next single token or expression enclosed in brackets. Return the index immediately after the end of the returned expression. Example:
\frac{a^2+b^2}{c+d}
│╰──┬──╯╰─ final position returned
│ ╰───── slice of tokens returned
╰───────── idx (initial position)
Types ¶
type CommandSpec ¶
type CommandSpec struct {
F func(*MathMLConverter, string, bool, parseContext, []*TokenBuffer, *TokenBuffer) *MMLNode
// contains filtered or unexported fields
}
type MMLNode ¶
type MMLNode struct {
Tok Token // the token from which this node was created
Text string // the <tag>text</tag> enclosed in the Tag.
Tag string // the value of the MathML tag, e.g. <mrow>, <msqrt>, <mo>....
Option string // container for any options that may be passed and processed for a tex command
Properties NodeProperties // bitfield of NodeProperties
Attrib map[string]string // key value pairs of XML attributes; nil until one is set
Children []*MMLNode // ordered list of child MathML elements
}
An MMLNode is the representation of a MathML tag or tree.
func NewMMLNode ¶
NewMMLNode allocates a new MathML node. The first optional argument sets the value of Tag. The second optional argument sets the value of Text.
func (*MMLNode) AppendChild ¶
AppendChild appends the child (or children) provided to the children of n.
func (*MMLNode) AppendNew ¶
AppendNew creates a new MMLNode and appends it to the children of n. The newly created MMLNode is returned.
func (*MMLNode) SetProps ¶
func (n *MMLNode) SetProps(p NodeProperties) *MMLNode
type MathMLConverter ¶
type MathMLConverter struct {
// contains filtered or unexported fields
}
MathMLConverter manages LaTeX to MathML conversion state
func NewMathMLConverter ¶
func NewMathMLConverter() *MathMLConverter
NewMathMLConverter returns a converter. It keeps per-expression state, so it must not be shared across concurrent conversions.
func (*MathMLConverter) ConvertDisplay ¶
func (converter *MathMLConverter) ConvertDisplay(tex string) (string, error)
ConvertDisplay converts LaTeX to display MathML
func (*MathMLConverter) ConvertInline ¶
func (converter *MathMLConverter) ConvertInline(tex string) (string, error)
ConvertInline converts LaTeX to inline MathML
func (*MathMLConverter) DisplayStyle ¶
func (converter *MathMLConverter) DisplayStyle(tex string) (string, error)
ConvertToDisplay converts LaTeX to display MathML
func (*MathMLConverter) OriginalString ¶
func (converter *MathMLConverter) OriginalString(b *TokenBuffer) string
func (*MathMLConverter) ParseTex ¶
func (converter *MathMLConverter) ParseTex(b *TokenBuffer, context parseContext, parent ...*MMLNode) *MMLNode
Parse a list of TeX tokens into a MathML node tree
func (*MathMLConverter) ProcessCommand ¶
func (converter *MathMLConverter) ProcessCommand(context parseContext, tok Token, b *TokenBuffer) *MMLNode
ProcessCommand sets the value of n and returns the next index of tokens to be processed.
type MismatchedBraceError ¶
type MismatchedBraceError struct {
// contains filtered or unexported fields
}
MismatchedBraceError is an error that occurs when a brace is mismatched
func (MismatchedBraceError) Error ¶
func (e MismatchedBraceError) Error() string
Error the MismatchedBraceError
type NodeProperties ¶
type NodeProperties uint64
type TokenBuffer ¶
type TokenBuffer struct {
Expr []Token // The current sub-expression
// contains filtered or unexported fields
}
func (*TokenBuffer) GetNextExpr ¶
func (b *TokenBuffer) GetNextExpr() (*TokenBuffer, error)
Get the next expression enclosed in {curly braces}
func (*TokenBuffer) GetNextN ¶
func (b *TokenBuffer) GetNextN(n int, skipWhitespace ...bool) (*TokenBuffer, error)
Get the next n tokens. Past the end of the buffer, it returns the rest of the buffer with ErrTokenBufferEnd, and consumes it all the same: a caller that ungets after the error rewinds to where it was, not before it. With skipWhitespace, the whitespace and comments before the tokens are skipped; without it, n counts every token, as a MatchOffset does.
Sub-buffers are cut with their capacity set to their length, here and in GetNextExpr, GetOptions and GetUntil, so that no offset read inside one can reach the tokens of the buffer around it.
func (*TokenBuffer) GetNextToken ¶
func (b *TokenBuffer) GetNextToken(skipWhitespace ...bool) (Token, error)
func (*TokenBuffer) GetOptions ¶
func (b *TokenBuffer) GetOptions(skipWhitespace ...bool) (*TokenBuffer, error)
Extract the tokens strictly between [square brackets]. skipWhitespace is true by default.
func (*TokenBuffer) GetUntil ¶
func (b *TokenBuffer) GetUntil(f func(Token) bool) *TokenBuffer
Get tokens until (but not including) the condition f evaluates as true, or the end of the token buffer is reached
type TokenBufferError ¶
type TokenBufferError struct {
// contains filtered or unexported fields
}
func (*TokenBufferError) Error ¶
func (e *TokenBufferError) Error() string
Error the TokenBufferError
func (*TokenBufferError) Unwrap ¶
func (e *TokenBufferError) Unwrap() error
Unwrap the TokenBufferError