Template:Unichar/doc

This template produces a formatted description of a Unicode character, to be used inline or otherwise with regular text.
 * The character is about intellectual property.
 * The character is about intellectual property.

Usage
The template takes the Unicode hexadecimal code point value as input. Thus, for example,  →.

This template produces a formatted description of a Unicode character, to be used in-line with regular text. It follows the standard Unicode presentation of a character, using the "U+" prefix for displaying the hex code point, followed by its glyph, then optionally by the character name, using Unicode's inline formatting recommendation. In running text such as the Unicode Standard, Wikipedia, or other rich-text environments, the character name is preferredly displayed in. (The all-caps presentation is mainly designed for plain-text environments.)

The hexadecimal value is required (e.g. A9), other input is optional. The actual glyph is rendered using a font that contains the character. This can be set to something more specific, e.g. to language- or IPA-specific fonts. To show the glyph, the font character can be overridden with an image. A wikilink to an article on the character or set of characters, and another to the article Unicode can be created. It is also possible to add (bracketed like this), the calculated decimal value, HTML character codes, and a custom note.

Some special code points are given extra care, like control and space characters. These are automatically detected by the  sub-template.

Examples



 * → – combined with a dotted circle
 * → –  combined with  a dotted circle
 * → – combined with a dotted circle
 * → –  combined with  a dotted circle
 * → –  combined with  a dotted circle

Parameters
The blank template, with all parameters, is as follows:

