package tex
import "github.com/d2lang/mathjax-go/internal/mml"
type pendingDots struct {
ldots *mml .Node
cdots *mml .Node
}
func (p *parser ) startDots () *pendingDots {
ldots := p .token ("mo" , "\u2026" )
ldots .Attributes .Set ("stretchy" , false )
p .applyVectorFactory (ldots )
cdots := p .token ("mo" , "\u22EF" )
cdots .Attributes .Set ("stretchy" , false )
p .applyVectorFactory (cdots )
return &pendingDots {ldots : ldots , cdots : cdots }
}
func (pending *pendingDots ) active () bool { return pending .ldots != nil }
func (pending *pendingDots ) finish () []*mml .Node {
if !pending .active () {
return nil
}
dots := pending .ldots
*pending = pendingDots {}
return []*mml .Node {dots }
}
func (pending *pendingDots ) apply (nodes []*mml .Node ) []*mml .Node {
if !pending .active () || len (nodes ) == 0 {
return nodes
}
dots := pending .ldots
if core := dotsCoreMO (nodes [0 ]); core != nil {
class := dotsOperatorClass (core )
if class == mml .TeXClassBin || class == mml .TeXClassRel {
dots = pending .cdots
}
}
*pending = pendingDots {}
return append ([]*mml .Node {dots }, nodes ...)
}
func dotsCoreMO(n *mml .Node ) *mml .Node {
if n == nil || !n .Flags .Embellished {
return nil
}
for n .Kind != "mo" {
next := n .Core ()
if next == nil || next == n {
return nil
}
n = next
}
return n
}
func dotsOperatorClass(n *mml .Node ) mml .TeXClass {
if _ , explicit := n .Property ("texClass" ); explicit {
return n .TeXClass
}
forms := operatorForms (n )
if n .Attributes .IsSet ("form" ) {
value , _ := n .Attributes .Get ("form" )
if form , ok := value .(string ); ok {
ordered := []string {form }
for _ , candidate := range forms {
if candidate != form {
ordered = append (ordered , candidate )
}
}
forms = ordered
}
}
if definition , ok := lookupOperatorDefinition (textContent (n ), forms ); ok {
return mml .TeXClass (definition .TexClass )
}
return mml .TeXClassRel
}
The pages are generated with Golds v0.8.7 . (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu .
PR and bug reports are welcome and can be submitted to the issue list .
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds .