Template:Unichar

2017年8月11日 (金) 08:57; Doraemonplus (会話 | 投稿記録) による版 (en:Template:Unichar 2017-02-18T02:08 UTC までの更新を反映)(日時は個人設定で未設定ならUTC

(差分) ← 古い版 | 最新版 (差分) | 新しい版 → (差分)

Error using {{unichar}}: Input "" is not a hexadecimal value (expected: like "09AF")

テンプレートの解説[表示] [編集] [履歴] [キャッシュを破棄]

このテンプレートは本文中でUnicode文字の書式化された記述を生成するためにインラインで使用されます。

  • {{unichar|a9|Copyright sign}}は著作権表示のための記号です。
U+00A9 © copyright signは著作権表示のための記号です。

使用法[編集]

次のようにUnicodeの16進値と名称を入力して使います。{{unichar|00A9|Copyright sign}}U+00A9 © copyright sign.

このテンプレートは"U+00A9"のような文字の標準のUnicode提示形式に従い、small capsを使用することにより、文字の名称を全て大文字で表記するUnicodeの命名習慣(これはウィキペディアの本文では望まれない)を許容しています。16進値の入力(例:A9)は必須ですが、その他のパラメータの入力は任意です。実際のグリフは該当する文字を含むフォントを使用してレンダリングされます。これは、例えば言語またはIPAに特化したフォントに対してはもっと具体的に示されることがあります。グリフを表示するために、フォントの文字が画像でオーバーライドされることがあります。記事へのウィキリンクとそれとは別のUnicodeへのリンクが作成されることもあり、10進値に変換された値やHTML文字参照や注記を(括弧内に)追加することを可能にしています。

制御文字や空白文字のような、いくつかの特別なコードポイントには特別な注意が払われます。これらの特別なコードポイントはunichar/gcのサブテンプレートにより自動的に検知されます。

使用例[編集]

  • {{unichar|00A9|Copyright sign}}U+00A9 © copyright sign
  • {{unichar|00A9|Copyright sign|nlink=著作権マーク}}U+00A9 © copyright sign
  • {{unichar|00A9|Copyright sign|nlink=|note=[[コピーレフト]]記号も参照}}U+00A9 © copyright sign (コピーレフト記号も参照)
  • {{unichar|00A9|Copyright sign|nlink=著作権マーク|dec=|html=}}U+00A9 © copyright sign (169decimal, HTML: © ©)
  • {{unichar|00A0|No-break space|note=NBSP}}U+00A0   no-break space (NBSP)
  • {{unichar|0007|nlink=Bell character}}U+0007 <control-0007> Bell character
  • {{unichar|0007|Bell character|nlink=}}U+0007 <control-0007> Error using {{unichar}}: Pagename expected in "nlink="

パラメータ[編集]

全てのパラメータ付きの空のテンプレートは以下のとおり:

{{unichar
| <!-- 16進値、コードポイント("U+"は付けないでください) -->
| <!-- Unicodeの名称 -->
| ulink	= 
| image	= 
| cwith = 
| size	= 
| use	= 
| use2	= 
| nlink	= 
| dec	= 
| html	= 
| note	= 
}}

インライン用:

{{unichar| <!--16進値("U+"は付けない)-->| <!--Unicodeの名称-->|ulink= |image= |cwith= |size= |use= |use2= |nlink= |dec= |html= |note= }}
  • 第1パラメータ, 1= 名前なし, 入力必須(プレフィックスの "1=" は省略可)。コードポイントの16進値を記入(例:00A9)。
備考: このパラメータはA9a900A9のような16進値も受け付けます。10進値は10進値であることが検知されず、予期しない結果を返すことになります(後述のエラーメッセージを参照)。
  • 第2パラメータ, 2= 名前なし(プレフィックスの "2=" は省略可)。その文字のUnicodeでの名称。このテンプレートはこの入力値をname in small capsとして使用し、いかなる入力値も強制的に小さな文字にされます。この名称はウィキペディアの記事に対応する名称と異なる場合があります(以下のnlink=を参照)。
  • nlink= 任意入力。ウィキリンク。リンク先となるウィキペディアの記事名を記入。記入すると、Unicode名(第2パラメータ)にウィキリンクが付与されます。もし記事名とUnicode名が同一ならば、第2パラメータを使わずに "nlink=" の指定だけで十分です。
制御文字については nlink パラメータを使用してください。Unicode名のパラメータ(第2パラメータ)は使われません。 nlink パラメータが小さな文字にされることなく代わりに表示されます。
備考: ページ名は全てのウィキページと同様に大文字と小文字を区別します。
{{unichar|00A9|Copyright sign|nlink=Copyright symbol}}U+00A9 © copyright sign
{{unichar|00A3|Pound sign|nlink=}}U+00A3 £ pound sign.
  • ulink 任意入力。"U+" プレフィックスにウィキリンクが付与されます。名前 ({{{1}}}) を記入せずに使用すると、既定値Unicodeが適用され、次のようになります: U+
  • dec= 任意入力。テキストの括弧内に10進値を追加します。
  • html= 任意入力。テキストの括弧内にHTML文字参照を追加します(例:&#160;)。"&nbsp;"のような「名前文字参照」が存在する場合はそれも追加されます。
  • use= 任意入力。通常のブラウザフォントに文字が出現しないかもしれないとき、グリフを取得するためにフォントヒンティングのテンプレートを指定します。既定は{{unicode}}で、他に{{IPA}}、{{lang}}、{{script}}の選択肢があります。"use=lang" または "use=script" を指定すると、use2が使用され、言語 ("use2=fr") またはスクリプト ("use2=Cyrs") が指定されるはずです。それでも、ブラウザの影響のため、グリフが期待された通りに表示されないままであることもあります。詳しい説明は各テンプレートの説明書をご参照ください。
{{unichar|0485|COMBINING CYRILLIC DASIA PNEUMATA|cwith=|use=script|use2=Cyrs}}U+0485  ҅  combining cyrillic dasia pneumata
  • image= 任意入力。グリフを表現するために、フォントを完全に無効にしてファイル(画像イメージ)を使用できるようにします。ファイル名は".svg"のような拡張子まで含めて記入してください。ただし、"File:"のプレフィックスは不要です。
  • cwith= 任意入力。Unicode文字が「結合している」ときに有効です。cwith=を使用して文字の前に空白を追加し、結合の効果を表します。そのため、cwith=aのような文字と共に使用するとき、その文字は "a" という文字と結合されます。Unicodeで結合文字を置くために使われる一般的なグリフはU+25CC dotted circle (HTML: &#9676;)です。
cwith=不使用時の例:
{{unichar|0485|COMBINING CYRILLIC DASIA PNEUMATA}}U+0485 ҅ combining cyrillic dasia pneumata
cwith= パラメータ未記入時の例:
{{unichar|0485|COMBINING CYRILLIC DASIA PNEUMATA|cwith=}}U+0485  ҅  combining cyrillic dasia pneumata
cwith= パラメータにDOTTED CIRCLEを記入した時の例:
{{unichar|0485|COMBINING CYRILLIC DASIA PNEUMATA|cwith=&#9676;}}U+0485 ◌҅ combining cyrillic dasia pneumata
  • size= 任意入力。グリフのサイズを指定したいときに使用します。既定値は "size=125%" です。フォントについては、"7px", "150%", "2em", "larger"など、全てのフォントサイズ指定様式を受け付けます。
{{unichar|0041|LATIN CAPITAL LETTER A|size=2em}}U+0041 A latin capital letter a
フォントの代わりに画像(ファイル)を使用するときは、"12px"のようなピクセル単位でのサイズ指定様式しか受け付けません。画像を用いる場合の既定値は "10px" です。
{{unichar
| A9
| Copyright sign
| ulink = Universal Character Set characters
| image = 
| size  = 150%
| nlink = Copyright symbol
| note  = Example
}}
出力結果:

提示形式の効果[編集]

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).

起こりうるエラー[編集]

  • このテンプレートは第1パラメータ(16進値)に記入漏れがあるときにError-messageを返します。
  • 00G9のように無効な16進値を入力するとエラーを返します(G/gは16進法にない数値であるため)。
  • U+00A9のようにプレフィックス U+ を付け足さないでください。正しく認識されません。
  • もしもテンプレートが "2038" のようなコードポイントの数値だけを表示する場合は、おそらく{{unichar}}とは異なるテンプレート{{unicode}}を使用していることが考えられます。
  • グリフは無効にされ、<control-0007>のような label に変更されることがあるかもしれません。これらの文字にはUnicode名がありません。nlinkは記事に直接リンクします("nlink=Bell signal"と入力したときなど)。"nlink="(これはポンド記号のような通常の文字については問題なくリンクします)のように空欄にした場合は<labeled>文字のために機能しません(リンクとする文字の名称は全くありません)。これはエラーを返します。
  • 1=98 のような10進値の入力値は16進値の0098として読み込まれます。もしあなたが9810=6216のつもりで入力したとしても、テンプレートがそれを検知できることは絶対にありません。これについては警告は一切発せられず、U+0062ではなく、意図した文字と異なるU+009816が誤って表示されます。

テクニカルノート[編集]

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

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=" that overrules the font. Uses also "use", "use2", "size", "cwith".
  • {{unichar/na}} 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 brackets: decimal value, HTML-character reference (both decimal and by name like &amp;nbsp; if that exists using {{numcr2namecr}}) and the free text note as provided by the editor. Also does the brackets themselves.
  • Using the main template as an input-easy 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 Name, because a Unicode name cannot have the characters <##>, and so salted is the right word (meaning uninhibitable). For ease of code maintenance it is used in more places around.

諸問題[編集]

  • Unassigned code points, to be labelled <reserved>, cannot be detected.
  • When using use-script, use2 needs lowercase (e.g. 0485, Cyrs or cyrs)
  • When using for one off the RTL formatting marks, its effect may break out of the template (text following goed rtl too). As it is now, this requires extra code.

関連項目[編集]

  • {{unicode}} - Unicodeをより広く扱うフォントを使用して特殊な文字を表示させたいときに使えます。

外部リンク[編集]

Unicode文字の調査に役立つリンク: