Documentation ¶
Overview ¶
Package bibtex is a bibtex parser written in Go.
The package contains a simple parser and data structure to represent bibtex records.
Supported syntax ¶
The basic syntax is:
@BIBTYPE{IDENT, key1 = word, key2 = "quoted", key3 = {quoted}, }
where BIBTYPE is the type of document (e.g. inproceedings, article, etc.) and IDENT is a string identifier.
The bibtex format is not standardised, this parser follows the descriptions found in the link below. If there are any problems, please file any issues with a minimal working example at the GitHub repository. http://maverick.inria.fr/~Xavier.Decoret/resources/xdkbibtex/bibtex_summary.html
Index ¶
- Variables
- type BibComposite
- type BibConst
- type BibEntry
- type BibString
- type BibTex
- func (bib *BibTex) AddEntry(entry *BibEntry)
- func (bib *BibTex) AddPreamble(p BibString)
- func (bib *BibTex) AddStringVar(key string, val BibString)
- func (bib *BibTex) GetStringVar(key string) *BibVar
- func (bib *BibTex) PrettyString(options ...PrettyStringOpt) string
- func (bib *BibTex) RawString() string
- func (bib *BibTex) String() string
- type BibVar
- type ErrParse
- type PrettyStringOpt
Constants ¶
This section is empty.
Variables ¶
var ( // ErrUnexpectedAtsign is an error for unexpected @ in {}. ErrUnexpectedAtsign = errors.New("unexpected @ sign") // ErrUnknownStringVar is an error for looking up undefined string var. ErrUnknownStringVar = errors.New("unknown string variable") )
Functions ¶
This section is empty.
Types ¶
type BibComposite ¶
type BibComposite []BibString
BibComposite is a composite string, may contain both variable and string.
func NewBibComposite ¶
func NewBibComposite(s BibString) *BibComposite
NewBibComposite creates a new composite with one element.
func (*BibComposite) Append ¶
func (c *BibComposite) Append(s BibString) *BibComposite
Append adds a BibString to the composite
func (*BibComposite) RawString ¶
func (c *BibComposite) RawString() string
RawString returns a raw (bibtex) representation of the composite string.
func (*BibComposite) String ¶
func (c *BibComposite) String() string
type BibConst ¶
type BibConst string
BibConst is a string constant.
func NewBibConst ¶
NewBibConst converts a constant string to BibConst.
type BibEntry ¶
BibEntry is a record of BibTeX record.
func NewBibEntry ¶
NewBibEntry creates a new BibTeX entry.
func (*BibEntry) PrettyString ¶ added in v1.2.0
func (entry *BibEntry) PrettyString(options ...PrettyStringOpt) string
PrettyString pretty prints a BibEntry
type BibString ¶
type BibString interface { RawString() string // Internal representation. String() string // Displayed string. }
BibString is a segment of a bib string.
type BibTex ¶
type BibTex struct { Preambles []BibString // List of Preambles Entries []*BibEntry // Items in a bibliography. StringVar map[string]*BibVar // Map from string variable to string. // contains filtered or unexported fields }
BibTex is a list of BibTeX entries.
func (*BibTex) AddPreamble ¶
AddPreamble adds a preamble to a bibtex.
func (*BibTex) AddStringVar ¶
AddStringVar adds a new string var (if does not exist).
func (*BibTex) GetStringVar ¶
GetStringVar looks up a string by its key.
func (*BibTex) PrettyString ¶
func (bib *BibTex) PrettyString(options ...PrettyStringOpt) string
PrettyString pretty prints a BibTex
type BibVar ¶
BibVar is a string variable.
type ErrParse ¶
type ErrParse struct { Pos tokenPos Err string // Error string returned from parser. }
ErrParse is a parse error.
type PrettyStringOpt ¶ added in v1.2.0
type PrettyStringOpt func(config *prettyStringConfig)
PrettyStringOpt allows to change the pretty print format for BibEntry and BibTex
func WithKeyOrder ¶ added in v1.2.0
func WithKeyOrder(keyOrder []string) PrettyStringOpt
WithKeyOrder changes the order in which BibEntry keys are printed to the order in which they appear in keyOrder