TextQuote and TextPosition representations on a defined source text, distinct from a generic reading-return note or cross-version anchoring guarantee.
Substantively revised October 21, 2026. Author interpretation, documented cases and hypothetical examples are distinguished below.
A highlighted phrase can survive an export while its location becomes wrong. The words still look familiar, the start and end numbers still look precise, and the receiving program selects a different substring. Precision in a record is useful only when both sides count the same thing in the same text representation.
Direct answer
Define the exact source text before constructing a passage selector. Record start-inclusive, end-exclusive code-point positions together with the selected text and enough adjacent context to inspect repeated occurrences. When JavaScript supplies UTF-16 offsets, convert them deliberately before using a code-point representation. Check the selected substring against the stored quote and reject a mismatch after an edit. These checks explain a selection in a fixed text stream; they do not implement a complete Web Annotation processor or a reliable resolver across changing documents.
Key takeaways
The chosen occurrence matters as much as the chosen words. Two identical phrases can require different positions and context. A quote-only lookup that returns the first occurrence can silently change the target of a comment intended for the second.
Offsets need named units. A supplementary Unicode character occupies one code point and two UTF-16 code units. If it precedes a selection, the numerical positions in a JavaScript string and a code-point array can differ even though both programs received the same text.
An unchanged quote does not prove an unchanged location. Inserting text before the target can invalidate every stored position while leaving the quoted phrase intact. A disagreement between position and quote is evidence to investigate, not a reason to accept whichever result appears convenient.
Definitions and relationships
A text representation is the particular ordered character stream against which the selection is measured. A source URL alone does not describe that stream. Plain text, extracted article text and serialized HTML can assign different positions to apparently similar passages.
A TextPositionSelector names a range using start and end positions. A TextQuoteSelector names selected text using an exact quote and, where supplied, immediately adjacent prefix and suffix. These terms come from the W3C Web Annotation specifications; the local checks below examine selected properties rather than validating a complete annotation document.
A code point is a Unicode value in the text sequence. A UTF-16 code unit is a storage and indexing unit used by JavaScript strings. A grapheme cluster can contain several code points. Choosing code-point coordinates therefore does not, by itself, establish that every possible range respects a reader's perceived character boundaries.
The problem: a comment arrives on the wrong occurrence
Consider a hypothetical annotation exporter for authorized research notes. A reviewer highlights the second occurrence of a repeated phrase and writes a comment about its surrounding sentence. The exporter sends the phrase and two numbers to another program, which reconstructs a highlight from those numbers.
If the receiver interprets the numbers using a different indexing convention, the visible result can shift. If it ignores the numbers and searches only for the phrase, it can attach the comment to the first occurrence instead. Neither fallback preserves the reviewer's intended target merely because it returns readable words.
The useful question is narrower than how to save better notes. What representation and selector evidence allow this particular export to identify the selected occurrence accurately? Answering it requires counting, slicing and testing ambiguity. A reading purpose or a reminder to return to the source cannot repair incompatible coordinates.
Root cause: the representation contract is implicit
An integer does not carry its counting convention. A field called start can mean bytes, UTF-16 units, code points or positions within a smaller extracted section. When the record omits that information, the receiving implementation must guess from its own language's convenient operations.
The source representation can also change before the record reaches the receiver. Removing markup, decoding entities, joining paragraphs or changing whitespace may be reasonable processing choices, but each choice can alter positions. Computing an offset before processing and applying it afterward mixes two coordinate spaces.
The repair is to settle the text stream first and then compute all selector evidence against it. Position, exact quote and context should describe one representation. If a later stage changes that representation, it must generate new evidence or explicitly reject the old coordinates rather than carrying their apparent precision forward.
Framework: the Passage Coordinate Agreement
The Passage Coordinate Agreement is the author's proposed method for inspecting a text selection export. Its components are Representation, Counting Unit, Occurrence Evidence and Mismatch Decision. It is a practical review method, not a new standard or a claim that a short example implements every Web Annotation requirement.
Representation identifies the exact logical-order text used for selection and the relevant source version. For a plain-text fixture, that can be the retained string itself. For a document extraction pipeline, the actual preprocessing choices must be specified and tested before positions are exported.
Counting Unit states how boundaries are measured and how the receiving runtime converts them. Do not label native JavaScript string indices as code-point positions without examining the text. A successful example containing only basic Latin characters can hide the mismatch because the two counts happen to agree there.
Occurrence Evidence retains the exact selected substring and adjacent context. It allows an inspector to compare the position-derived slice with the intended quote and examine repeated matches. Context can distinguish the two occurrences in the fixture below; that result is not a general uniqueness guarantee for arbitrary documents.
Mismatch Decision defines what happens when the evidence disagrees. The conservative local rule is to reject a stale positional selection and request a new selection from the correct representation. An automatic relocation system would need additional rules and tests; none is demonstrated by merely finding the same phrase elsewhere.
Framework example and application
For a selected phrase after a supplementary character, record the fixed text, its version, code-point boundaries and the quote with immediate context. Reproduce the substring using code-point slicing. Separately inspect the runtime's native indices to show whether a conversion was necessary.
Apply the method at the export boundary, before the receiving application displays a highlight as authoritative. The acceptance condition is not that some phrase was found. It is that the declared representation and coordinate interpretation reproduce the intended occurrence and that the quote agrees with that range.
Three documented mechanisms
Example 1: the W3C data model defines the text range
The Web Annotation Data Model describes TextPositionSelector boundaries with the start included and end excluded. Its text selection rules use Unicode code points in logical order and require a consistent normalized text representation before counting. The model also warns that positional selection is brittle when content changes. These are specification requirements and cautions, rather than results from the local experiment. [S1]
The operational implication is to choose the processed stream before generating offsets. The study below starts with original plain text containing no tags or character entities and preserves that sequence. It does not test an HTML normalization pipeline, apply compatibility normalization or claim that a raw browser selection already satisfies the model.
Example 2: the vocabulary separates quote and position properties
The Web Annotation Vocabulary identifies start and end for TextPositionSelector and exact text for TextQuoteSelector, with prefix and suffix as recommended quote context. These distinct properties represent different evidence about a target. A quote with surrounding text can be inspected for ambiguity; numerical boundaries describe a location in a particular stream. [S2]
Keeping both forms in an inspection record makes disagreement observable. This article does not prescribe a complete JSON-LD annotation or assume that putting two selector objects in a container automatically defines their combined semantics. Applications still need to implement and validate their chosen annotation structure.
Example 3: JavaScript string length counts UTF-16 units
MDN documents JavaScript string length as a count of UTF-16 code units. String iteration can instead traverse code points, while grapheme counting is a separate operation. That distinction explains why native string slicing and slicing an array produced by Array.from can interpret the same integer boundaries differently. [S3]
The local Node execution below checks one supplementary character before an otherwise simple phrase. It does not demonstrate every Unicode sequence, browser text selection API or grapheme boundary. A runtime result supports the operation that actually ran, not an untested promise of complete international text handling.
Case study: selecting the second repeated phrase
This is an executed experiment using an original invented text fixture, not a client outcome or an observed improvement in research productivity. Python 3.11.9 and Node 24.15.0 processed the same string. The retained fixture begins with a compass character, followed by First: keep this; Second: keep this.
The target was the second keep this. In Python's code-point indexing, its start was 28 and its end was 37. The resulting half-open slice contained nine code points and exactly reproduced the intended phrase. The immediately preceding eight characters were Second followed by a colon and space; the immediately following character was a period.
Searching for the quote alone found two occurrences. Applying the chosen adjacent prefix and suffix selected the second occurrence in this fixture. That narrow result shows how context can expose a difference that the quoted words alone do not express. It does not establish a universal amount of context sufficient for every document.
The coordinate mismatch control
Node reported 39 UTF-16 units for the complete string, while code-point iteration and Python both counted 38 code points. The leading supplementary compass character accounts for the difference. No character was removed, and no source edit was required to produce two different numerical coordinate systems.
Node's native index for the second phrase was 29, with an end of 38. Its native slice using those native unit offsets correctly returned keep this. Passing the Python code-point boundaries 28 and 37 directly to JavaScript string slice instead returned a leading space followed by keep thi.
Converting the string to Array.from(text), slicing that array at 28 and 37 and joining the result returned the intended phrase. This checks one explicit conversion path for the retained fixture. It does not mean that every API consuming offsets accepts an array's code-point coordinates or that this conversion repairs offsets computed against different text.
The stale position control
The experiment then inserted New followed by a period and space before the original string. The original code-point range 28 through 37 now returned ond: keep. The selected quote still occurred twice in the edited text, so confirming that the phrase existed somewhere would not have detected the incorrect positional target.
Because the insertion was deliberately constructed and its five-code-point length was known, the experiment also checked the corresponding shifted range. That check reproduced the intended quote. It is an experimental control with a known edit, not a deployed relocation algorithm that can infer arbitrary changes from an old annotation.
All 23 assertions passed. They covered the repeated quote, adjacent context, half-open range, runtime counting difference, incorrect and correct slicing operations, byte-count distinction and the explicit insertion control. The retained script and report make those particular findings reproducible; no browser, document fetch or user interface was exercised.
Failure example: readable text can conceal a wrong target
The incorrect JavaScript slice looks close to the desired phrase. A display that trims leading spaces or presents only a short excerpt might make the defect harder to notice. The exact comparison catches a disagreement that a casual visual scan could overlook, which is why the comparison should precede presentation cleanup.
The edited-text result illustrates a different failure. The coordinates remain valid integers within the new string, yet they describe a different substring. Bounds checking alone would accept them. Correctness requires agreement with the declared source representation and the intended text, not merely a range that avoids an exception.
Quote matching also has a limit. If the same phrase and chosen surrounding context recur, the context check can remain ambiguous. The appropriate response is to preserve that ambiguity or request a more precise selection. Choosing the first match silently would introduce an occurrence decision that the stored evidence did not justify.
Common mistakes in selector exports
One mistake is testing only text in which every character occupies one UTF-16 unit. Such a test can pass while leaving the conversion assumption unexamined. Include a supplementary character before the selection so that the chosen runtime operations must reveal which unit they count.
Another mistake is computing positions in markup and applying them to extracted prose. Tag removal and entity interpretation can change the measured sequence. Decide whether the target representation is source markup, a specified text extraction or another stream, and generate the selector after the relevant processing is complete.
A third mistake is treating prefix and suffix as a guaranteed global identifier. They are evidence for distinguishing occurrences, and their effectiveness depends on the actual text. Check the number of resulting candidates rather than assuming that a fixed context length always creates a unique target.
Finally, avoid interpreting code-point safety as complete character safety. A boundary can be a valid code-point boundary while splitting a grapheme cluster. The simple target in the experiment does not exercise that problem. A product promising grapheme-respecting selection needs additional processing and suitable fixtures.
Counterargument: why retain positions when quotes are easier?
For a short, fixed note with a unique phrase, searching for the quote can be sufficient for a particular local task. Positions add a representation dependency and require conversion discipline. There is no reason to claim every saved note needs a complex export format or a full annotation ecosystem.
The tradeoff changes when occurrence identity matters or when another program must reconstruct a precise range. A quote can recur, and context can recur as well. Positions provide direct location evidence within a known representation, while the quote supplies a useful check on what that location selects.
The costs are extra metadata, explicit preprocessing and a defined failure path after edits. Retain the evidence needed by the task and describe its limits. A small honest selector contract is more useful than promising seamless cross-version anchoring without an implemented and evaluated resolver.
Action plan: inspect one real export boundary
Start with an authorized plain-text sample and identify the exact stream against which the export computes offsets. Record the source version and any preprocessing. If the implementation cannot explain whether it counts before or after transformation, resolve that uncertainty before evaluating its selector output.
Select a repeated phrase after a supplementary character. Retain the intended occurrence, exact quote and adjacent context, then compare the exported boundaries with the receiving runtime's actual slicing behavior. Include the incorrect direct interpretation as a negative control rather than testing only the successful path.
Insert text before the selection in a separate copy and confirm that the old range is rejected when its slice disagrees with the quote. Do not silently update the original evidence to make the test pass. Record the mismatch and require the selection or relocation process appropriate to the changed representation.
Finally, document which checks remain outside the result. A plain-text exporter test does not establish browser DOM behavior, accessibility, permission to redistribute quotations, grapheme segmentation or complete JSON-LD conformance. Add those evaluations only when the product actually depends on those additional capabilities.
FAQ: coordinates, context and changed sources
What does start-inclusive, end-exclusive mean?
The character at start belongs to the range, while the character at end does not. In the fixture, start 28 and end 37 select nine code points. The period immediately following the selected phrase is outside that range.
Why do Python and JavaScript return different positions?
The experiment compares Python string code-point indexing with native JavaScript UTF-16 indexing. A supplementary character before the target occupies one code point but two UTF-16 units. Both positions can be correct within their own counting conventions while being incompatible without conversion.
Does Array.from solve every text selection problem?
No. It provides a code-point sequence for the demonstrated string operation. It does not choose a source version, extract text from a DOM, respect every grapheme boundary or translate positions computed against a different representation. Those are separate parts of a product's selection contract.
Why keep the quote if positions are already present?
The quote lets an inspector check what the range actually selects. The edited-text control produces a range inside the string that returns the wrong substring. Comparing that result with the stored quote reveals a problem that numerical bounds checking alone would miss.
Is the exact quote a unique identifier?
It is not necessarily unique. The fixture deliberately contains keep this twice. The particular prefix and suffix distinguish the target there, but another document could repeat the surrounding context too. An implementation must inspect ambiguity rather than infer uniqueness from the presence of context fields.
Are prefix and suffix arbitrary descriptive labels?
For the quote selector discussed here, they are adjacent text before and after the selected passage. They are not a section title or a researcher's summary of the passage. Preserving their adjacency makes it possible to compare the recorded context with candidate occurrences.
Should I normalize Unicode before selecting?
Define the text processing required by the representation and apply it consistently before counting. This experiment retains an original plain-text sequence and applies no compatibility normalization. It does not prescribe a Unicode normalization algorithm or show that changing normalization after selection preserves old offsets.
Does the experiment implement Web Annotation completely?
No. It examines selected text selector properties and coordinate behavior. A complete implementation must also address the annotation structure and applicable specification requirements. The local inspection record is not presented as a validated JSON-LD annotation or an interoperability certification.
Can I use offsets measured in UTF-8 bytes?
Only if the consuming operation explicitly expects byte coordinates for that representation. The fixture's UTF-8 byte count differs from its code-point count. Relabeling byte offsets as text code-point positions does not convert them, and a native string slice may interpret them incorrectly.
Will the saved positions survive an insertion?
They may change their target. Inserting five code points before the fixture shifts the intended selection, while the old range remains a valid range elsewhere in the text. The study detects that mismatch; it does not claim to recover from unknown edits automatically.
Why not find the first matching phrase after every edit?
That rule can attach the annotation to a different occurrence. The intended phrase is the second copy in the original fixture. A first-match fallback would make a new occurrence choice without evidence that it preserves the original target, even when the words are identical.
Are code points the same as visible characters?
Not in every case. A perceived character can contain multiple code points. This study uses a simple selected phrase and does not test grapheme segmentation. A selection interface claiming to preserve complete perceived characters needs to evaluate that additional boundary rule explicitly.
Was a browser highlight tested?
No browser was used. Python and Node processed retained plain text. The report supports those runtime operations only. DOM nodes, browser selection APIs, rendering order and user interface behavior require their own actual tests before an implementation can claim equivalent results.
Does context prove that a quoted claim is true?
No. Context helps describe the selected occurrence. It does not evaluate the passage's factual accuracy, relevance or permission for reuse. A correctly anchored false statement is still false, and an exact quotation can still require substantive source review.
What should happen when position and quote disagree?
Reject the positional selection for the current representation and inspect the source version and counting convention. A product may offer an explicit relocation workflow, but that workflow needs its own acceptance criteria. The conservative experiment reports a mismatch without pretending to have inferred the correct new target.
Recommended books
Unicode Demystified by Richard Gillam, published by Addison-Wesley Professional in September 2002, offers historical background on Unicode representation. Its age matters: use the current specifications and actual runtime documentation for present behavior. The recommendation concerns its subject and verified publisher metadata, not a claim that the full book was read for this experiment.
Designing Interfaces, third edition, by Jenifer Tidwell, Charles Brewer and Aynne Valencia is relevant when a product must explain a failed or ambiguous selection to a person. Treat that recommendation as interface design context rather than evidence for the numerical results. Official metadata was verified in the preceding research; a later publisher fetch timed out and adds no new verification.
Data and Reality, third edition, by William Kent with commentary by Steve Hoberman supplies broader context for distinguishing a represented object from its description. That is useful when deciding whether a selector names words, an occurrence or a versioned range. Its publisher record confirms the edition and attribution; it does not validate this selector implementation.
Further exploration
Compare this selection task with regex extraction: a regex operation generates candidate match spans, whereas this article represents an already chosen passage and inspects its coordinate agreement. The boundaries can look similar while the decisions producing them differ. Neither operation establishes the truth of the text it identifies.
For reading continuity, an intentional note about why to return to a passage can still be useful. That is a different problem from constructing compatible selector coordinates. Keep the reading question and the technical range evidence distinct so that a clear research purpose does not conceal an incorrectly reconstructed highlight.
The next implementation step is to test the actual representation your exporter consumes. If that representation is extracted document text, retain the extraction rules and use fixtures that exercise them. If source revisions must be supported, evaluate the proposed relocation behavior separately instead of extending this fixed-text experiment beyond what it demonstrates.
Primary evidence sources
- [S1] TextQuote exact/prefix/suffix and codepoint/logicalorder requirement; TextPosition startincluded endexcluded actually read
- [S2] TextQuoteSelector exact required with prefix/suffix to distinguish repeated text actually read
- [S3] UTF16unit length versus codepoints and iterator examples actually read
Related concepts: systems thinking, wealth structure, and the survival loop. Read the editorial policy and citation guide.