bibtex

package module
v1.0.5 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2022 License: Apache-2.0 Imports: 11 Imported by: 1

README

bibtex Build Status Go Reference

nickng/bibtex is a bibtex parser and library for Go.

The bibtex format is not standardised, this parser follows the descriptions found here. Please file any issues with a minimal working example.

To get:

go get -u github.com/Jblew/bibtex/...

This will also install prettybib, a bibtex pretty printer. To parse and pretty print a bibtex file, for example:

cd $GOPATH/src/github.com/Jblew/bibtex
prettybib -in example/simple.bib

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

Constants

This section is empty.

Variables

View Source
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

func NewBibConst(c string) BibConst

NewBibConst converts a constant string to BibConst.

func (BibConst) RawString

func (c BibConst) RawString() string

RawString is the internal representation of the constant (i.e. the string).

func (BibConst) String

func (c BibConst) String() string

type BibEntry

type BibEntry struct {
	Type     string
	CiteName string
	Fields   map[string]BibString
}

BibEntry is a record of BibTeX record.

func NewBibEntry

func NewBibEntry(entryType string, citeName string) *BibEntry

NewBibEntry creates a new BibTeX entry.

func (*BibEntry) AddField

func (entry *BibEntry) AddField(name string, value BibString)

AddField adds a field (key-value) to a BibTeX entry.

func (*BibEntry) RawString added in v1.0.4

func (entry *BibEntry) RawString() string

RawString returns a BibTex entry data structure in its internal representation.

func (*BibEntry) String added in v1.0.4

func (entry *BibEntry) String() string

String returns a BibTex entry as a simplified BibTex string.

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 NewBibTex

func NewBibTex() *BibTex

NewBibTex creates a new BibTex data structure.

func Parse

func Parse(r io.Reader) (*BibTex, error)

Parse is the entry point to the bibtex parser.

func (*BibTex) AddEntry

func (bib *BibTex) AddEntry(entry *BibEntry)

AddEntry adds an entry to the BibTeX data structure.

func (*BibTex) AddPreamble

func (bib *BibTex) AddPreamble(p BibString)

AddPreamble adds a preamble to a bibtex.

func (*BibTex) AddStringVar

func (bib *BibTex) AddStringVar(key string, val BibString)

AddStringVar adds a new string var (if does not exist).

func (*BibTex) GetStringVar

func (bib *BibTex) GetStringVar(key string) *BibVar

GetStringVar looks up a string by its key.

func (*BibTex) PrettyString

func (bib *BibTex) PrettyString() string

PrettyString pretty prints a BibTex.

func (*BibTex) RawString

func (bib *BibTex) RawString() string

RawString returns a BibTex data structure in its internal representation.

func (*BibTex) String

func (bib *BibTex) String() string

String returns a BibTex data structure as a simplified BibTex string.

type BibVar

type BibVar struct {
	Key   string    // Variable key.
	Value BibString // Variable actual value.
}

BibVar is a string variable.

func (*BibVar) RawString

func (v *BibVar) RawString() string

RawString is the internal representation of the variable.

func (*BibVar) String

func (v *BibVar) String() string

type ErrParse

type ErrParse struct {
	Pos tokenPos
	Err string // Error string returned from parser.
}

ErrParse is a parse error.

func (*ErrParse) Error

func (e *ErrParse) Error() string

Directories

Path Synopsis
cmd
prettybib
Command prettybib pretty prints a bib entry from command line.
Command prettybib pretty prints a bib entry from command line.

Jump to

Keyboard shortcuts

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