Unicode Settings
To use Unicode, set the character encoding to "UTF-8" on the "Encoding" tab of [Setup] Additional settings... or in the [KanjiCode] menu. UTF-8 is the default in Tera Term Mac.Character Display
-
There are three types of character display widths:
- The character width expected by the remote host (or its program)
- The character width used by Tera Term to render
- The character width defined by the font design
-
Some applications on the remote host take character width into account when rendering.
Examples include certain programs and libraries.- Text editor (Vim, Emacs, nano etc)
- viewer (more, less, lv etc)
- readline library linked to bash, etc.
- curses library linked to aptitude, etc.
-
Tera Term allows you to configure the character width used by Tera Term for rendering through settings
Ambiguous Characters width,
Override Emoji Characters width,
and Override Character width Per Character.
If "the width expected by the remote host" differs from "the width used by Tera Term for rendering", display misalignment is more likely to occur. -
The font used by Tera Term for rendering assumes each character is either 1 cell (half-width) or 2 cells (full-width).
There may be cases where "the width used by Tera Term to render" does not match "the width defined by the font design."
If "the width used by Tera Term to render" is aligned with "the width defined by the font design", characters are displayed as designed. However, if this width does not match "width expected by the remote host", display misalignment is more likely to occur.
When the widths do not match, the font is either scaled to fit the rendering width or displayed within the rendering width as-is. Refer to Drawing resized font to fit cell width. - The character to be displayed may not exist in the selected font.
macOS automatically draws such characters with another font (font fallback). Characters that no font has are shown as a replacement symbol (such as a box).
Some text files in the Tera Term repository can be displayed and checked (curl comes with macOS).
-
Unicode (Kanji) width
"curl -L https://github.com/TeraTermProject/teraterm/raw/main/tests/unicodebuf-east_asian_width.txt" -
Unicode Emoji width
"curl -L https://raw.githubusercontent.com/TeraTermProject/teraterm/main/tests/unicodebuf-text-emoji.txt"
Character width (cells)
Character width for single-byte character code such as Latin-1 is 1 cell.
Character width for double-byte character code such as Shift_JIS is 1 cell for 1-byte characters and 2 cells for 2-byte characters.
In Unicode, character width of a single character changes case-by-case.
Example, "§" (section sign, section mark)
| code | character code(code point) | cell | |--------------------|----------------------------|--------| | ISO8859-1(Latin-1) | 0xA7 | 1 | | Shift_JIS(CP932) | 0x8198 | 2 | | KS5601(CP949) | 0xA1D7 | 2 | | Big5(CP950) | 0xA1B1 | 2 | | BG2312(CP936) | 0xA1EC | 2 | | Unicode | 0xA7 (U+00A7) | 1 or 2 |
In a multibyte character code environment (CJK), character width should be 2 cell, and in other environments it should be 1 cell for natural use. Type of character whose width changes are called Ambiguous. Refer to East_Asian_Width and width (cells) for detail.
East_Asian_Width and width (cells)
In Unicode, characters are classified into 6 categories of display width, defined by the East_Asian_Width property.
In addition, there are two types of interpretation of character width
- In an East Asian context
- in a non-East Asian context
The following table
cells(2=full/1=half) | | East Asian | non-East Asian | | property | context | context | | F(Fullwidth) | 2 | 2 | | H(Halfwidth) | 1 | 1 | | W(Wide) | 2 | 2 | | Na(Narrow) | 1 | 1 | | A(Ambiguous) | 2 | 1 | | N(Neutral) | 1 | 1 |
Tera Term determines the character width used for rendering based on the properties of the following data.
https://www.unicode.org/Public/UCD/latest/ucd/EastAsianWidth.txt
Setting Ambiguous Characters width allows you to specify the width of ambiguous characters.
When the remote host program is in a CJK environment,
it is generally assumed that ambiguous characters have a width of 2.
Example in Vim:
When ambiwidth=single, ambiguous characters have a width of 1.
When ambiwidth=double, ambiguous characters have a width of 2.
If you want to customize the width of certain characters,
such as setting some characters (e.g., umlauted letters) to width 1 like in Emacs,
you can use setcellwidths().
Example in Emacs:
By default, ambiguous characters in Emacs have a width of 1.
Calling (set-language-environment "Japanese") executes use-cjk-char-width-table.
This changes the width of some ambiguous characters to 2 (for example,
umlauted letters remain 1, while Greek and Cyrillic characters become 2).
If "the width used by Tera Term for rendering" is adjusted to match "the width expected by the remote host", display misalignment is less likely to occur.
About Emoji width (cells)
The Emoji property is a separate property from East_Asian_Width. Even characters with the Emoji property set to Yes also have a value for the East_Asian_Width property.
Tera Term determines whether a character is an emoji based on the Extended_Pictographic property of the data below.
https://www.unicode.org/Public/UCD/latest/ucd/emoji/emoji-data.txt
The character width expected by the remote host may differ from the width defined by the font design.
For example, an emoji with the East_Asian_Width property set to Neutral may be designed as 2 cells in the font.
By specifying a width of 2 cells for emoji using the
Override Emoji Characters Width setting,
characters can be rendered according to the font design.
However, this may cause display misalignment, and even Neutral emoji will be rendered as 2 cells.