Skip to content

Commit c54d72f

Browse files
DOC: Generate the charset tables dynamically from codes (#3409)
Co-authored-by: yvonnefroelich <[email protected]>
1 parent 93f0503 commit c54d72f

File tree

1 file changed

+70
-106
lines changed

1 file changed

+70
-106
lines changed

doc/techref/encodings.md

Lines changed: 70 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,34 @@
1+
---
2+
file_format: mystnb
3+
---
4+
5+
```{code-cell}
6+
---
7+
tags: [remove-input]
8+
---
9+
from IPython.display import display, Markdown
10+
from pygmt.encodings import charset
11+
12+
13+
def get_charset_mdtable(name):
14+
"""
15+
Create a markdown table for a charset.
16+
"""
17+
mappings = charset[name]
18+
19+
text = "| Octal | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 |\n"
20+
text += "|:---|:---:|:---:|:---:|:---:|:---:|:---:|:---:|:---:|\n"
21+
for i in range(0o00, 0o400, 8):
22+
chars = [mappings.get(j) for j in range(i, i + 8)]
23+
if all(v is None for v in chars): # All characters in this row are undefined
24+
continue
25+
row = f"\\{i:03o}"[:-1] + "x"
26+
chars = [f"&#x{ord(char):04x};" for char in chars]
27+
text += f"| **{row}** | {' | '.join(chars)} |\n"
28+
text += "\n"
29+
return Markdown(text)
30+
```
31+
132
# Supported Encodings and Non-ASCII Characters
233

334
GMT supports a number of encodings and each encoding contains a set of ASCII and
@@ -6,125 +37,58 @@ in arguments and text strings. When using non-ASCII characters in PyGMT, the eas
637
is to copy and paste the character from the encoding tables below.
738

839
**Note**: The special character &#xfffd; (REPLACEMENT CHARACTER) is used to indicate
9-
that the character is not defined in the encoding.
40+
that the character is undefined in the encoding.
1041

1142
## Adobe ISOLatin1+ Encoding
1243

13-
| octal | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 |
14-
|---|---|---|---|---|---|---|---|---|
15-
| **\03x** | &#xfffd; | &#x2022; | &#x2026; | &#x2122; | &#x2014; | &#x2013; | &#xfb01; | &#x017e; |
16-
| **\04x** | &#x0020; | &#x0021; | &#x0022; | &#x0023; | &#x0024; | &#x0025; | &#x0026; | &#x2019; |
17-
| **\05x** | &#x0028; | &#x0029; | &#x002a; | &#x002b; | &#x002c; | &#x002d; | &#x002e; | &#x002f; |
18-
| **\06x** | &#x0030; | &#x0031; | &#x0032; | &#x0033; | &#x0034; | &#x0035; | &#x0036; | &#x0037; |
19-
| **\07x** | &#x0038; | &#x0039; | &#x003a; | &#x003b; | &#x003c; | &#x003d; | &#x003e; | &#x003f; |
20-
| **\10x** | &#x0040; | &#x0041; | &#x0042; | &#x0043; | &#x0044; | &#x0045; | &#x0046; | &#x0047; |
21-
| **\11x** | &#x0048; | &#x0049; | &#x004a; | &#x004b; | &#x004c; | &#x004d; | &#x004e; | &#x004f; |
22-
| **\12x** | &#x0050; | &#x0051; | &#x0052; | &#x0053; | &#x0054; | &#x0055; | &#x0056; | &#x0057; |
23-
| **\13x** | &#x0058; | &#x0059; | &#x005a; | &#x005b; | &#x005c; | &#x005d; | &#x005e; | &#x005f; |
24-
| **\14x** | &#x2018; | &#x0061; | &#x0062; | &#x0063; | &#x0064; | &#x0065; | &#x0066; | &#x0067; |
25-
| **\15x** | &#x0068; | &#x0069; | &#x006a; | &#x006b; | &#x006c; | &#x006d; | &#x006e; | &#x006f; |
26-
| **\16x** | &#x0070; | &#x0071; | &#x0072; | &#x0073; | &#x0074; | &#x0075; | &#x0076; | &#x0077; |
27-
| **\17x** | &#x0078; | &#x0079; | &#x007a; | &#x007b; | &#x007c; | &#x007d; | &#x007e; | &#x0161; |
28-
| **\20x** | &#x0152; | &#x2020; | &#x2021; | &#x0141; | &#x2044; | &#x2039; | &#x0160; | &#x203a; |
29-
| **\21x** | &#x0153; | &#x0178; | &#x017d; | &#x0142; | &#x2030; | &#x201e; | &#x201c; | &#x201d; |
30-
| **\22x** | &#x0131; | &#x0060; | &#x00b4; | &#x005e; | &#x02dc; | &#x00af; | &#x02d8; | &#x02d9; |
31-
| **\23x** | &#x00a8; | &#x201a; | &#x02da; | &#x00b8; | &#x0027; | &#x02dd; | &#x02db; | &#x02c7; |
32-
| **\24x** | &#xfffd; | &#x00a1; | &#x00a2; | &#x00a3; | &#x00a4; | &#x00a5; | &#x00a6; | &#x00a7; |
33-
| **\25x** | &#x00a8; | &#x00a9; | &#x00aa; | &#x00ab; | &#x00ac; | &#x00ad; | &#x00ae; | &#x00af; |
34-
| **\26x** | &#x00b0; | &#x00b1; | &#x00b2; | &#x00b3; | &#x00b4; | &#x00b5; | &#x00b6; | &#x00b7; |
35-
| **\27x** | &#x00b8; | &#x00b9; | &#x00ba; | &#x00bb; | &#x00bc; | &#x00bd; | &#x00be; | &#x00bf; |
36-
| **\30x** | &#x00c0; | &#x00c1; | &#x00c2; | &#x00c3; | &#x00c4; | &#x00c5; | &#x00c6; | &#x00c7; |
37-
| **\31x** | &#x00c8; | &#x00c9; | &#x00ca; | &#x00cb; | &#x00cc; | &#x00cd; | &#x00ce; | &#x00cf; |
38-
| **\32x** | &#x00d0; | &#x00d1; | &#x00d2; | &#x00d3; | &#x00d4; | &#x00d5; | &#x00d6; | &#x00d7; |
39-
| **\33x** | &#x00d8; | &#x00d9; | &#x00da; | &#x00db; | &#x00dc; | &#x00dd; | &#x00de; | &#x00df; |
40-
| **\34x** | &#x00e0; | &#x00e1; | &#x00e2; | &#x00e3; | &#x00e4; | &#x00e5; | &#x00e6; | &#x00e7; |
41-
| **\35x** | &#x00e8; | &#x00e9; | &#x00ea; | &#x00eb; | &#x00ec; | &#x00ed; | &#x00ee; | &#x00ef; |
42-
| **\36x** | &#x00f0; | &#x00f1; | &#x00f2; | &#x00f3; | &#x00f4; | &#x00f5; | &#x00f6; | &#x00f7; |
43-
| **\37x** | &#x00f8; | &#x00f9; | &#x00fa; | &#x00fb; | &#x00fc; | &#x00fd; | &#x00fe; | &#x00ff; |
44+
```{code-cell}
45+
---
46+
tags: [remove-input]
47+
---
48+
display(get_charset_mdtable("ISOLatin1+"))
49+
```
4450

4551
## Adobe Symbol Encoding
4652

47-
| octal | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 |
48-
|---|---|---|---|---|---|---|---|---|
49-
| **\04x** | &#x0020; | &#x0021; | &#x2200; | &#x0023; | &#x2203; | &#x0025; | &#x0026; | &#x220b; |
50-
| **\05x** | &#x0028; | &#x0029; | &#x2217; | &#x002b; | &#x002c; | &#x2212; | &#x002e; | &#x002f; |
51-
| **\06x** | &#x0030; | &#x0031; | &#x0032; | &#x0033; | &#x0034; | &#x0035; | &#x0036; | &#x0037; |
52-
| **\07x** | &#x0038; | &#x0039; | &#x003a; | &#x003b; | &#x003c; | &#x003d; | &#x003e; | &#x003f; |
53-
| **\10x** | &#x2245; | &#x0391; | &#x0392; | &#x03a7; | &#x2206; | &#x0395; | &#x03a6; | &#x0393; |
54-
| **\11x** | &#x0397; | &#x0399; | &#x03d1; | &#x039a; | &#x039b; | &#x039c; | &#x039d; | &#x039f; |
55-
| **\12x** | &#x03a0; | &#x0398; | &#x03a1; | &#x03a3; | &#x03a4; | &#x03a5; | &#x03c2; | &#x2126; |
56-
| **\13x** | &#x039e; | &#x03a8; | &#x0396; | &#x005b; | &#x2234; | &#x005d; | &#x22a5; | &#x005f; |
57-
| **\14x** | &#xf8e5; | &#x03b1; | &#x03b2; | &#x03c7; | &#x03b4; | &#x03b5; | &#x03c6; | &#x03b3; |
58-
| **\15x** | &#x03b7; | &#x03b9; | &#x03d5; | &#x03ba; | &#x03bb; | &#x03bc; | &#x03bd; | &#x03bf; |
59-
| **\16x** | &#x03c0; | &#x03b8; | &#x03c1; | &#x03c3; | &#x03c4; | &#x03c5; | &#x03d6; | &#x03c9; |
60-
| **\17x** | &#x03be; | &#x03c8; | &#x03b6; | &#x007b; | &#x007c; | &#x007d; | &#x223c; | &#xfffd; |
61-
| **\24x** | &#x20ac; | &#x03d2; | &#x2032; | &#x2264; | &#x2215; | &#x221e; | &#x0192; | &#x2663; |
62-
| **\25x** | &#x2666; | &#x2665; | &#x2660; | &#x2194; | &#x2190; | &#x2191; | &#x2192; | &#x2193; |
63-
| **\26x** | &#x00b0; | &#x00b1; | &#x2033; | &#x2265; | &#x00d7; | &#x221d; | &#x2202; | &#x2022; |
64-
| **\27x** | &#x00f7; | &#x2260; | &#x2261; | &#x2248; | &#x2026; | &#x23d0; | &#x23af; | &#x21b5; |
65-
| **\30x** | &#x2135; | &#x2111; | &#x211c; | &#x2118; | &#x2297; | &#x2295; | &#x2205; | &#x2229; |
66-
| **\31x** | &#x222a; | &#x2283; | &#x2287; | &#x2284; | &#x2282; | &#x2286; | &#x2208; | &#x2209; |
67-
| **\32x** | &#x2220; | &#x2207; | &#x00ae; | &#x00a9; | &#x2122; | &#x220f; | &#x221a; | &#x22c5; |
68-
| **\33x** | &#x00ac; | &#x2227; | &#x2228; | &#x21d4; | &#x21d0; | &#x21d1; | &#x21d2; | &#x21d3; |
69-
| **\34x** | &#x25ca; | &#x2329; | &#x00ae; | &#x00a9; | &#x2122; | &#x2211; | &#x239b; | &#x239c; |
70-
| **\35x** | &#x239d; | &#x23a1; | &#x23a2; | &#x23a3; | &#x23a7; | &#x23a8; | &#x23a9; | &#x23aa; |
71-
| **\36x** | &#xfffd; | &#x232a; | &#x222b; | &#x2320; | &#x23ae; | &#x2321; | &#x239e; | &#x239f; |
72-
| **\37x** | &#x23a0; | &#x23a4; | &#x23a5; | &#x23a6; | &#x23ab; | &#x23ac; | &#x23ad; | &#xfffd; |
73-
74-
**Note**: The octal code `\140` represents the RADICAL EXTENDER character, which is not available in
75-
the Unicode character set.
53+
```{code-cell}
54+
---
55+
tags: [remove-input]
56+
---
57+
display(get_charset_mdtable("Symbol"))
58+
```
59+
60+
**Note**: The octal code `\140` represents the RADICAL EXTENDER character, which is not
61+
available in the Unicode character set.
7662

7763
## Adobe ZapfDingbats Encoding
7864

79-
| octal | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 |
80-
|---|---|---|---|---|---|---|---|---|
81-
| **\04x** | &#x0020; | &#x2701; | &#x2702; | &#x2703; | &#x2704; | &#x260e; | &#x2706; | &#x2707; |
82-
| **\05x** | &#x2708; | &#x2709; | &#x261b; | &#x261e; | &#x270c; | &#x270d; | &#x270e; | &#x270f; |
83-
| **\06x** | &#x2710; | &#x2711; | &#x2712; | &#x2713; | &#x2714; | &#x2715; | &#x2716; | &#x2717; |
84-
| **\07x** | &#x2718; | &#x2719; | &#x271a; | &#x271b; | &#x271c; | &#x271d; | &#x271e; | &#x271f; |
85-
| **\10x** | &#x2720; | &#x2721; | &#x2722; | &#x2723; | &#x2724; | &#x2725; | &#x2726; | &#x2727; |
86-
| **\11x** | &#x2605; | &#x2729; | &#x272a; | &#x272b; | &#x272c; | &#x272d; | &#x272e; | &#x272f; |
87-
| **\12x** | &#x2730; | &#x2731; | &#x2732; | &#x2733; | &#x2734; | &#x2735; | &#x2736; | &#x2737; |
88-
| **\13x** | &#x2738; | &#x2739; | &#x273a; | &#x273b; | &#x273c; | &#x273d; | &#x273e; | &#x273f; |
89-
| **\14x** | &#x2740; | &#x2741; | &#x2742; | &#x2743; | &#x2744; | &#x2745; | &#x2746; | &#x2747; |
90-
| **\15x** | &#x2748; | &#x2749; | &#x274a; | &#x274b; | &#x25cf; | &#x274d; | &#x25a0; | &#x274f; |
91-
| **\16x** | &#x2750; | &#x2751; | &#x2752; | &#x25b2; | &#x25bc; | &#x25c6; | &#x2756; | &#x25d7; |
92-
| **\17x** | &#x2758; | &#x2759; | &#x275a; | &#x275b; | &#x275c; | &#x275d; | &#x275e; | &#xfffd; |
93-
| **\20x** | &#x2768; | &#x2769; | &#x276a; | &#x276b; | &#x276c; | &#x276d; | &#x276e; | &#x276f; |
94-
| **\21x** | &#x2770; | &#x2771; | &#x2772; | &#x2773; | &#x2774; | &#x2775; | &#xfffd; | &#xfffd; |
95-
| **\24x** | &#xfffd; | &#x2761; | &#x2762; | &#x2763; | &#x2764; | &#x2765; | &#x2766; | &#x2767; |
96-
| **\25x** | &#x2663; | &#x2666; | &#x2665; | &#x2660; | &#x2460; | &#x2461; | &#x2462; | &#x2463; |
97-
| **\26x** | &#x2464; | &#x2465; | &#x2466; | &#x2467; | &#x2468; | &#x2469; | &#x2776; | &#x2777; |
98-
| **\27x** | &#x2778; | &#x2779; | &#x277a; | &#x277b; | &#x277c; | &#x277d; | &#x277e; | &#x277f; |
99-
| **\30x** | &#x2780; | &#x2781; | &#x2782; | &#x2783; | &#x2784; | &#x2785; | &#x2786; | &#x2787; |
100-
| **\31x** | &#x2788; | &#x2789; | &#x278a; | &#x278b; | &#x278c; | &#x278d; | &#x278e; | &#x278f; |
101-
| **\32x** | &#x2790; | &#x2791; | &#x2792; | &#x2793; | &#x2794; | &#x2192; | &#x2194; | &#x2195; |
102-
| **\33x** | &#x2798; | &#x2799; | &#x279a; | &#x279b; | &#x279c; | &#x279d; | &#x279e; | &#x279f; |
103-
| **\34x** | &#x27a0; | &#x27a1; | &#x27a2; | &#x27a3; | &#x27a4; | &#x27a5; | &#x27a6; | &#x27a7; |
104-
| **\35x** | &#x27a8; | &#x27a9; | &#x27aa; | &#x27ab; | &#x27ac; | &#x27ad; | &#x27ae; | &#x27af; |
105-
| **\36x** | &#xfffd; | &#x27b1; | &#x27b2; | &#x27b3; | &#x27b4; | &#x27b5; | &#x27b6; | &#x27b7; |
106-
| **\37x** | &#x27b8; | &#x27b9; | &#x27ba; | &#x27bb; | &#x27bc; | &#x27bd; | &#x27be; | &#xfffd; |
65+
```{code-cell}
66+
---
67+
tags: [remove-input]
68+
---
69+
display(get_charset_mdtable("ZapfDingbats"))
70+
```
10771

10872
## ISO/IEC 8859
10973

11074
PyGMT also supports the ISO/IEC 8859 standard for 8-bit character encodings. Refer to
111-
<https://en.wikipedia.org/wiki/ISO/IEC_8859> for descriptions of the different parts of
112-
the standard.
75+
[ISO/IEC 8859](https://en.wikipedia.org/wiki/ISO/IEC_8859) for descriptions of the
76+
different parts of the standard.
11377

11478
For a list of the characters in each part of the standard, refer to the following links:
11579

116-
- <https://en.wikipedia.org/wiki/ISO/IEC_8859-1>
117-
- <https://en.wikipedia.org/wiki/ISO/IEC_8859-2>
118-
- <https://en.wikipedia.org/wiki/ISO/IEC_8859-3>
119-
- <https://en.wikipedia.org/wiki/ISO/IEC_8859-4>
120-
- <https://en.wikipedia.org/wiki/ISO/IEC_8859-5>
121-
- <https://en.wikipedia.org/wiki/ISO/IEC_8859-6>
122-
- <https://en.wikipedia.org/wiki/ISO/IEC_8859-7>
123-
- <https://en.wikipedia.org/wiki/ISO/IEC_8859-8>
124-
- <https://en.wikipedia.org/wiki/ISO/IEC_8859-9>
125-
- <https://en.wikipedia.org/wiki/ISO/IEC_8859-10>
126-
- <https://en.wikipedia.org/wiki/ISO/IEC_8859-11>
127-
- <https://en.wikipedia.org/wiki/ISO/IEC_8859-13>
128-
- <https://en.wikipedia.org/wiki/ISO/IEC_8859-14>
129-
- <https://en.wikipedia.org/wiki/ISO/IEC_8859-15>
130-
- <https://en.wikipedia.org/wiki/ISO/IEC_8859-16>
80+
- [ISO/IEC 8859-1](https://en.wikipedia.org/wiki/ISO/IEC_8859-1)
81+
- [ISO/IEC 8859-2](https://en.wikipedia.org/wiki/ISO/IEC_8859-2)
82+
- [ISO/IEC 8859-3](https://en.wikipedia.org/wiki/ISO/IEC_8859-3)
83+
- [ISO/IEC 8859-4](https://en.wikipedia.org/wiki/ISO/IEC_8859-4)
84+
- [ISO/IEC 8859-5](https://en.wikipedia.org/wiki/ISO/IEC_8859-5)
85+
- [ISO/IEC 8859-6](https://en.wikipedia.org/wiki/ISO/IEC_8859-6)
86+
- [ISO/IEC 8859-7](https://en.wikipedia.org/wiki/ISO/IEC_8859-7)
87+
- [ISO/IEC 8859-8](https://en.wikipedia.org/wiki/ISO/IEC_8859-8)
88+
- [ISO/IEC 8859-9](https://en.wikipedia.org/wiki/ISO/IEC_8859-9)
89+
- [ISO/IEC 8859-10](https://en.wikipedia.org/wiki/ISO/IEC_8859-10)
90+
- [ISO/IEC 8859-11](https://en.wikipedia.org/wiki/ISO/IEC_8859-11)
91+
- [ISO/IEC 8859-13](https://en.wikipedia.org/wiki/ISO/IEC_8859-13)
92+
- [ISO/IEC 8859-14](https://en.wikipedia.org/wiki/ISO/IEC_8859-14)
93+
- [ISO/IEC 8859-15](https://en.wikipedia.org/wiki/ISO/IEC_8859-15)
94+
- [ISO/IEC 8859-16](https://en.wikipedia.org/wiki/ISO/IEC_8859-16)

0 commit comments

Comments
 (0)