Skip to main content

Module annotations

Module annotations 

Source
Expand description

The annotations feature: a reviewer’s marks in a document, passages highlighted and remarks written into the text, under commands that a host configures, one per reviewer.

§What an author writes

An annotator is one reviewer, configured with a command name and optional initials (Annotator, AnnotationsConfig). The annotators are numbered from zero in configuration order, and an output can give each number its own color. The default configuration declares no annotator, and the feature then declares no command: \phf is an unknown command until a host configures an annotator whose command is phf.

Each annotator’s command writes two kinds of annotation:

  • a highlight, a passage the annotator marks, which stays part of the text: written \phf{…}, or \phf … \endphf;
  • a comment, a remark the annotator writes into the text, which is not part of it: written \phf[…]. (A comment in this sense is a reviewer’s remark, not a source comment written with %.)
The result \phf{holds in every case}, as \phf[cite the lemma here] shown.
\phf The second form needs no braces, which helps
with a long passage.\endphf

The command takes one argument, read by the feature’s own parser (AnnotationParser), which chooses the form by what follows the command (past any whitespace and source comments): a { begins a braced group, a [ a bracketed group, and anything else begins a passage that ends at \endphf (end followed by the command’s name). The argument holds inline content or paragraphs, as written. \phf{x}[y] is a highlight of x followed by the text [y]. The function form_of reads which form an annotation was written in. The guide for authors describes annotations under Annotations.

An annotation never becomes a block that holds paragraphs. A blank line inside it is a paragraph break of the text around it, and the annotation continues in the next paragraph; a list inside it is a block of the text around it, still part of the annotation (a cut part around that block, see below), and a displayed formula inside it stays in the inline content the annotation spans. The annotator’s initials are shown at the start of the annotation only.

§What the feature provides to the pipeline

The element. Every annotator’s command is one element value of the element type ANNOTATION (flm.annotations.annotation), carrying an AnnotationElement: a macro with one argument, TEXT_ARG, declared in text mode.

Cut parts. The element is block-transparent: its content is laid out as if it were written directly in the content around it (block-transparent elements). Before any paragraph is built, the block-structure pass (blocks) cuts an annotation whose argument crosses a paragraph break or holds a block into cut parts: one node of the annotation’s element around each stretch of inline content between paragraph breaks and blocks, and one around each block. Each cut part carries an AnnotationPiece record, its continuation record, which says which cut part of how many it is. The lowering rules read it to show the initials on the first cut part only, and the text backend’s rule reads it to open a comment’s bracket on the first cut part and close it on the last.

Lowering rules. A lowering rule (LoweringRule) says how an element becomes output on a backend. The feature registers these rules. A rule marked as the default for one backend ranks above a rule marked as the default everywhere (DefaultMark):

  • RULE (AnnotationRule), the default on every backend that has no rule of its own for an annotation: an annotation, or a cut part of one, lowers to a flm.pres.span of the role HIGHLIGHT_ROLE or COMMENT_ROLE (a flm.pres.block of that role for a cut part around a block placed among blocks), with the kind tokens <command> and annotator-<n> (annotator_kind). A role is a feature-owned dotted name on a presentation payload that says what a container is, and kind tokens classify it further (payload). A cut part also carries the kind token MARK_CONTINUES_KIND when a cut part follows it and MARK_CONTINUED_KIND when one precedes it. The annotator’s initials are a margin decoration at the start of the annotation, holding a span of the role INITIALS_ROLE; a decoration is a node that the lowering driver moves out of the content into an attached slot of the enclosing presentation node (Decoration).
  • TEXT_RULE (AnnotationTextRule), the default on the text backend: it lowers an annotation as the general rule does, except that a comment is written with its brackets and initials as text and no decoration: [PhF: remark] for an annotator with the initials PhF. The text backend prints a highlight as [PhF] passage.
  • On the html backend, the feature’s stylesheet flm.annotations.style (html), which colors each annotation by its annotator’s number; the general rule and the text backend’s rule require it wherever they write an annotation.
  • On the latex-rendered backend, the definition piece flm.latex.def.flmx.annotations (latex_rendered), which the same requirement brings into the style file.
  • latex::LATEX_RULE (latex::AnnotationLatexRule), the default on the latex-recomposed backend: it writes the command back as the author wrote it, over the LaTeX package phfcc, which makes each annotator’s command (latex).

Settings. The feature’s configuration, AnnotationsConfig, is the value the feature is constructed from; it is fixed when the registry is built (configuration), because the commands are part of the language. Written as data, its settings key annotators maps each command name to the annotator’s other fields, and a host that combines several sources of settings combines that map one annotator at a time. The feature feeds the configuration into the registry digest, the number that changes whenever something about the registry that can change what processing produces changes (FeatureBuilder::digest_input); AnnotationsConfig::digest_bytes gives the bytes. The feature also declares one option type, AnnotationsRenderOptions, set per render request: when its field hidden is true, every rule leaves every annotation out of the output, for a clean copy: a highlight is shown as its passage alone and a comment as nothing (the recomposed LaTeX keeps the paragraph breaks a comment held).

§Errors

A passage opened by \phf and not closed by \endphf is reported as Unterminated (flm.annotations.unterminated) while the document is parsed. An unknown command (a stray \endphf, or \phf with no annotator configured) and an unclosed group are reported by the language itself.

§Interactions with other features

  • Block structure. The element carries the block-transparent aspect (BlockTransparent) and a block role per occurrence (BlockRoleAspect); the block-structure pass (blocks) cuts it into cut parts.
  • Text of a title. The element carries the aspect ApartFromText: a comment’s remark is not part of the text around it, so that reading the plain text of a run (for example to give an unlabeled heading an identifier from its title) leaves the remark out. A highlight’s passage is part of the text.
  • Decorations. The initials are a margin decoration (flm.pres.deco.margin); each backend writes it as it writes every margin decoration.
  • The latex-recomposed backend lowers the tree before the block-structure pass, so an annotation reaches its rule uncut and is written back as one invocation (latex).
  • The standard features. The standard features include the feature under the configuration StdlibConfig::annotations.

§Items

Modules§

html
The stylesheet of the annotations feature on the html backend, flm.annotations.style (stylesheet), and the markup it selects on.
latex
The recomposition rule of the annotations feature on the latex-recomposed backend: an annotation is written back as the author wrote it, over the LaTeX package phfcc, which defines a reviewer’s commands.
latex_rendered
The definition piece of the annotations feature on the latex-rendered backend, flm.latex.def.flmx.annotations (piece).

Structs§

AnnotationElement
The data that each element value of ANNOTATION carries: the annotator whose command writes the annotation, and the annotator’s number, its position in the configuration counted from zero.
AnnotationParser
The parser of an annotator’s one argument: a {…} group, a […] group, or the passage up to the annotator’s closing command, chosen by the first character after the command and any whitespace and source comments that follow it. The feature declares the argument TEXT_ARG of every annotator’s command with this parser.
AnnotationPiece
The continuation record a cut part of an annotation carries: which cut made it, its rank among the cut parts of that cut, and how many cut parts the cut made.
AnnotationRule
The implementation of the general rule RULE, the default on every backend that has no rule of its own for an annotation.
AnnotationTextRule
The implementation of the text backend’s rule, TEXT_RULE, the default on that backend only.
AnnotationsConfig
The configuration of the annotations feature: the annotators, in order.
AnnotationsFeature
The annotations feature (FlmFeature), constructed from an AnnotationsConfig: it declares one command per annotator and the lowering rules of an annotation. See the module documentation.
AnnotationsRenderOptions
The render options of the annotations feature: an option type whose values are set on a render request (crate::model::options), in the plan request’s overrides (Overrides), as the example shows.
Annotator
One annotator: a reviewer who highlights passages and writes remarks in a document, with the command they write and the initials shown at the start of each of their annotations.
Unterminated
Condition flm.annotations.unterminated, an Error: a passage opened by an annotator’s command in its third form, \phf …, is not closed by the closing command \endphf before the input ends, or before the group or environment enclosing the annotation ends. Reported over the passage read. Recovery: the passage is what was read up to there, highlighted as if it had been closed.

Enums§

Form
The kind of an annotation, highlight or comment, as form_of reads it from the way its argument was written.

Constants§

ANNOTATION
The element type of an annotation, flm.annotations.annotation: one element value per configured annotator, each carrying an AnnotationElement.
COMMENT_ROLE
The role of the span or block a comment is staged as, flm.annotations.comment.
FEATURE
The feature’s registered name, annotations.
HIGHLIGHT_ROLE
The role of the span or block a highlight is staged as, flm.annotations.highlight.
INITIALS_ROLE
The role of the span that holds an annotator’s initials inside the margin decoration at the start of a highlight or a comment, flm.annotations.initials.
MARK_CONTINUED_KIND
The kind token mark-continued, carried by every cut part of a cut annotation except the first: the annotation began in an earlier cut part. See MARK_CONTINUES_KIND.
MARK_CONTINUES_KIND
The kind token mark-continues, carried by every cut part of a cut annotation except the last: the annotation continues in a later cut part. With MARK_CONTINUED_KIND, it lets a stylesheet draw what opens an annotation on its first cut part only and what closes it on its last cut part only. An annotation that was not cut carries neither token.
RULE
The name of the general lowering rule of the element ANNOTATION, flm.annotations.annotation.lower.default (AnnotationRule), the default on every backend.
TEXT_ARG
The name of an annotation’s one argument, text: the highlighted passage or the written remark, read by the AnnotationParser.
TEXT_RULE
The name of the lowering rule of the element ANNOTATION on the text backend, flm.annotations.annotation.lower.text (AnnotationTextRule), which writes a comment’s brackets and initials as text.

Functions§

annotator_kind
Returns the kind token of the annotator numbered number, annotator-<n>: the second kind token of every annotation’s span or block and of its initials’ span, after the command’s name. A stylesheet selects an annotator’s color by this token.
feature
Returns the AnnotationsFeature under the default configuration (no annotator, so no command), ready to be listed in a package entry.
form_of
Returns the form of the annotation node (a node of an annotator’s command, or a cut part of one), read from the opening delimiter that its argument’s group recorded: [ makes a comment, and { or no delimiter at all (the passage closed by \endphf) a highlight.
payload_readers
Returns the payload readers of the feature: one, which reads back the continuation records of cut parts (AnnotationPiece), registered under the element’s name ANNOTATION.