1 package uk.ac.cam.aa582.structures.boxes;
2 
3 /**
4  * Many math symbols are stored here in short integer fields<br/>
5  * The short integer encodes the character in the first 8 bits
6  * (0x00FF) and the font in the next 4 bits (0x0F00)
7  * For example: 0x0DA1 specifies the char A1 in font D (which
8  * happens to be cmsy)<br/>
9  * This class contains few more utility methods to extract the
10  * char and font information from the short integer.<br/>
11  * The field names are chosen to be the TeX name of that symbol
12  * (when applicable), for example pm stands for "plus or minus"
13  * which is the TeX name for the symbol
14  *
15  * @author Ahmad Akra
16  *
17  */
18 public class S {
19 
20 
21 	/**
22 	 * Extract the font information from the short integer
23 	 * given how they are encoded in this class
24 	 *
25 	 * @param s the short int to extract the info from
26 	 * @return the font file encoded in the short int
27 	 */
font(short s)28 	public static Font font(short s) {
29 		char fontCode = (char) ((s & 0x0F00)/(0x0100));
30 
31 		if(fontCode == 0x0A) return Font.cmr;
32 		if(fontCode == 0x0B) return Font.cmmi;
33 		if(fontCode == 0x0C) return Font.cmex;
34 		if(fontCode == 0x0D) return Font.cmsy;
35 
36 		return Font.cmr;
37 	}
38 
39 	/**
40 	 * Extract the character from the short integer
41 	 * given how it is encoded in the fields of this
42 	 * class
43 	 *
44 	 * @param s the short int to extract the info from
45 	 * @return the character encoded in the short int
46 	 */
symbol(short s)47 	public static char symbol(short s) {
48 		//s = (s & 0x00FF);
49 		return (char)  (s & 0x00FF);
50 	}
51 
52 	/**
53 	 *
54 	 * @param s the short int to turn into text
55 	 * @return the Reduce string representation of the
56 	 * symbol encoded in the parameter, for example
57 	 * <tt>text(S.times)</tt> returns <tt>"*"</tt>
58 	 */
text(short s)59 	public static String text(short s) {
60 		switch(s) {
61 		case minus : return "-";
62 		case times : return "*";
63 		case div : return "/";
64 		case pi : return "pi";
65 		case infty : return "infinity";
66 		default : return symbol(s)+"";
67 		}
68 	}
69 
70 	/**
71 	 * +
72 	 */
73 	public static final short plus 			= 0x0A00 + '+';
74 
75 	/**
76 	 * Minus sign
77 	 */
78 	public static final short minus 		= 0x0DA1;
79 
80 	/**
81 	 * Plus of minus
82 	 */
83 	public static final short pm			= 0x0DA7;
84 
85 	/**
86 	 * Minus of plus
87 	 */
88 	public static final short mp			= 0x0DA8;
89 
90 	/**
91 	 * Multiplication symbol
92 	 */
93 	public static final short times 		= 0x0DA3;
94 
95 	/**
96 	 * Division symbol
97 	 */
98 	public static final short div			= 0x0DA5;
99 
100 	/**
101 	 * *
102 	 */
103 	public static final short ast			= 0x0DA4;
104 	public static final short cdot			= 0x0DA2;
105     public static final short ominus 		= 0x0DAA;
106     public static final short oplus 		= 0x0DA9;
107     public static final short oslash 		= 0x0DAE;
108     public static final short otimes 		= 0x0DAD;
109     public static final short odot 			= 0x0DAF;
110 
111     /**
112      * =
113      */
114     public static final short equals		= 0x0A00 + '=';
115 
116     /**
117      * Less then sign
118      */
119     public static final short lessthen		= 0x0A00 + '<';
120 
121     /**
122      * Greater then sign
123      */
124     public static final short greaterthen 	= 0x0A00 + '>';
125 
126     /**
127      * Less then or equal sign
128      */
129     public static final short leq			= 0x0DB7;
130 
131     /**
132      * Greater then or equal sign
133      */
134     public static final short geq			= 0x0DB8;
135     public static final short simeq 		= 0x0D27;
136 
137     /**
138      * Approximately equal sign
139      */
140     public static final short approx		= 0x0DBC;
141 
142     /**
143      * Infinity
144      */
145     public static final short infty 		= 0x0D31;
146 
147 	/**
148 	 * Letter a in Computer Modern Math Italic font (cmmi)
149 	 */
150 	public static final short a				= 0x0B00 + 'a';
151 
152 	/**
153 	 * Letter b in Computer Modern Math Italic font (cmmi)
154 	 */
155 	public static final short b				= 0x0B00 + 'b';
156 
157 	/**
158 	 * Letter c in Computer Modern Math Italic font (cmmi)
159 	 */
160 	public static final short c				= 0x0B00 + 'c';
161 
162 	/**
163 	 * Letter d in Computer Modern Math Italic font (cmmi)
164 	 */
165 	public static final short d				= 0x0B00 + 'd';
166 
167 	/**
168 	 * Letter e in Computer Modern Math Italic font (cmmi)
169 	 */
170 	public static final short e				= 0x0B00 + 'e';
171 
172 	/**
173 	 * Letter f in Computer Modern Math Italic font (cmmi)
174 	 */
175 	public static final short f				= 0x0B00 + 'f';
176 
177 	/**
178 	 * Letter g in Computer Modern Math Italic font (cmmi)
179 	 */
180 	public static final short g				= 0x0B00 + 'g';
181 
182 	/**
183 	 * Letter h in Computer Modern Math Italic font (cmmi)
184 	 */
185 	public static final short h				= 0x0B00 + 'h';
186 
187 	/**
188 	 * Letter i in Computer Modern Math Italic font (cmmi)
189 	 */
190 	public static final short i				= 0x0B00 + 'i';
191 
192 	/**
193 	 * Letter j in Computer Modern Math Italic font (cmmi)
194 	 */
195 	public static final short j				= 0x0B00 + 'j';
196 
197 	/**
198 	 * Letter k in Computer Modern Math Italic font (cmmi)
199 	 */
200 	public static final short k				= 0x0B00 + 'k';
201 
202 	/**
203 	 * Letter l in Computer Modern Math Italic font (cmmi)
204 	 */
205 	public static final short l				= 0x0B00 + 'l';
206 
207 	/**
208 	 * Letter m in Computer Modern Math Italic font (cmmi)
209 	 */
210 	public static final short m				= 0x0B00 + 'm';
211 
212 	/**
213 	 * Letter n in Computer Modern Math Italic font (cmmi)
214 	 */
215 	public static final short n				= 0x0B00 + 'n';
216 
217 	/**
218 	 * Letter o in Computer Modern Math Italic font (cmmi)
219 	 */
220 	public static final short o				= 0x0B00 + 'o';
221 
222 	/**
223 	 * Letter p in Computer Modern Math Italic font (cmmi)
224 	 */
225 	public static final short p				= 0x0B00 + 'p';
226 
227 	/**
228 	 * Letter q in Computer Modern Math Italic font (cmmi)
229 	 */
230 	public static final short q				= 0x0B00 + 'q';
231 
232 	/**
233 	 * Letter r in Computer Modern Math Italic font (cmmi)
234 	 */
235 	public static final short r				= 0x0B00 + 'r';
236 
237 	/**
238 	 * Letter s in Computer Modern Math Italic font (cmmi)
239 	 */
240 	public static final short s				= 0x0B00 + 's';
241 
242 	/**
243 	 * Letter t in Computer Modern Math Italic font (cmmi)
244 	 */
245 	public static final short t				= 0x0B00 + 't';
246 
247 	/**
248 	 * Letter u in Computer Modern Math Italic font (cmmi)
249 	 */
250 	public static final short u				= 0x0B00 + 'u';
251 
252 	/**
253 	 * Letter v in Computer Modern Math Italic font (cmmi)
254 	 */
255 	public static final short v				= 0x0B00 + 'v';
256 
257 	/**
258 	 * Letter w in Computer Modern Math Italic font (cmmi)
259 	 */
260 	public static final short w				= 0x0B00 + 'w';
261 
262 	/**
263 	 * Letter x in Computer Modern Math Italic font (cmmi)
264 	 */
265 	public static final short x				= 0x0B00 + 'x';
266 
267 	/**
268 	 * Letter y in Computer Modern Math Italic font (cmmi)
269 	 */
270 	public static final short y				= 0x0B00 + 'y';
271 
272 	/**
273 	 * Letter z in Computer Modern Math Italic font (cmmi)
274 	 */
275 	public static final short z				= 0x0B00 + 'z';
276 
277 	/**
278 	 * Letter A in Computer Modern Math Italic font (cmmi)
279 	 */
280 	public static final short A				= 0x0B00 + 'A';
281 
282 	/**
283 	 * Letter B in Computer Modern Math Italic font (cmmi)
284 	 */
285 	public static final short B				= 0x0B00 + 'B';
286 
287 	/**
288 	 * Letter C in Computer Modern Math Italic font (cmmi)
289 	 */
290 	public static final short C				= 0x0B00 + 'C';
291 
292 	/**
293 	 * Letter D in Computer Modern Math Italic font (cmmi)
294 	 */
295 	public static final short D				= 0x0B00 + 'D';
296 
297 	/**
298 	 * Letter E in Computer Modern Math Italic font (cmmi)
299 	 */
300 	public static final short E				= 0x0B00 + 'E';
301 
302 	/**
303 	 * Letter F in Computer Modern Math Italic font (cmmi)
304 	 */
305 	public static final short F				= 0x0B00 + 'F';
306 
307 	/**
308 	 * Letter G in Computer Modern Math Italic font (cmmi)
309 	 */
310 	public static final short G				= 0x0B00 + 'G';
311 
312 	/**
313 	 * Letter H in Computer Modern Math Italic font (cmmi)
314 	 */
315 	public static final short H				= 0x0B00 + 'H';
316 
317 	/**
318 	 * Letter I in Computer Modern Math Italic font (cmmi)
319 	 */
320 	public static final short I				= 0x0B00 + 'I';
321 
322 	/**
323 	 * Letter J in Computer Modern Math Italic font (cmmi)
324 	 */
325 	public static final short J				= 0x0B00 + 'J';
326 
327 	/**
328 	 * Letter K in Computer Modern Math Italic font (cmmi)
329 	 */
330 	public static final short K				= 0x0B00 + 'K';
331 
332 	/**
333 	 * Letter L in Computer Modern Math Italic font (cmmi)
334 	 */
335 	public static final short L				= 0x0B00 + 'L';
336 
337 	/**
338 	 * Letter M in Computer Modern Math Italic font (cmmi)
339 	 */
340 	public static final short M				= 0x0B00 + 'M';
341 
342 	/**
343 	 * Letter N in Computer Modern Math Italic font (cmmi)
344 	 */
345 	public static final short N				= 0x0B00 + 'N';
346 
347 	/**
348 	 * Letter O in Computer Modern Math Italic font (cmmi)
349 	 */
350 	public static final short O				= 0x0B00 + 'O';
351 
352 	/**
353 	 * Letter P in Computer Modern Math Italic font (cmmi)
354 	 */
355 	public static final short P				= 0x0B00 + 'P';
356 
357 	/**
358 	 * Letter Q in Computer Modern Math Italic font (cmmi)
359 	 */
360 	public static final short Q				= 0x0B00 + 'Q';
361 
362 	/**
363 	 * Letter R in Computer Modern Math Italic font (cmmi)
364 	 */
365 	public static final short R				= 0x0B00 + 'R';
366 
367 	/**
368 	 * Letter S in Computer Modern Math Italic font (cmmi)
369 	 */
370 	public static final short S				= 0x0B00 + 'S';
371 
372 	/**
373 	 * Letter T in Computer Modern Math Italic font (cmmi)
374 	 */
375 	public static final short T				= 0x0B00 + 'T';
376 
377 	/**
378 	 * Letter U in Computer Modern Math Italic font (cmmi)
379 	 */
380 	public static final short U				= 0x0B00 + 'U';
381 
382 	/**
383 	 * Letter V in Computer Modern Math Italic font (cmmi)
384 	 */
385 	public static final short V				= 0x0B00 + 'V';
386 
387 	/**
388 	 * Letter W in Computer Modern Math Italic font (cmmi)
389 	 */
390 	public static final short W				= 0x0B00 + 'W';
391 
392 	/**
393 	 * Letter X in Computer Modern Math Italic font (cmmi)
394 	 */
395 	public static final short X				= 0x0B00 + 'X';
396 
397 	/**
398 	 * Letter Y in Computer Modern Math Italic font (cmmi)
399 	 */
400 	public static final short Y				= 0x0B00 + 'Y';
401 
402 	/**
403 	 * Letter Z in Computer Modern Math Italic font (cmmi)
404 	 */
405 	public static final short Z				= 0x0B00 + 'Z';
406 
407     public static final short alpha 		= 0x0BAE;
408     public static final short beta 			= 0x0BAF;
409     public static final short gamma 		= 0x0BB0;
410     public static final short delta 		= 0x0BB1;
411     public static final short epsilon 		= 0x0BB2;
412     public static final short zeta 			= 0x0BB3;
413     public static final short eta 			= 0x0BB4;
414     public static final short theta 		= 0x0BB5;
415     public static final short iota 			= 0x0BB6;
416     public static final short kappa 		= 0x0BB7;
417     public static final short lambda 		= 0x0BB8;
418     public static final short mu 			= 0x0BB9;
419     public static final short nu 			= 0x0BBA;
420     public static final short xi 			= 0x0BBB;
421     public static final short pi 			= 0x0BBC;
422     public static final short rho 			= 0x0BBD;
423     public static final short sigma 		= 0x0BBE;
424     public static final short tau 			= 0x0BBF;
425     public static final short upsilon 		= 0x0BC0;
426     public static final short phi 			= 0x0BC1;
427     public static final short chi 			= 0x0BC2;
428     public static final short psi 			= 0x0BC3;
429 
430     public static final short omega 		= 0x0B21;
431     public static final short varepsilon 	= 0x0B22;
432     public static final short vartheta 		= 0x0B23;
433     public static final short varpi 		= 0x0B24;
434     public static final short varrho 		= 0x0B25;
435     public static final short varphi 		= 0x0B27;
436 
437     public static final short Gamma 		= 0x0BA1;
438     public static final short Delta 		= 0x0BA2;
439     public static final short Theta 		= 0x0BA3;
440     public static final short Lambda		= 0x0BA4;
441     public static final short Xi 			= 0x0BA5;
442     public static final short Pi 			= 0x0BA6;
443     public static final short Sigma 		= 0x0BA7;
444     public static final short Upsilon 		= 0x0BA8;
445     public static final short Phi 			= 0x0BA9;
446     public static final short Psi 			= 0x0BAA;
447     public static final short Omega 		= 0x0BAD;
448 
449     public static final short rightarrow	= 0x0D21;
450     public static final short leftarrow		= 0x0DC3;
451     public static final short uparrow		= 0x0D22;
452     public static final short downarrow		= 0x0D23;
453     public static final short Rightarrow	= 0x0D27;
454     public static final short Leftarrow		= 0x0D28;
455     public static final short Uparrow		= 0x0D2A;
456     public static final short Downarrow		= 0x0D2B;
457 
458 
459     /**
460      * Small integral sign
461      */
462 	public static final short int_small 	= 0x0C52;
463 
464 	/**
465 	 * Large integral sign
466 	 */
467 	public static final short int_large 	= 0x0C5A;
468 
469 	/**
470 	 * Small summation sign (Sigma)
471 	 */
472 	public static final short sum_small 	= 0x0C50;
473 
474 	/**
475 	 * Large summation sign (Sigma)
476 	 */
477 	public static final short sum_large 	= 0x0C58;
478 
479 	/**
480 	 * Small closed loop integral sign
481 	 */
482 	public static final short oint_small 	= 0x0C48;
483 
484 	/**
485 	 * Large closed loop integral sign
486 	 */
487 	public static final short oint_large 	= 0x0C49;
488 
489 	/**
490 	 * Small product sign (pi)
491 	 */
492 	public static final short prod_small 	= 0x0C51;
493 
494 	/**
495 	 * Large product sign (pi)
496 	 */
497 	public static final short prod_large 	= 0x0C59;
498 
499 	/**
500 	 * Curl symbol (triangle)
501 	 */
502 	public static final short curl 			= 0x0D72;
503 
504 	/**
505 	 * Forward slash /
506 	 */
507 	public static final short slash 		= 0x0A00 + '/';
508 
509 	/**
510 	 * Vertical bar |
511 	 */
512 	public static final short abs_bar_tiny							= 0x0D6A;
513 
514 	public static final short bracket_paren_left_tiny				= 0x0A00 + '(';
515 	public static final short bracket_paren_left_small 				= 0x0CA1;
516 	public static final short bracket_paren_left_medium 			= 0x0CB3;
517 	public static final short bracket_paren_left_large 				= 0x0CB5;
518 	public static final short bracket_paren_left_xlarge 			= 0x0CC3;
519 	public static final short bracket_paren_left_head 				= 0x0C30;
520 	public static final short bracket_paren_left_tail 				= 0x0C40;
521 	public static final short bracket_paren_left_vertical_bar		= 0x0C42;
522 
523 	public static final short bracket_paren_right_tiny 				= 0x0A00 + ')';
524 	public static final short bracket_paren_right_small 			= 0x0CA2;
525 	public static final short bracket_paren_right_medium 			= 0x0CB4;
526 	public static final short bracket_paren_right_large 			= 0x0CB6;
527 	public static final short bracket_paren_right_xlarge 			= 0x0C21;
528 	public static final short bracket_paren_right_head 				= 0x0C31;
529 	public static final short bracket_paren_right_tail 				= 0x0C41;
530 	public static final short bracket_paren_right_vertical_bar		= 0x0C43;
531 
532 	public static final short bracket_square_left_tiny				= 0x0A00 + '[';
533 	public static final short bracket_square_left_small				= 0x0CA3;
534 	public static final short bracket_square_left_medium			= 0x0C68;
535 	public static final short bracket_square_left_large				= 0x0CB7;
536 	public static final short bracket_square_left_xlarge			= 0x0C22;
537 	public static final short bracket_square_left_head				= 0x0C32;
538 	public static final short bracket_square_left_tail				= 0x0C34;
539 	public static final short bracket_square_left_vertical_bar		= 0x0C36;
540 
541 	public static final short bracket_square_right_tiny				= 0x0A00 + ']';
542 	public static final short bracket_square_right_small			= 0x0CA4;
543 	public static final short bracket_square_right_medium			= 0x0C69;
544 	public static final short bracket_square_right_large			= 0x0CB8;
545 	public static final short bracket_square_right_xlarge			= 0x0C23;
546 	public static final short bracket_square_right_head				= 0x0C33;
547 	public static final short bracket_square_right_tail				= 0x0C35;
548 	public static final short bracket_square_right_vertical_bar		= 0x0C37;
549 
550 	public static final short bracket_curly_left_tiny 				= 0x0D66;
551 	public static final short bracket_curly_left_small				= 0x0CA9;
552 	public static final short bracket_curly_left_medium				= 0x0C6E;
553 	public static final short bracket_curly_left_large				= 0x0CBD;
554 	public static final short bracket_curly_left_xlarge				= 0x0C28;
555 	public static final short bracket_curly_left_head				= 0x0C38;
556 	public static final short bracket_curly_left_tail				= 0x0C3A;
557 	public static final short bracket_curly_left_vertical_bar		= 0x0C3E;
558 	public static final short bracket_curly_left_middle				= 0x0C3C;
559 
560 	public static final short bracket_curly_right_tiny 				= 0x0D67;
561 	public static final short bracket_curly_right_small				= 0x0CAA;
562 	public static final short bracket_curly_right_medium			= 0x0C6F;
563 	public static final short bracket_curly_right_large				= 0x0CBE;
564 	public static final short bracket_curly_right_xlarge			= 0x0C29;
565 	public static final short bracket_curly_right_head				= 0x0C39;
566 	public static final short bracket_curly_right_tail				= 0x0C3B;
567 	public static final short bracket_curly_right_vertical_bar		= 0x0C3E;
568 	public static final short bracket_curly_right_middle			= 0x0C3D;
569 
570 	/**
571 	 * The smallest square root sign
572 	 */
573 	public static final short sqrt_tiny 							= 0x0D70;
574 	public static final short sqrt_small							= 0x0C70;
575 	public static final short sqrt_medium							= 0x0C71;
576 	public static final short sqrt_large							= 0x0C72;
577 	public static final short sqrt_xlarge							= 0x0C73;
578 	public static final short sqrt_base								= 0x0C74;
579 	public static final short sqrt_vertical_bar						= 0x0C75;
580 	public static final short sqrt_corner							= 0x0C76;
581 
582 }
583