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.\endphfThe 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 aflm.pres.spanof the roleHIGHLIGHT_ROLEorCOMMENT_ROLE(aflm.pres.blockof that role for a cut part around a block placed among blocks), with the kind tokens<command>andannotator-<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 tokenMARK_CONTINUES_KINDwhen a cut part follows it andMARK_CONTINUED_KINDwhen one precedes it. The annotator’s initials are a margin decoration at the start of the annotation, holding a span of the roleINITIALS_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 thetextbackend: 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 initialsPhF. The text backend prints a highlight as[PhF] passage.- On the
htmlbackend, the feature’s stylesheetflm.annotations.style(html), which colors each annotation by its annotator’s number; the general rule and thetextbackend’s rule require it wherever they write an annotation. - On the
latex-renderedbackend, the definition pieceflm.latex.def.flmx.annotations(latex_rendered), which the same requirement brings into the style file. latex::LATEX_RULE(latex::AnnotationLatexRule), the default on thelatex-recomposedbackend: it writes the command back as the author wrote it, over the LaTeX packagephfcc, 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-recomposedbackend 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
AnnotationsFeatureandfeature— the feature, under a configuration or the default one.AnnotationsConfig,Annotator— the configuration;AnnotationsRenderOptions— the render option.AnnotationElement— the data of each element value ofANNOTATION.AnnotationParser,Form,form_of— the argument’s parser and the reading of an annotation’s form.AnnotationPiece,payload_readers— the continuation record of a cut part, and its reader for serialized trees.AnnotationRule,AnnotationTextRule— the general rule and thetextbackend’s rule;htmlandlatex— the rules of thehtmlandlatex-recomposedbackends.Unterminated— the one condition the feature reports.- The names:
FEATURE,ANNOTATION,TEXT_ARG,RULE,TEXT_RULE, the rolesHIGHLIGHT_ROLE,COMMENT_ROLE,INITIALS_ROLE, and the kind tokensannotator_kind,MARK_CONTINUES_KIND,MARK_CONTINUED_KIND.
Modules§
- html
- The stylesheet of the
annotationsfeature on thehtmlbackend,flm.annotations.style(stylesheet), and the markup it selects on. - latex
- The recomposition rule of the
annotationsfeature on thelatex-recomposedbackend: an annotation is written back as the author wrote it, over the LaTeX packagephfcc, which defines a reviewer’s commands. - latex_
rendered - The definition piece of the
annotationsfeature on thelatex-renderedbackend,flm.latex.def.flmx.annotations(piece).
Structs§
- Annotation
Element - The data that each element value of
ANNOTATIONcarries: the annotator whose command writes the annotation, and the annotator’s number, its position in the configuration counted from zero. - Annotation
Parser - 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 argumentTEXT_ARGof every annotator’s command with this parser. - Annotation
Piece - 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.
- Annotation
Rule - The implementation of the general rule
RULE, the default on every backend that has no rule of its own for an annotation. - Annotation
Text Rule - The implementation of the text backend’s rule,
TEXT_RULE, the default on that backend only. - Annotations
Config - The configuration of the
annotationsfeature: the annotators, in order. - Annotations
Feature - The
annotationsfeature (FlmFeature), constructed from anAnnotationsConfig: it declares one command per annotator and the lowering rules of an annotation. See the module documentation. - Annotations
Render Options - The render options of the
annotationsfeature: 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\endphfbefore 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_ofreads 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 anAnnotationElement. - 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. SeeMARK_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. WithMARK_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 theAnnotationParser. - TEXT_
RULE - The name of the lowering rule of the element
ANNOTATIONon thetextbackend,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
AnnotationsFeatureunder 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 nameANNOTATION.