1 /*
2  *      letters.c
3  *
4  *      Copyright 2008-2012 Frank Lanitz <frank(at)frank(dot)uvena(dot)de>
5  *
6  *      This program is free software; you can redistribute it and/or modify
7  *      it under the terms of the GNU General Public License as published by
8  *      the Free Software Foundation; either version 2 of the License, or
9  *      (at your option) any later version.
10  *
11  *      This program is distributed in the hope that it will be useful,
12  *      but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  *      GNU General Public License for more details.
15  *
16  *      You should have received a copy of the GNU General Public License
17  *      along with this program; if not, write to the Free Software
18  *      Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19  *      MA 02110-1301, USA.
20  */
21 
22 #include <gtk/gtk.h>
23 #include "support.h"
24 #include "datatypes.h"
25 #include "letters.h"
26 
27 enum
28 {
29 	LATEX_LETTERS = 0,
30 	GREEK_LETTERS,
31 	GERMAN_LETTERS,
32 	MISC_LETTERS,
33 	ARROW_CHAR,
34 	RELATIONAL_SIGNS,
35 	BINARY_OPERATIONS,
36 	LETTERS_END
37 };
38 
39 CategoryName glatex_cat_names[] = {
40 	{ LATEX_LETTERS, N_("LaTeX letters"), TRUE},
41 	{ GREEK_LETTERS, N_("Greek letters"), TRUE},
42 	{ GERMAN_LETTERS, N_("German umlauts"), TRUE},
43 	{ MISC_LETTERS, N_("Misc"), FALSE},
44 	{ ARROW_CHAR, N_("Arrow characters"), FALSE},
45 	{ RELATIONAL_SIGNS, N_("Relational"), FALSE},
46 	{ BINARY_OPERATIONS, N_("Binary operation"), FALSE},
47 	{ 0, NULL, FALSE}
48 };
49 
50 /* Entries need to be sorted by categorie (1st field) or some random
51  * features will occure.
52  * AAABBBCCC is valid
53  * AAACCCBBB is valid
54  * ACABCBACB is _not_ valid and will course trouble */
55 SubMenuTemplate glatex_char_array[] = {
56 	/* LaTeX characters */
57 	{LATEX_LETTERS, "$", "\\$"},
58 	{LATEX_LETTERS, "%", "\\%"},
59 	{LATEX_LETTERS, "_", "\\_"},
60 	{LATEX_LETTERS, "}", "\\}"},
61 	{LATEX_LETTERS, "{", "\\{"},
62 	{LATEX_LETTERS, "&", "\\&"},
63 	{LATEX_LETTERS, "#", "\\#"},
64 	/* Greek characters */
65 	{GREEK_LETTERS, "Α", "\\Alpha" },
66 	{GREEK_LETTERS, "α", "\\alpha" },
67 	{GREEK_LETTERS, "Β", "\\Beta" },
68 	{GREEK_LETTERS, "β", "\\beta" },
69 	{GREEK_LETTERS, "Γ", "\\Gamma" },
70 	{GREEK_LETTERS, "γ", "\\gamma" },
71 	{GREEK_LETTERS, "Δ", "\\Delta" },
72 	{GREEK_LETTERS, "δ", "\\Delta" },
73 	{GREEK_LETTERS, "δ", "\\delta" },
74 	{GREEK_LETTERS, "Ε", "\\Epsilon" },
75 	{GREEK_LETTERS, "ε", "\\epsilon" },
76 	{GREEK_LETTERS, "Ζ", "\\Zeta" },
77 	{GREEK_LETTERS, "ζ", "\\zeta" },
78 	{GREEK_LETTERS, "Η", "\\Eta" },
79 	{GREEK_LETTERS, "η", "\\eta" },
80 	{GREEK_LETTERS, "Θ", "\\Theta" },
81 	{GREEK_LETTERS, "θ", "\\theta" },
82 	{GREEK_LETTERS, "Ι", "\\Iota" },
83 	{GREEK_LETTERS, "ι", "\\iota" },
84 	{GREEK_LETTERS, "Κ", "\\Kappa" },
85 	{GREEK_LETTERS, "κ", "\\kappa" },
86 	{GREEK_LETTERS, "Λ", "\\Lambda" },
87 	{GREEK_LETTERS, "λ", "\\lambda" },
88 	{GREEK_LETTERS, "Μ", "\\Mu" },
89 	{GREEK_LETTERS, "μ", "\\mu" },
90 	{GREEK_LETTERS, "Ν", "\\Nu" },
91 	{GREEK_LETTERS, "ν", "\\nu" },
92 	{GREEK_LETTERS, "Ξ", "\\Xi" },
93 	{GREEK_LETTERS, "ξ", "\\xi" },
94 	{GREEK_LETTERS, "Ο", "\\Omicron" },
95 	{GREEK_LETTERS, "ο", "\\omicron" },
96 	{GREEK_LETTERS, "Π", "\\Pi" },
97 	{GREEK_LETTERS, "π", "\\pi" },
98 	{GREEK_LETTERS, "Ρ", "\\Rho" },
99 	{GREEK_LETTERS, "ρ", "\\rho" },
100 	{GREEK_LETTERS, "Σ", "\\Sigma" },
101 	{GREEK_LETTERS, "ς", "\\sigmaf" },
102 	{GREEK_LETTERS, "σ", "\\sigma" },
103 	{GREEK_LETTERS, "Τ", "\\Tau" },
104 	{GREEK_LETTERS, "τ", "\\tau" },
105 	{GREEK_LETTERS, "Υ", "\\Upsilon" },
106 	{GREEK_LETTERS, "υ", "\\upsilon" },
107 	{GREEK_LETTERS, "Φ", "\\Phi" },
108 	{GREEK_LETTERS, "φ", "\\phi" },
109 	{GREEK_LETTERS, "Χ", "\\Chi" },
110 	{GREEK_LETTERS, "χ", "\\chi" },
111 	{GREEK_LETTERS, "Ψ", "\\Psi" },
112 	{GREEK_LETTERS, "ψ", "\\psi" },
113 	{GREEK_LETTERS, "Ω", "\\Omega" },
114 	{GREEK_LETTERS, "ω", "\\omega" },
115 	{GREEK_LETTERS, "ϑ", "\\thetasym" },
116 	{GREEK_LETTERS, "ϒ", "\\upsih" },
117 	{GREEK_LETTERS, "ϖ", "\\piv" },
118 
119 	/* German Umlaute */
120 	{GERMAN_LETTERS, "ä","\\\"a"},
121 	{GERMAN_LETTERS, "Ä","\\\"A"},
122 	{GERMAN_LETTERS, "ü","\\\"u"},
123 	{GERMAN_LETTERS, "Ü","\\\"U"},
124 	{GERMAN_LETTERS, "ö","\\\"o"},
125 	{GERMAN_LETTERS, "Ö","\\\"O"},
126 	{GERMAN_LETTERS, "ß","\\\"s"},
127 
128 	/* Czech characters */
129 	{MISC_LETTERS, "ě","\\v{e}"},
130 	{MISC_LETTERS, "š","\\v{s}"},
131 	{MISC_LETTERS, "č","\\v[c}"},
132 	{MISC_LETTERS, "ř","\\v{r}"},
133 	{MISC_LETTERS, "ž","\\v{z}"},
134 	{MISC_LETTERS, "ů","\\r{u}"},
135 	{MISC_LETTERS, "Ě","\\v{E}"},
136 	{MISC_LETTERS, "Š","\\v{S}"},
137 	{MISC_LETTERS, "Č","\\v{C}"},
138 	{MISC_LETTERS, "Ř","\\v{R}"},
139 	{MISC_LETTERS, "Ž","\\v{Z}"},
140 
141 	/* Misc */
142 	{MISC_LETTERS, "\\","\\backslash"},
143 	{MISC_LETTERS, "€", "\\euro"},
144 	{MISC_LETTERS, "»", "\\frqq"},
145 	{MISC_LETTERS, "«", "\\flqq"},
146 	{MISC_LETTERS, "›", "\\frq"},
147 	{MISC_LETTERS, "‹", "\\flq"},
148 	{ARROW_CHAR, "←", "\\leftarrow" },
149 	{ARROW_CHAR, "↑", "\\uparrow" },
150 	{ARROW_CHAR, "→", "\\rightarrow" },
151 	{ARROW_CHAR, "↓", "\\downarrow" },
152 	{ARROW_CHAR, "↔", "\\leftrightarrow" },
153 	{ARROW_CHAR, "⇐", "\\Leftarrow" },
154 	{ARROW_CHAR, "⇑", "\\Uparrow" },
155 	{ARROW_CHAR, "⇒", "\\Rightarrow" },
156 	{ARROW_CHAR, "⇓", "\\Downarrow" },
157 	{ARROW_CHAR, "⇔", "\\Leftrightarrow" },
158 	{RELATIONAL_SIGNS, "\342\211\244", "\\leq"},
159 	{RELATIONAL_SIGNS, "\342\211\245", "\\geq"},
160 	{RELATIONAL_SIGNS, "\342\210\216", "\\qed"},
161 	{RELATIONAL_SIGNS, "\342\211\241", "\\equiv"},
162 	{RELATIONAL_SIGNS, "\342\212\247", "\\models"},
163 	{RELATIONAL_SIGNS, "\342\211\272", "\\prec"},
164 	{RELATIONAL_SIGNS, "\342\211\273", "\\succ"},
165 	{RELATIONAL_SIGNS, "\342\211\274", "\\sim"},
166 	{RELATIONAL_SIGNS, "\342\237\202", "\\perp"},
167 	{RELATIONAL_SIGNS, "\342\252\257", "\\preceq"},
168 	{RELATIONAL_SIGNS, "\342\252\260", "\\succeq"},
169 	{RELATIONAL_SIGNS, "\342\211\203", "\\simeq"},
170 	{RELATIONAL_SIGNS, "\342\210\243", "\\mid"},
171 	{RELATIONAL_SIGNS, "\342\211\252", "\\ll"},
172 	{RELATIONAL_SIGNS, "\342\211\253", "\\gg"},
173 	{RELATIONAL_SIGNS, "\342\211\215", "\\asymp"},
174 	{RELATIONAL_SIGNS, "\342\210\245", "\\parallel"},
175 	{RELATIONAL_SIGNS, "\342\212\202", "\\subset"},
176 	{RELATIONAL_SIGNS, "\342\212\203", "\\supset"},
177 	{RELATIONAL_SIGNS, "\342\211\210", "\\approx"},
178 	{RELATIONAL_SIGNS, "\342\213\210", "\\bowtie"},
179 	{RELATIONAL_SIGNS, "\342\212\206", "\\subseteq"},
180 	{RELATIONAL_SIGNS, "\342\212\207", "\\supseteq"},
181 	{RELATIONAL_SIGNS, "\342\211\205", "\\cong"},
182 	{RELATIONAL_SIGNS, "\342\250\235", "\\Join"},
183 	{RELATIONAL_SIGNS, "\342\212\217", "\\sqsubset"},
184 	{RELATIONAL_SIGNS, "\342\212\220", "\\sqsupset"},
185 	{RELATIONAL_SIGNS, "\342\211\240", "\\neq"},
186 	{RELATIONAL_SIGNS, "\342\214\243", "\\smile"},
187 	{RELATIONAL_SIGNS, "\342\212\221", "\\sqsubseteq"},
188 	{RELATIONAL_SIGNS, "\342\212\222", "\\sqsupseteq"},
189 	{RELATIONAL_SIGNS, "\342\211\220", "\\doteq"},
190 	{RELATIONAL_SIGNS, "\342\214\242", "\\frown"},
191 	{RELATIONAL_SIGNS, "\342\210\210", "\\in"},
192 	{RELATIONAL_SIGNS, "\342\210\213", "\\ni"},
193 	{RELATIONAL_SIGNS, "\342\210\235", "\\propto"},
194 	{RELATIONAL_SIGNS, "\342\212\242", "\\vdash"},
195 	{RELATIONAL_SIGNS, "\342\212\243", "\\dashv"},
196 	{BINARY_OPERATIONS, "\302\261", "\\pm"},
197 	{BINARY_OPERATIONS, "\342\210\223", "\\mp"},
198 	{BINARY_OPERATIONS, "\303\227", "\\times"},
199 	{BINARY_OPERATIONS, "\303\267", "\\div"},
200 	{BINARY_OPERATIONS, "\342\210\227", "\\ast"},
201 	{BINARY_OPERATIONS, "\342\213\206", "\\star"},
202 	{BINARY_OPERATIONS, "\342\210\230", "\\circ"},
203 	{BINARY_OPERATIONS, "\342\210\231", "\\bullet"},
204 	{BINARY_OPERATIONS, "\342\213\205", "\\cdot"},
205 	{BINARY_OPERATIONS, "\342\210\251", "\\cap"},
206 	{BINARY_OPERATIONS, "\342\210\252", "\\cup"},
207 	{BINARY_OPERATIONS, "\342\212\216", "\\uplus"},
208 	{BINARY_OPERATIONS, "\342\212\223", "\\sqcap"},
209 	{BINARY_OPERATIONS, "\342\210\250", "\\vee"},
210 	{BINARY_OPERATIONS, "\342\210\247", "\\wedge"},
211 	{BINARY_OPERATIONS, "\342\210\226", "\\setminus"},
212 	{BINARY_OPERATIONS, "\342\211\200", "\\wr"},
213 	{BINARY_OPERATIONS, "\342\213\204", "\\diamond"},
214 	{BINARY_OPERATIONS, "\342\226\263", "\\bigtriangleup"},
215 	{BINARY_OPERATIONS, "\342\226\275", "\\bigtriangledown"},
216 	{BINARY_OPERATIONS, "\342\227\201", "\\triangleleft"},
217 	{BINARY_OPERATIONS, "\342\226\267", "\\triangleright"},
218 	{BINARY_OPERATIONS, "", "\\lhd"},
219 	{BINARY_OPERATIONS, "", "\\rhd"},
220 	{BINARY_OPERATIONS, "", "\\unlhd"},
221 	{BINARY_OPERATIONS, "", "\\unrhd"},
222 	{BINARY_OPERATIONS, "\342\212\225", "\\oplus"},
223 	{BINARY_OPERATIONS, "\342\212\226", "\\ominus"},
224 	{BINARY_OPERATIONS, "\342\212\227", "\\otimes"},
225 	{BINARY_OPERATIONS, "\342\210\205", "\\oslash"},
226 	{BINARY_OPERATIONS, "\342\212\231", "\\odot"},
227 	{BINARY_OPERATIONS, "\342\227\213", "\\bigcirc"},
228 	{BINARY_OPERATIONS, "\342\200\240", "\\dagger"},
229 	{BINARY_OPERATIONS, "\342\200\241", "\\ddagger"},
230 	{BINARY_OPERATIONS, "\342\250\277", "\\amalg"},
231 	{0, NULL, NULL},
232 
233 };
234 
glatex_get_entity(const gchar * letter)235 const gchar *glatex_get_entity(const gchar *letter)
236 {
237 	if (! utils_str_equal(letter, "\\"))
238 	{
239 		guint i, len;
240     	len = G_N_ELEMENTS(glatex_char_array);
241 		for (i = 0; i < len; i++)
242 		{
243 			if (utils_str_equal(glatex_char_array[i].label, letter))
244 			{
245 				return glatex_char_array[i].latex;
246 			}
247 		}
248 	}
249 
250 	/* if the char is not in the list */
251 	return NULL;
252 }
253