►V Reference
On this page:
58.8.1 La  Te  X Formula Visuals
formula-mode?
latex-option?
latex-formula
58.8.1.1 Inspecting and Updating Formula Models
formula-visual?
formula-visual-source
formula-visual-mode
formula-visual-font-size
formula-visual-preamble
formula-visual-document-class-options
formula-visual-preview-options
formula-visual-horizontal-alignment
formula-visual-vertical-alignment
formula-visual-with-source
58.8.2 Tagged Formula Layouts
formula-fragment
tagged-formula
math-tex
glyph-tex
58.8.3 Making latex-pict Available
9.3

58.8 Formula Construction and Layout🔗ℹ

Choose latex-formula for one formula model value, tagged-formula for named fragments laid out together, math-tex for source-addressable construction, or glyph-tex for rendered glyph leaves. Jointly typeset constructors run the external TeX and SVG tools during construction; plain LaTeX model construction does not. For manual part placement, see Named Formula Parts and Correspondence.

See also Formula Assemblies and Named Parts, Formula Source Selection and Matching.

    58.8.1 LaTeX Formula Visuals

      58.8.1.1 Inspecting and Updating Formula Models

    58.8.2 Tagged Formula Layouts

    58.8.3 Making latex-pict Available

58.8.1 LaTeX Formula Visuals🔗ℹ

A formula Visual stores an immutable LaTeX mathematical snippet and explicit typesetting data. It implements gen:visual, gen:affine-visual, and gen:opacity-visual. Its raw structure constructor and internal transform and opacity fields are not public.

Formula model values are backend-independent. They do not contain Picts, PDF pages, Poppler values, process handles, or cached TeX results. The built-in adapter calls latex-pict only when a nonempty formula is rendered.

procedure

(formula-mode? value) → boolean?

  value : any/c
Returns #t when value is one of the supported formula modes:

'inline
'display
'display-environment

The 'inline mode uses ordinary inline mathematics. The 'display mode uses display-style mathematics in a tight inline box. The 'display-environment mode uses a real LaTeX display environment, which can include wider horizontal margins.

procedure

(latex-option? value) → boolean?

  value : any/c
Returns #t when value is a symbol or string accepted as one ordered LaTeX option. Mutable strings satisfy this predicate; constructors copy them into immutable model storage.

procedure