Inline version:


 * First unnamed parameter or 1= Required. The hexadecimal value of the code point, e.g. 00A9.
 * Notes: The parameter accepts input like A9, a9 and 00A9 as hexadecimal value. Decimal values are not detected being decimal, and will give unexpected results.
 * Second unnamed parameter (The canonical name is fetched from Wikidata, there is no longer any need to specify it manually. If supplied, it is ignored. )
 * nlink=  Optional wikilink target. Name of the Wikipedia page that will be linked to. If used, the Unicode name (second parameter) has a wikilink to the article.
 * &rarr;
 * Notes:
 * The name of the page is case-sensitive as with all Wikipedia pages.
 * It is possible to give a Wiktionary page here, using the syntax nlink=wikt:, which may be appropriate if there is no suitable Wikipedia article. For example:
 * &rarr;
 * When used without a name (i.e., nlink, blank with no value), the link points to the character itself except when that causes a problem with WP:NCTR in which case the name of the character is used or an error is produced if no such name exists (see ).
 * &rarr; is equivalent to.


 * ulink Optional. Creates a wikilink from the U+ prefix. When used without a name (i.e., ulink, blank with no value), the article Unicode is used as the default value in the output: U+ producing U+. This only needs to change if you have a reason to link elsewhere than Unicode, e.g. to an article on a subset of Unicode characters.
 * html= Optional. Adds the HTML character reference to the text, like &amp;#160; in the bracketed note. If a named character reference exists, like "&amp;nbsp;", that is added too. In the latter case, you do not need to add the values manually, just add html, blank.
 * use= Optional. Sets the font-hinting template to get the glyph, since the character may not be present in a regular browser font. Default is, other options are , and.
 * use2= Optional. When setting lang or script, use2 should be used to set the language (e.g. fr) or the script (e.g. Cyrs). A glyph may still not show as expected due to browser effects. For a detailed description, see each template's documentation.
 * &rarr;
 * image= Optional. Allows for a graphic image file to represent the glyph; overrides the font completely. The filename should include the extension (like .svg or .png ), but the prefix File:.
 * cwith= Optional. The only valid content is ◌ or (or its HTML code, &amp;#x25CC;). This parameter is useful when the Unicode character is (such as a combining diacritic). Using ◌, the character will be combined with the placeholder symbol,.
 * without cwith:
 * &rarr;
 * cwith with dotted circle:
 * &rarr; or
 * &rarr;
 * Note that cwith=◌◌ does not provide the desired result if the intention is to display a diacritic that spans two characters (such as those in the range U+035C to U+0362): the diacritic will be offset. In such cases, editors must emulate the template output by hand, because the correct HTML sequence is "first-character + combining-diacritic + second-character". Thus, for example, to show the combining double tilde U+0360, write U+0360 &#x25cc;&#x0360;&#x25cc; then (in small), COMBINING DOUBLE TILDE. This produces U+0360 &#x25cc;&#x0360;&#x25cc; COMBINING DOUBLE TILDE.
 * Use of any other character except dotted circle as input to cwith is deprecated; this restriction is not currently enforced but if any other character is used, the output (grapheme and description) is at best misleading.
 * size= Optional. Can be used to set the size of the glyph. The default value is 125% . For the font, all CSS font-size style inputs are accepted: 7px, 150% , 2em , larger.
 * For example,  &rarr;
 * When using an image (file) instead of a font, this size can only accept sizes in px like 12px . Default for images is 10px.
 * name = . Optional; if used, the only permitted content is none. This parameter is provided for the rare cases where only the code-point and the corresponding character are wanted.
 * For example, produces.
 * alias = . Optional; if used, the only permitted content is yes. The purpose of this parameter is to handle the very rare cases where the Unicode Consortium has identified that a name is seriously defective and misleading, or has a serious typographical error, and has defined a formal alias that applications are encouraged to use in place of the official character name. (See Unicode for details.)
 * For example, U+A015 has the formal alias . Thus, rather than  &rarr;, the style  &rarr;  is preferred in most contexts.

Produces:

Presentation effects
Since this template is aimed at presenting a formatted, inline description, some effects are introduced to sustain this target.
 * Showing space characters: All space characters (those with General Category: Zs) are presented with a light-blue background, to show their actual presence and width:.
 * Incidentally, the regular space is replaced with   (NBSP) to prevent wiki-markup deleting it as repeated spaces.
 * Removing formatting characters: Formatting characters (those with General Category: Cf, Zl and Zp) are removed from the output. By definition, formatting characters have no glyph. By removing them they cannot have a formatting effect.
 * Exception: five Arabic Cf/formatting number markings U+0600..U+0603 and U+60DD, are shown. While Cf formatting characters usually have no glyph, these five have. By internally adding "(visible)" to the category, these characters are shown.
 * Removing whitespace: The template removes formatting code and surrounding whitespace from the input. A &lt;Return&gt; in the Name-input (possibly unintended) would frustrate the in-line behaviour expectation.
 * Showing a label like &lt;control-0007&gt;: Unicode states that a code point has no name when it is one of these: a control character, a private use character, a surrogate, a not assigned code point (reserved), or a non-character. These code points instead should be referred to by using a "Code Point Label", such as &lt;private-use&gt; or &lt;private-use-E000>. In this situation, this template replaces the glyph with that label. This way, the correct presentation wins it over Unicode-usage to the letter of the law.
 * "Control" general category=Cc:  or
 * "Surrogate" general category=Cs:  or
 * "Private Use": general category=Co:  or
 * "Not a character" (minus the reserved code points, see below): general category=Cn:,   or

The second parameter (Unicode name) is not presented, since it cannot exist. It is possible to create a link to an article.
 * Note: A &lt;reserved> (unassigned) code point cannot be detected yet, and so is not presented with this label. These code points too are given Cn category.
 * (Background on <>-labels: A Name can never have <>-brackets at all. These rules prevent mixing up a name with an actual control-character. So it will not happen that a bell rings when a page is opened that contains a Name of U+0007).

Possible errors

 * The template produces an when 1 (or first unnamed parameter), the hex value, is missing, empty, or invalid.


 * A non-hexadecimal input like 00G9 produces an error (because G or g is not hexadecimal).
 * Do not add the U+ prefix, as in U+00A9. It will not be recognised.
 * The glyph may be overruled and changed into a like &lt;control-0007&gt; . These characters have no Unicode name. An nlink will be directly to the article (entered in a form like Bell signal). A blank value of just undefined cannot work for &lt;label-hhhh&gt; characters (there is no character name at all to make into a link). This produces an error.
 * A decimal-value input like 98 will be read as being hexadecimal value 0098 . There is that the template can detect you intended to enter 9810=6216 . No warning is issued, and the wrong character, U+009816, will be shown ( U+0062 ).
 * The alias= cannot be used to create an unofficial alias.
 * If alias=yes is used but the code point does not have an official alias, no name whatever will be displayed.
 * The text provided in nlink= should be the normal name of an article. Do not type it in all caps as a red link will result.

Technical notes
The string "unichar" is used only in English Wikipedia, as a name for this template. It has no meaning outside this context.

The template uses these subtemplates:
 * unichar/main Accepts all the input from . Calls several subtemplates to produce the textstrings, and then strings them together. Also checks for the error non-hex input.
 * unichar/ulink Creates a piped link for the U+ prefix.
 * unichar/gc Determines the Unicode general category, when this category is special (like, for control characters).
 * unichar/glyph For rendering the glyph by font. Accepts image, which overrides the font. Also processes use, use2, size, cwith.
 * unichar/name Produces the formatted name of the character in . Accepts the nlink to create a piped wikilink to an article. When the general category (gc) is special, the name will change into a &lt;label-hhhh&gt;.
 * unichar/notes Shows notes in parentheses (round brackets): HTML (from html named entity like &amp;nbsp; if that exists, using ); and the free-text note.
 * Using the main template as an easy-input feature, there are few calculations done (actually only two hex2dec), and allows for adding default values not too deep in the templates.
 * The value  is used internally to pass through a non-defined input parameter. This value is correct when about the Unicode name, because it cannot have the characters <##>, and so salted is the right word (meaning uninhibitable). For ease of code maintenance, it is used in various places in the code.


 * Named entities for : &rarr;

Issues

 * Unassigned code points, to be labelled &lt;reserved&gt;, cannot be detected.
 * When using use-script, then use2 needs lowercase (e.g. 0485, Cyrs or cyrs)
 * When using for one of the RTL formatting marks, its effect may break out of the template (text following the template goes RTL, too). As it is now, this requires extra code.

TemplateData
{	"params": { "1": {			"label": "Hex value", "description": "Hexadecimal unicode codepoint", "example": "031A", "type": "string", "required": true },		"2": {			"label": "Character name", "description": "The canonical name is fetched from Wikidata, there is no longer any need to specify it manually. If supplied, it is ignored.", "example": "COMBINING LEFT ANGLE ABOVE", "type": "string", "deprecated": true },		"ulink": { "example": "Phonetic symbols in Unicode", "type": "line", "description": "Add link to the Unicode HEX code point" },		"image": {}, "cwith": { "type": "string", "description": "(for combing characters only) add the following character before this combining character:", "example": "◌", "suggestedvalues": [ "◌"			]		},		"size": { "description": "Relative size of rendered character", "example": "200%", "type": "string" },		"use": { "type": "string" },		"use2": { "type": "string" },		"nlink": { "type": "string", "description": "Add link to the Unicode character name" },		"note": { "type": "line" },		"html": { "label": "HTML code", "description": "When present, shows HTML named entity", "example": "html= shows \"&copy;\"", "type": "string" },		"alias": { "suggestedvalues": [ "yes" ]		},		"name": { "suggestedvalues": [ "none" ],			"description": "Hide the name of the character" }	},	"description": "Formats a Unicode character description inline.", "format": "inline", "paramOrder": [ "1",		"2",		"ulink", "nlink", "cwith", "size", "image", "use", "use2", "html", "note", "alias", "name" ] }

External research links
Useful links for researching Unicode characters:
 * Unicode.org charts in PDF format, showing the U+ hex values.
 * Fileformat.info search, to search by name (whole or partial), by U+ hex value or decimal value, or by the font symbol (copy-paste it). Extra information provided per character. One character only.
 * branah.com's a multi-character Unicode converter.
 * Unicode properties overview, e.g comma U+002C: