Documentation
¶
Overview ¶
Package latex opens a LaTeX or a plain TeX document and puts it on pages (D62). It runs a copy of the TeX engine of github.com/go-tex/engine, in latex/internal/engine, and draws its pages onto the display list of ivy (D10).
A document reads other files by their names: its class, its packages, the files of \input and its figures. The package reads them from two places. WithDir gives the folder of the document, and the field TeX of ivy.Config gives a tree of TeX files, such as the classes and the packages of a TeX distribution. The module of ivy holds no file of LaTeX, so a document whose class neither place holds is set without it. The package reads no file of the disk and no variable of the environment, because a document is input from a stranger (D5).
The engine sets the text in Latin Modern and the math in Latin Modern Math, as TeX does, when the field Fonts or the field TeX of ivy.Config holds them, such as fonts.TeX of the module github.com/xo/ivy/fonts or the tree of a TeX distribution. Without them, it sets the text in the Go fonts and the math in STIX Two Math.
The engine runs the whole document when a program first asks for its pages, because TeX numbers the pages and resolves the references of the whole document. The context stops the run. A command that the engine does not know is skipped, and the page is drawn without it.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var Format = ivy.Format{ Name: "latex", Mimes: []string{"text/x-tex", "application/x-tex", "text/x-latex", "application/x-latex"}, Exts: []string{"tex", "latex", "ltx"}, Open: func(ctx context.Context, src ivy.Source, cfg ivy.Config) (ivy.Document, error) { return Open(ctx, src, WithConfig(cfg)) }, }
Format describes the package for the registry of a program.
Functions ¶
This section is empty.
Types ¶
type Document ¶
type Document struct {
// contains filtered or unexported fields
}
Document is an open LaTeX document.
func Open ¶
Open opens a TeX document. It reads the whole source into memory. It returns an error that wraps ivy.ErrFormat if src is not text, and one that wraps ivy.ErrLimit if src is larger than the memory of the limits. The engine runs later, when a program asks for the pages.
func (*Document) Describe ¶
Describe satisfies the ivy.Describer interface. It gives the title and the authors of \hypersetup, or of \title and \author. It runs the engine.
Example ¶
A program reads the title and the authors that \title and \author give, without drawing the pages.
package main
import (
"bytes"
"context"
"fmt"
"os"
"path/filepath"
"github.com/xo/ivy"
"github.com/xo/ivy/latex"
)
func main() {
ctx := context.Background()
dir := filepath.Join("testdata", "report")
buf, err := os.ReadFile(filepath.Join(dir, "report.tex"))
if err != nil {
fmt.Println(err)
return
}
cfg := ivy.Config{TeX: os.DirFS(filepath.Join("..", "fonts"))}
d, err := latex.Open(ctx, bytes.NewReader(buf), latex.WithConfig(cfg), latex.WithDir(os.DirFS(dir)), latex.WithName("report"))
if err != nil {
fmt.Println(err)
return
}
defer d.Close()
info, err := d.Describe(ctx)
if err != nil {
fmt.Println(err)
return
}
fmt.Printf("%q %q\n", info.Title, info.Authors)
}
Output: "A Report on the Rendering of Documents" ["The Test Team"]
type Option ¶
type Option func(*options)
Option is an option of Open.
func WithConfig ¶
WithConfig sets the configuration that every format shares.
func WithDir ¶
WithDir gives the folder of the document. The document reads the files that it names, such as \input{chapter1} and \includegraphics{fig}, from dir, by their paths relative to the folder. dir must be safe for concurrent use. Without it, the document reads only the files of the field TeX of ivy.Config.
func WithName ¶
WithName gives the job name of the document: the name of its input file without the extension, such as "report" for report.tex. The engine reads the files of the run that carry the job name, such as report.bbl, from the folder of WithDir. Without it, the job name is "texput", as in TeX.
Example ¶
A program sets a LaTeX document that cites a bibliography. WithDir gives the folder of the document, where the engine finds its figures and its report.bbl, and WithName gives the job name, so that the engine reads report.bbl and not texput.bbl. The field TeX of ivy.Config gives the classes, the packages and the fonts of TeX, such as fonts.TeX of the module github.com/xo/ivy/fonts.
package main
import (
"bytes"
"context"
"fmt"
"os"
"path/filepath"
"github.com/xo/ivy"
"github.com/xo/ivy/latex"
)
func main() {
ctx := context.Background()
dir := filepath.Join("testdata", "report")
buf, err := os.ReadFile(filepath.Join(dir, "report.tex"))
if err != nil {
fmt.Println(err)
return
}
cfg := ivy.Config{TeX: os.DirFS(filepath.Join("..", "fonts"))}
d, err := latex.Open(ctx, bytes.NewReader(buf),
latex.WithConfig(cfg),
latex.WithDir(os.DirFS(dir)),
latex.WithName("report"),
)
if err != nil {
fmt.Println(err)
return
}
defer d.Close()
n, err := d.PageCount(ctx)
if err != nil {
fmt.Println(err)
return
}
fmt.Println(n > 0)
}
Output: true
type Page ¶
type Page struct {
// contains filtered or unexported fields
}
Page is a page of a LaTeX document.
func (*Page) Draw ¶
Draw satisfies the display.Drawer interface (D58). A figure that fails to draw is left out, and Draw returns an *ivy.PartialError.
Directories
¶
| Path | Synopsis |
|---|---|
|
internal
|
|
|
engine
Package engine is the core of a pure-Go (CGO=0) TeX engine: a faithful re-implementation of TeX's mouth and gullet — category-code tokenization, the equivalents table (eqtb) with grouping/scoping, macro definition with delimited parameters, and the expansion machinery (\def, \edef, \let, \expandafter, \csname, \noexpand, \string, \the, \number, conditionals, integer registers).
|
Package engine is the core of a pure-Go (CGO=0) TeX engine: a faithful re-implementation of TeX's mouth and gullet — category-code tokenization, the equivalents table (eqtb) with grouping/scoping, macro definition with delimited parameters, and the expansion machinery (\def, \edef, \let, \expandafter, \csname, \noexpand, \string, \the, \number, conditionals, integer registers). |
|
mathsvg
Package mathsvg gives the engine of LaTeX the part of the API of github.com/go-tex/math that it calls, on the layout of math of okage, texmath (okage D78).
|
Package mathsvg gives the engine of LaTeX the part of the API of github.com/go-tex/math that it calls, on the layout of math of okage, texmath (okage D78). |
|
nofs
Package nofs gives the engine of LaTeX the part of the API of the package os that it calls, without the file system and without the environment (D62).
|
Package nofs gives the engine of LaTeX the part of the API of the package os that it calls, without the file system and without the environment (D62). |
|
opentype
Package opentype gives the engine of LaTeX the part of the API of github.com/go-opentype/opentype that it calls, on the fonts of okage (D62).
|
Package opentype gives the engine of LaTeX the part of the API of github.com/go-opentype/opentype that it calls, on the fonts of okage (D62). |