symbols
The symbols rule converts (c), (r) and (tm) to the copyright, registered and trademark signs, between-number x to the multiplication sign, and +/- before a digit to a plus-minus sign.
symbols performs three narrow substitutions that look trivial and are easy to get wrong:
(c),(r)and(tm)become ©, ® and ™.- The letter
xbetween two numbers becomes the multiplication sign ×. +/-followed by a number becomes ±.
Each substitution is a literal match with adjacency guards, so code, hexadecimal literals and ordinary words are left alone. The rule is on by default, reads no locale data and behaves the same in every locale.
How it works #
The rule scans left to right and tries three cases, each keyed on a different first character, so they never compete.
Trademark signs #
The accepted spellings are listed explicitly: (c) and (C), (r) and (R), and (tm), (TM), (Tm), (tM). Nothing else matches, so (s), (a) and (x) are never touched. Three guards apply:
- Left side, for
(c)and(r)only. If the character before is a letter or digit,)or], or one of ©, ® or ™, nothing happens. This keepsf(c)andarr[i](c)intact.(tm)is exempt:Acme(tm)is how the sign is actually typed, sof(tm)does becomef™. - Right side. If a letter or digit follows directly, nothing happens.
(r)evolution,(c)ompilerand(s)heare the "optional first letter" idiom. - No nesting. If the character before is
(, nothing happens:((c))is left as it is.
Multiplication sign #
The rule reads a whole chain of numbers joined by the letter: digits, optional space, the letter, optional space, digits, and so on. The letters accepted are Latin x and X and Cyrillic х and Х. The Cyrillic pair is included because a Cyrillic х between digits looks identical to a Latin x and is a keyboard-layout slip.
A chain converts only if all of these hold:
- Spacing is symmetric and consistent. Either every
xhas a space on both sides or none has.3 x4is declined, and so is5x4 x 3. - The chain does not start directly after a letter (
H2x4,ax3) and does not end directly before a letter. The second guard rejects hexadecimal0x1F. - A hex literal such as
0x10(no spaces, Latinx, first number exactly0) is declined.
The whole chain converts in one pass, so 5x4x3 becomes 5×4×3 at once. The existing spaces are kept, character for character: a no-break space already in the text stays a no-break space.
Plus-minus #
Only the three-character sequence +/- converts, and only when a digit follows it, optionally after one space. +- alone is never converted, since it appears in diffs, ASCII tables and regular expressions. A +/- directly after [ (a regex character class) is skipped.
Examples #
Trademark signs, with the guards visible:
Input
Output
Notice that Acme(R) and f(c) stayed (a letter before a (r) or (c)), while Acme(TM) converted.
Adjacent signs: a (c) or (r) directly after another sign is declined, which keeps a second pass from changing anything, while (tm) is always converted:
Input
Output
Multiplication:
Input
Output
Only the first three chains converted. Each of the others is asymmetric, has no number on one side, or looks like hex or a name.
The Russian layout case, where the letter between the digits is Cyrillic:
Input
Output
Both alphabets convert, even in one chain. The nbsp rule has also bound см to the number.
German and French get the same sign. The spacing differences come from nbsp:
Input
Output
Plus-minus:
Input
Output
Only the first two converted. The regex class, the prose use and +- are untouched.
In markdown mode, code spans are skipped:
Input
Output
In html mode, <pre> and attributes are skipped:
Input
Output
Locale data #
None. The signs are the same code points in every locale, and the spacing around ×, ©, ® and ™ is not decided here. The rule only carries over whatever spacing the text already has.
Options #
symbols is on by default. To switch it off:
transform(text, { locale: 'en-US', rules: { symbols: false } })
All three substitutions go off together; there is no way to keep one and drop another.
Edge cases #
- Matching is by code point, with no case folding, so a Turkish process behaves like any other.
xas a word or variable (x = 5,the x axis,Malcolm X) has no number on both sides and stays.- An existing × ends a chain:
5×4x3becomes5×4×3. - A Cyrillic
хin a word, such asхорошо, is not touched: the rule needs ASCII digits on both sides and no letter next to the chain. - Digits are ASCII only.
(c)after an existing © (©(c)) is declined by the left-side guard, which is what keeps the rule stable on a second pass.- The plus-minus sign needs a digit after
+/-, so prose that names the characters is never rewritten. - Skipped regions are decided by the mode, not by this rule. In
textmode nothing is skipped, so(c)inside code is converted there.
Related #
- nbsp: spacing around ×, ©, ® and ™.
- Rule order
- Markdown skip list
- Modes overview
Normative text: spec/rules/symbols.md.