Pang-bô͘:Unichar

Wikipedia (chū-iû ê pek-kho-choân-su) beh kā lí kóng...
Documentation icon Pang-bô͘ bûn-su[chhâ-khòaⁿ] [pian-chi̍p] [le̍k-sú] [kun-sin]

This template produces a formatted description of a Unicode character, to be used inline or otherwise with regular text.

  • The character {{unichar|a9|COPYRIGHT SIGN}} is about intellectual property.
    The character U+00A9 © COPYRIGHT SIGN is about intellectual property.

Usage[kái goân-sí-bé]

The {{unichar}} template takes the Unicode hexadecimal code point value and optionally the character name as input, like {{unichar|00A9|COPYRIGHT SIGN}}U+00A9 © COPYRIGHT SIGN.

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 Pang-bô͘:Sc2. (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 unichar/gc sub-template.

Examples[kái goân-sí-bé]

  • {{unichar|00A9}}U+00A9 ©
  • {{unichar|00A9|sans=y}}U+00A9 ©
  • {{unichar|00A9|COPYRIGHT SIGN}}U+00A9 © COPYRIGHT SIGN
  • {{unichar|00A9|COPYRIGHT SIGN|nlink=Copyright symbol}}U+00A9 © COPYRIGHT SIGN
  • {{unichar|00A9|COPYRIGHT SIGN|nlink=Copyright symbol|note={{crossref|See also [[Copyleft]] symbol}}}}U+00A9 © COPYRIGHT SIGN (Pang-bô͘:Crossref)
  • {{unichar|00A9|COPYRIGHT SIGN|nlink=Copyright symbol|dec=|html=}}U+00A9 © COPYRIGHT SIGN (169decimal⧼dot-separator⧽ HTML ©⧼dot-separator⧽ ©, ©)
  • {{unichar|00A9|nlink=Copyright symbol}}U+00A9 © – no name added to link to
  • {{unichar|030D|COMBINING VERTICAL LINE ABOVE|cwith=◌}}U+030D ◌̍ COMBINING VERTICAL LINE ABOVEcombine with a dotted circle

Errors[kái goân-sí-bé]

Parameters[kái goân-sí-bé]

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

{{unichar
| <!-- hex value, code point (do not add the "U+")  -->
| <!-- Unicode name, in ALL-CAPS -->
| ulink	= 
| image	= 
| cwith = 
| size	= 
| use	= 
| use2	= 
| nlink	= 
| dec	= 
| html	= 
| note	= 
| sans  = <!-- must be ⟨y⟩ and only ⟨y⟩ to make "U+" as sans-serif & not mono -->
}}

Inline version:

{{unichar| <!--hex value (do not add "U+")-->| <!--Unicode name in ALL-CAPS-->|ulink= |image= |cwith= |size= |use= |use2= |nlink= |dec= |html= |note= }}
  • 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 Pang-bô͘:Crossref.
  • Second unnamed parameter or 2= Optional. The Unicode name of the character. This is given in ALL-CAPS, and the template will re-render it in SMALL-CAPS. This name may differ from the title of the corresponding Wikipedia article (see below: nlink=).
  • nlink= Optional wikilink. Name of the Wikipedia page that will be linked to. If used, the Unicode name (second parameter) has a wikilink to the article.
    Warning: This parameter must have valid value if it is present; if present and empty, a red-link error will appear unless a redirect from the formal Unicode symbol name like COPYRIGHT SIGN exists and goes to the correct article here (in this case Copyright symbol). Eventually all of these redirects should exist, but few do as of 2017.
    Note: The name of the page is case-sensitive as with all Wikipedia pages.
    {{unichar|00A9|COPYRIGHT SIGN|nlink=Copyright symbol}}U+00A9 © COPYRIGHT SIGN
  • ulink Optional. Creates a wikilink from the U+ prefix. When used without a name (i.e., |, blank with no value), the article Unicode is used as the default value in the output: [[Unicode|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.
  • sans=y Optional. Make the U+ sans (U+). Any value other than a single ASCII y, including blank/undefined, is interpreted as "use mono".
  • dec= Optional. Adds the decimal value to the text, in the bracketed note. You do not need to add the value manually; just add |dec=, blank.
  • html= Optional. Adds the HTML character reference to the text, like &#160; in the bracketed note. If a named character reference exists, like "&nbsp;", that is added too. 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 {{unicode}}, other options are {{IPA}}, {{lang}} and {{script}}.
  • use2= Optional. When setting |use=lang or |use=script, |use2= should be used to set the language (e.g. |use2=fr) or the script (e.g. |use2=Cyrs). A glyph may still not show as expected due to browser effects. For a detailed description, see each template's documentation.
    {{unichar|0485|COMBINING CYRILLIC DASIA PNEUMATA|cwith=|use=script|use2=Cyrs}}U+0485  ҅  COMBINING CYRILLIC DASIA PNEUMATA
  • 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 not the prefix File:.
  • cwith= Optional. Useful when the Unicode character is combining. Using |cwith= adds a space before the character, allowing the combining effect. So when used with a character like |cwith=a, the character will be combined with the letter "a". In Unicode, a general glyph used to place a combined character is U+25CC DOTTED CIRCLE (HTML &#9676;).
    without |cwith=:
    {{unichar|0485|COMBINING CYRILLIC DASIA PNEUMATA}}U+0485 ҅ COMBINING CYRILLIC DASIA PNEUMATA
    |cwith= without parameter:
    {{unichar|0485|COMBINING CYRILLIC DASIA PNEUMATA|cwith=}}U+0485  ҅  COMBINING CYRILLIC DASIA PNEUMATA
    |cwith= with dotted circle:
    {{unichar|0485|COMBINING CYRILLIC DASIA PNEUMATA|cwith=&#9676;}}U+0485 ◌҅ COMBINING CYRILLIC DASIA PNEUMATA
  • 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.
    {{unichar|0041|LATIN CAPITAL LETTER A|size=2em}}U+0041 A LATIN CAPITAL LETTER A
    When using an image (file) instead of a font, this size can only accept sizes in px like 12px. Default for images is 10px.
{{unichar
| A9
| COPYRIGHT SIGN
| ulink = Universal Character Set characters
| image = 
| size  = 150%
| nlink = Copyright symbol
| note  = Example
}}
Produces:

Presentation effects[kái goân-sí-bé]

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: U+00A0   NO-BREAK SPACE.
    Incidentally, the regular space   is replaced with &#00A0; (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 <Return> in the Name-input (possibly unintended) would frustrate the in-line behaviour expectation.
  • Showing a label like <control-0007>: 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 <private-use> or <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: <control> or <control-0007>
  • "Surrogate" general category=Cs: <surrogate> or <surrogate-D800>
  • "Private Use": general category=Co: <private-use> or <private-use-FFA0>
  • "Not a character" (minus the reserved code points, see below): general category=Cn: <not-a-character>, <non-character> or <not-a-character-FFA0>

The second parameter (Unicode name) is not presented, since it cannot exist. It is possible to create a link to an article.

  • Note: A <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[kái goân-sí-bé]

  • The template produces an Error-message when |1= (or first unnamed parameter), the hex value, is missing, empty, or invalid.
  • A non-hexadecimal input like Pang-bô͘:!mxt produces an error (because Pang-bô͘:!mxt or Pang-bô͘:!mxt is not hexadecimal).
  • Do not add the Pang-bô͘:!mxt prefix, as in Pang-bô͘:!mxt. It will not be recognised.
  • If the template only shows the code point number, like 2038, you're probably using the wrong template, {{unicode}}, instead of {{unichar}}.
  • The glyph may be overruled and changed into a label like <control-0007>. These characters have no Unicode name. An |nlink= will be directly to the article (entered in a form like |nlink=Bell signal). A blank value of just | cannot work for <label-hhhh> characters (there is no character name at all to make into a link). This produces an error.
  • A decimal-value input like |1=98 will be read as being hexadecimal value 0098. There is no way that the template can detect you intended to enter 9810=6216. No warning is issued, and the wrong character, U+009816, will be shown (not U+0062).
  • As noted above, misuse of the |nlink= parameter may result in red links to articles that don't exist.

Technical notes[kái goân-sí-bé]

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 {{unichar}}. 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 smallcaps. Accepts the |nlink= to create a piped wikilink to an article. When the general category (gc) is special, the name will change into a <label-hhhh>.
  • {{unichar/notes}} Produces the three optional notes in parentheses (round brackets): decimal (from |dec=); HTML (from |html= – both decimal like &#160; and named like &nbsp; if that exists, using {{numcr2namecr}}); and the free-text |note=. Also does the parentheses themselves.
  • 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 <#salted#> 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.

Issues[kái goân-sí-bé]

  • Unassigned code points, to be labelled <reserved>, cannot be detected.
  • When using |use-script=, then |use2= needs lowercase (e.g. 0485, Cyrs or cyrs)Pang-bô͘:Clarify
  • 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.

Pang-bô͘:Unicode templates

TemplateData[kái goân-sí-bé]

This is the TemplateData documentation for this template used by VisualEditor and other tools.

See the monthly error report for this template.

TemplateData for Unichar

Formats a Unicode character description inline.

模板參數[編輯模板資料]

此模板以參數行內格式為優先。

參數描述類型狀態
Hex value1 hval

Hexadecimal unicode codepoint

範例
031A
字串必填
Character name2 na

If provided, shows Unicode character name

範例
COMBINING LEFT ANGLE ABOVE
字串建議
Should U+ be sans-serif?sans

沒有描述

範例
How to show the U+. Any value except a single lowercase letter y means use mono, the default
字串非必填
ulinkulink

沒有描述

範例
Phonetic symbols in Unicode
非必填
imageimage

沒有描述

不明非必填
cwithcwith

沒有描述

字串非必填
sizesize

Relative size of rendered character

範例
200%
字串非必填
useuse

沒有描述

字串非必填
use2use2

沒有描述

字串非必填
nlinknlink

沒有描述

字串非必填
decdec

沒有描述

數值非必填
Show HTML code?HTML html

If provided, shows HTML code

範例
yes
字串建議
notenote

沒有描述

非必填

See also[kái goân-sí-bé]

U+00A9169dec&copy; (literal, not the character)

External research links[kái goân-sí-bé]

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: [1]