(latex-formula 
  source 
  #:id id 
  [#:center center 
  #:rotation rotation 
  #:scale scale 
  #:opacity opacity 
  #:mode mode 
  #:font-size font-size 
  #:preamble preamble 
  #:document-class-options document-class-options 
  #:preview-options preview-options 
  #:horizontal-alignment horizontal-alignment 
  #:vertical-alignment vertical-alignment]) 
 → formula-visual?
  source : string?
  id : symbol?
  center : vec2? = origin
  rotation : finite-real? = 0
  scale : scale-factor? = 1
  opacity : opacity? = 1
  mode : formula-mode? = 'display
  font-size : (and/c finite-real? positive?) = 1
  preamble : string? = ""
  document-class-options : (listof latex-option?) = '()
  preview-options : (listof latex-option?) = '()
  horizontal-alignment : text-horizontal-alignment? = 'center
  vertical-alignment : text-vertical-alignment? = 'center
Creates a semantic mathematical formula Visual. The required id is its stable Visual identity. center is the selected formula anchor in the containing coordinate system. At the top level it is a world-space point; inside a group it is local to that group.

source is a LaTeX mathematical snippet without surrounding dollar signs, \\( ... \\), or \\[ ... \\] delimiters. The selected mode supplies those delimiters. Formula source may contain carriage returns and newlines. It may also be empty. The constructor copies it into an immutable string.

The mode-to-typesetter mapping is:

Mode

latex-pict operation

'inline

tex-math

'display

tex-display-math

'display-environment

tex-real-display-math

The font-size value is measured in local world units before semantic scale is applied. The adapter asks latex-pict to typeset at its natural scale and then maps the selected document base of 10pt, 11pt, or 12pt to the requested world-unit size. When no standard size option is present, 10pt is assumed. Supplying more than one distinct standard size option is an error. Other document-class options and preamble commands may still change the formula’s visible metrics.

The complete visible height and width depend on the formula content. The constructor does not automatically separate two independent formula Visuals, so their rendered boxes can overlap when their anchors are placed too close together. Use visual-layout-box, visual-place-above, visual-place-below, or arrange-visuals-vertically when spacing must follow the actual rendered boxes.

preamble is inserted into the generated LaTeX document. The document-class-options and preview-options lists are passed in stored order. Their strings and preamble are copied into immutable storage. Option order is significant because a LaTeX document class or package may interpret options in order. The adapter passes these values and an extra typesetter scale of one explicitly, so process-wide latex-pict parameters do not silently change a formula Visual.

The alignment arguments select the left, center, or right horizontal point and the top, center, baseline, or bottom vertical point of the untransformed typeset Pict. That point is placed at center. Scale and rotation are then applied around the anchor.

Named parts in a formula-assembly can be styled with formula-style, formula-color, or formula-color-map. This is an assembly-level semantic operation: a bare latex-formula has no part namespace. The Pict and tagged-SVG adapters apply the selected colour at their own rendering boundaries rather than relying on a generic outer recolouring operation.

Generic lines, paths, and ordinary shape outlines use semantic axis ink by default; an explicit "black" remains literal black in every theme. Formula source is different: raw TeX and imported SVG can contain an author’s own black or multicolour paint, and the adapters cannot reliably distinguish that from implicit default ink without altering the artifact. They therefore preserve unstyled formula paint. Use the explicit formula styling operations with theme-foreground when a formula must follow a theme; selected formula parts continue to preserve all other source paint.

Rendering a nonempty formula requires the latex-pict package, a working pdflatex, Poppler, the requested document class, and every package named by the preamble. Model construction, scene sampling, and empty formula rendering do not run TeX. Exact output depends on those external tools and their installed versions. Formula source and preamble are trusted input; this library does not sandbox the TeX process.

58.8.1.1 Inspecting and Updating Formula Models🔗ℹ

procedure

(formula-visual? value) → boolean?

  value : any/c
Returns #t when value is a built-in LaTeX formula Visual.

procedure

(formula-visual-source visual) → string?

  visual : formula-visual?
Returns the immutable LaTeX source string without surrounding mathematical delimiters.

procedure

(formula-visual-mode visual) → formula-mode?

  visual : formula-visual?
Returns the stored formula display mode.

procedure

(formula-visual-font-size visual)

 → (and/c finite-real? positive?)
  visual : formula-visual?
Returns the unscaled semantic formula font size in local world units.

procedure

(formula-visual-preamble visual) → string?

  visual : formula-visual?
Returns the immutable additional LaTeX preamble string.

Returns the ordered document-class options. String options are immutable. Ordering is significant.

procedure

(formula-visual-preview-options visual)

 → (listof latex-option?)
  visual : formula-visual?
Returns the ordered options passed to the LaTeX Preview package by latex-pict. String options are immutable. The mode-specific option used by latex-pict is added by that package separately.

Returns the horizontal formula-anchor alignment.

Returns the vertical formula-anchor alignment.

procedure

(formula-visual-with-source visual source) → formula-visual?

  visual : formula-visual?
  source : string?
Returns a new formula Visual with source copied into immutable model storage. Identity, affine transform, opacity, mode, font size, preamble, ordered option lists, and alignment are preserved. The original Visual is unchanged. Multiline and empty source are accepted.

These model operations do not invoke TeX.

Examples:
> (define original (latex-formula "x^2" #:id 'power))
> (define revised (formula-visual-with-source original "x^3"))
> (formula-visual-source original)

"x^2"

> (formula-visual-source revised)

"x^3"

58.8.2 Tagged Formula Layouts🔗ℹ

struct

(struct formula-fragment (name source)
    #:transparent)
  name : symbol?
  source : string?
Represents one author-declared contiguous TeX fragment. name is the local part name in a tagged-formula; source must be a nonempty string. Names must be unique within each tagged formula.

Fragments are deliberately explicit. Animate does not parse arbitrary TeX into tokens, so a fragment must be a valid piece of the complete math expression and must produce visible ink.

procedure

(tagged-formula 
  #:id id 
  [#:center center 
  #:rotation rotation 
  #:scale scale 
  #:opacity opacity 
  #:mode mode 
  #:font-size font-size 
  #:preamble preamble 
  #:document-class-options document-class-options 
  #:color-map color-map] 
  fragment ...) 
 → formula-assembly-visual?
  id : symbol?
  center : vec2? = origin
  rotation : finite-real? = 0
  scale : scale-factor? = 1
  opacity : opacity? = 1
  mode : formula-mode? = 'display
  font-size : (and/c finite-real? positive?) = 1
  preamble : string? = ""
  document-class-options : (listof latex-option?) = '()
  color-map : (hash/c symbol? color-spec?) = (hash)
  fragment : formula-fragment?
Builds one full-layout formula from one or more formula-fragment values. Unlike formula-assembly, the fragments are typeset together. Their positions, ordinary TeX spacing, kerning, scripts, and alignment come from the complete formula rather than from manually supplied part positions.

Construction runs the external latex and dvisvgm executables once. It wraps every fragment in a dvisvgm SVG group, measures the group, and returns an ordinary formula assembly whose parts render as the resulting SVG fragments. Those SVG fragments are renderer-cached, so sampling or rendering animation frames does not run TeX again. Both executables must be available on PATH when this constructor is called.

All keyword options have the same validation and semantic meaning as for latex-formula, except that Preview-package options and per-fragment anchors are not applicable to a formula whose layout is computed as one unit. The returned assembly can be moved, rotated, scaled, faded, addressed through nested part paths, and used with the normal formula-correspondence operations.

color-map maps declared fragment names to semantic colours. It is applied after the complete TeX layout and SVG crops have been created, so it does not alter kerning, scripts, or measurements. Every key must name a declared fragment.

procedure

(math-tex #:id id 
  [#:center center 
  #:rotation rotation 
  #:scale scale 
  #:opacity opacity 
  #:mode mode 
  #:font-size font-size 
  #:preamble preamble 
  #:document-class-options document-class-options 
  #:color-map color-map 
  #:source-map source-map 
  #:parts parts] 
  source ...) 
 → formula-assembly-visual?
  id : symbol?
  center : vec2? = origin
  rotation : finite-real? = 0
  scale : scale-factor? = 1
  opacity : opacity? = 1
  mode : formula-mode? = 'display
  font-size : (and/c finite-real? positive?) = 1
  preamble : string? = ""
  document-class-options : (listof latex-option?) = '()
  color-map : (hash/c symbol? color-spec?) = (hash)
  source-map : (or/c 'none 'declared 'tokens) = 'tokens
  parts : (listof source-part?) = '()
  source : string?
Source-addressable construction for one complete formula. It accepts the same layout and color-map options as tagged-formula. Use tagged-formula when the author needs explicit stable part names without source queries.

math-tex records a canonical source string and a conservative token-to-rendered-part source map by default. Use formula-find or formula-source-select to query rendered source material by a literal string, regexp, source span, or occurrence. 'none is the explicit opt-out when no source queries are required. 'declared requires #:parts, a list of named source-part declarations; it maps only those author-declared ranges. The token scanner establishes safe TeX boundaries, not algebraic meaning or a complete TeX parse: user macros, category-code changes, and source that has no visible output may not be selectable.

procedure

(glyph-tex #:id id 
  [#:center center 
  #:rotation rotation 
  #:scale scale 
  #:opacity opacity 
  #:mode mode 
  #:font-size font-size 
  #:preamble preamble 
  #:document-class-options document-class-options 
  #:color-map color-map] 
  source ...) 
 → formula-assembly-visual?
  id : symbol?
  center : vec2? = origin
  rotation : finite-real? = 0
  scale : scale-factor? = 1
  opacity : opacity? = 1
  mode : formula-mode? = 'display
  font-size : (and/c finite-real? positive?) = 1
  preamble : string? = ""
  document-class-options : (listof latex-option?) = '()
  color-map : (hash/c symbol? color-spec?) = (hash)
  source : string?
Typesets one complete TeX expression and exposes each visible dvisvgm glyph leaf as a formula part named 'glyph-0, 'glyph-1, and so on, in painter order. The complete expression is still typeset as one unit, so its ordinary TeX spacing, kerning, and script placement are retained. Construction has the same external latex and dvisvgm requirements as tagged-formula.

The generated glyph parts retain the complete author TeX source, but their matching identity is the referenced dvisvgm path outline together with their typesetting options. Consequently, exact unchanged glyphs can match between two separately compiled expressions despite dvisvgm assigning different local font-definition ids on each compilation. Use tagged-formula or math-tex when several glyphs need one semantic identity: glyph leaves are not TeX tokens, a superscript or accent can contain several leaves, and repeated outlines match greedily in source order.

color-map maps generated names such as 'glyph-0 to semantic colours. Generated names are positional, so explicit tagged fragments are usually preferable for durable pedagogical styling.

58.8.3 Making latex-pict Available🔗ℹ

Use the same Racket installation for this library and for latex-pict. For example, to install the catalog package with Racket 9.3.0.2 on macOS:

"/Applications/Racket v9.3.0.2/bin/raco" pkg install \

  --auto \

  latex-pict

For a local checkout, link the checkout with that same raco executable:

"/Applications/Racket v9.3.0.2/bin/raco" pkg install \

  --auto \

  --link \

  "/Users/soegaard/Dropbox/GitHub/latex-pict"

A one-command alternative is to add the checkout root to PLTCOLLECTS:

PLTCOLLECTS="/Users/soegaard/Dropbox/GitHub/latex-pict:" \

  "/Applications/Racket v9.3.0.2/bin/racket" -c \

  examples/formula-visuals.rkt \

  frames/formula-visuals \

  formula-visuals.mp4

The trailing colon is significant. It keeps Racket’s ordinary collection paths after the added checkout. A package linked with one Racket installation is not automatically visible to another installation, so use matching racket and raco executables.