1 | ; |
---|
2 | ;+ |
---|
3 | ; NAME: |
---|
4 | ; TEXTOIDL |
---|
5 | ; PURPOSE: |
---|
6 | ; Convert a valid TeX string to a valid IDL string for plot labels. |
---|
7 | ; CATEGORY: |
---|
8 | ; text/strings |
---|
9 | ; CALLING SEQUENCE: |
---|
10 | ; new = textoidl(old) |
---|
11 | ; INPUTS: |
---|
12 | ; old -- TeX string to be converted. Will not be in |
---|
13 | ; modified. old may be a string array. |
---|
14 | ; KEYWORD PARAMETERS: |
---|
15 | ; FONT -- Set to 0 to use hardware font, -1 to use |
---|
16 | ; vector. Note that the only hardware font |
---|
17 | ; supported is PostScript. |
---|
18 | ; /TEX_SEQUENCES -- return the available TeX sequences |
---|
19 | ; /HELP -- print out info on use of the function |
---|
20 | ; and exit. |
---|
21 | ; OUTPUTS: |
---|
22 | ; new -- IDL string corresponding to old. out |
---|
23 | ; COMMON BLOCKS: |
---|
24 | ; SIDE EFFECTS: |
---|
25 | ; NOTES: |
---|
26 | ; - Use the procedure SHOWTEX to get a list of the available TeX |
---|
27 | ; control sequences. |
---|
28 | ; - The only hardware font for which translation is available is |
---|
29 | ; PostScript. |
---|
30 | ; - The only device for which hardware font' |
---|
31 | ; translation is available is PostScript.' |
---|
32 | ; - The FONT keyword overrides the font selected' |
---|
33 | ; by !p.font' |
---|
34 | ; EXAMPLE: |
---|
35 | ; out = TeXtoIDL('\Gamma^2 + 5N_{ed}') |
---|
36 | ; The string out may be used in XYOUTS or other IDL text |
---|
37 | ; display routines. It will be an uppercase Gamma, with an |
---|
38 | ; exponent of 2, then a plus sign, then an N with the subscript |
---|
39 | ; ed. |
---|
40 | ; MODIFICATION HISTORY: |
---|
41 | ; $Id$ |
---|
42 | ; $Log: textoidl.pro,v $ |
---|
43 | ; Revision 1.7 2004/06/15 17:25:54 mcraig |
---|
44 | ; Fixed bug in regular expression, changed array notation to square brackets |
---|
45 | ; |
---|
46 | ; Revision 1.6 2004/01/11 01:49:00 mcraig |
---|
47 | ; Changed format of one array to newer [] style to avoidf conflict with function name in astro library. |
---|
48 | ; |
---|
49 | ; Revision 1.5 2001/11/23 21:10:55 mcraig |
---|
50 | ; Added backslash '\' to tex sequences in translation table to protect them during regexp search in strsplit. |
---|
51 | ; |
---|
52 | ; Revision 1.4 1996/06/14 20:00:27 mcraig |
---|
53 | ; Updated Copyright info. |
---|
54 | ; |
---|
55 | ; Revision 1.3 1996/05/09 00:22:17 mcraig |
---|
56 | ; Added error handling, cleaned up documentation. |
---|
57 | ; |
---|
58 | ; Revision 1.2 1996/02/08 18:52:50 mcraig |
---|
59 | ; Added ability to use hardware fonts for PostScript device. |
---|
60 | ; |
---|
61 | ; Revision 1.1 1996/01/31 18:47:37 mcraig |
---|
62 | ; Initial revision |
---|
63 | ; |
---|
64 | ; RELEASE: |
---|
65 | ; $Name: Rel_2_1_2 $ |
---|
66 | ; |
---|
67 | ; COPYRIGHT: |
---|
68 | ; Copyright (C) 1996 The Regents of the University of California, All |
---|
69 | ; Rights Reserved. Written by Matthew W. Craig. |
---|
70 | ; See the file COPYRIGHT for restrictions on distrubting this code. |
---|
71 | ; This code comes with absolutely NO warranty; see DISCLAIMER for details. |
---|
72 | ;- |
---|
73 | ; |
---|
74 | FUNCTION Textoidl, InputString, $ |
---|
75 | FONT=fnt, $ |
---|
76 | HELP=hlp, $ |
---|
77 | TEX_SEQUENCES=tex_seq |
---|
78 | ; |
---|
79 | compile_opt idl2, strictarrsubs |
---|
80 | ; |
---|
81 | |
---|
82 | ; Return to caller if there is an error. |
---|
83 | On_error, 2 |
---|
84 | ; We begin by deciding on the font. PostScript = 0 means use vector. |
---|
85 | PostScript = 0 |
---|
86 | IF n_elements(fnt) EQ 0 THEN BEGIN ; get font from !p.font |
---|
87 | IF !p.font NE -1 THEN BEGIN ; User wants hardware font. |
---|
88 | PostScript=1 |
---|
89 | ENDIF |
---|
90 | ENDIF ELSE BEGIN ; get font from FONT keyword |
---|
91 | IF fnt NE -1 THEN PostScript = 1 |
---|
92 | ENDELSE |
---|
93 | |
---|
94 | ; Bomb out if user wants non-PostScript hardware font. |
---|
95 | IF (PostScript EQ 1) AND (!d.name NE 'PS') THEN BEGIN |
---|
96 | ; Device isn't postscript |
---|
97 | ; and user wants hardware |
---|
98 | ; font. Not good. |
---|
99 | print,'Warning: No translation for device: ',!d.name |
---|
100 | return,InputString |
---|
101 | ENDIF |
---|
102 | |
---|
103 | IF keyword_set (tex_seq) THEN BEGIN |
---|
104 | table=textable() |
---|
105 | return,table[0,*] |
---|
106 | ENDIF |
---|
107 | |
---|
108 | IF keyword_set(hlp) OR (n_params() EQ 0) THEN BEGIN |
---|
109 | print, ' Convert a TeX string to an IDL string' |
---|
110 | print, ' new = TeXtoIDL(old)' |
---|
111 | print, ' old = TeX string to translate. in' |
---|
112 | print, ' new = resulting IDL string. out' |
---|
113 | print, ' Keywords:' |
---|
114 | print, ' FONT set to -1 to translate for vector fonts ' |
---|
115 | print, ' (DEFAULT) . Set to 0 to translate for' |
---|
116 | print, ' hardware font.' |
---|
117 | print, ' /TEX_SEQUENCES -- return the available TeX sequences' |
---|
118 | print, ' /HELP print this message and exit.' |
---|
119 | print, ' NOTES: ' |
---|
120 | print, ' - Use SHOWTEX to obtain a list of the available' |
---|
121 | print, ' TeX control sequences.' |
---|
122 | print, ' - old may be a string array. If so, new is too.' |
---|
123 | print, ' - The only device for which hardware font' |
---|
124 | print, ' translation is available is PostScript.' |
---|
125 | print, ' - The FONT keyword overrides the font selected' |
---|
126 | print, ' by !p.font' |
---|
127 | return, -1 |
---|
128 | ENDIF |
---|
129 | |
---|
130 | ; PostScript has been set to 1 if PostScript fonts are desired. |
---|
131 | strn = InputString |
---|
132 | table = textable(POSTSCRIPT=PostScript) |
---|
133 | |
---|
134 | ; Greek sub/superscripts need to be protected by putting braces |
---|
135 | ; around them if they are unbraced. This will have the result the |
---|
136 | ; it will be difficult to use \ as a sub/superscript. Get over it. |
---|
137 | |
---|
138 | ; V2.11 Must include the '\' in from of translation table TeX |
---|
139 | ; sequences to ensure that strsplit properly treats the '\' in the |
---|
140 | ; TeX sequence. Since strsplit is doing a regexp replace, and '\' is |
---|
141 | ; special in regexps, need to escape it. |
---|
142 | strn = strtrans(strn, '\^'+'\'+table[0, *], '^{'+table[0, *]+'}') |
---|
143 | strn = strtrans(strn, '\_'+'\'+table[0, *], '_{'+table[0, *]+'}') |
---|
144 | |
---|
145 | ; First we translate Greek letters and the like. This makes guessing |
---|
146 | ; alignment of sub/superscripts easier, as all special characters will then |
---|
147 | ; be one character long. |
---|
148 | |
---|
149 | ; V2.11 Must include the '\' in from of translation table TeX |
---|
150 | ; sequences to ensure that strsplit properly treats the '\' in the |
---|
151 | ; TeX sequence. Since strsplit is doing a regexp replace, and '\' is |
---|
152 | ; special in regexps, need to escape it. |
---|
153 | strn = strtrans(strn, '\'+table[0, *], table[1, *]) |
---|
154 | |
---|
155 | |
---|
156 | FOR i = 0L, n_elements(strn)-1 DO BEGIN |
---|
157 | strn[i] = translate_sub_super(strn[i]) ; Take care of sub/superscripts |
---|
158 | ENDFOR |
---|
159 | |
---|
160 | return,strn |
---|
161 | END |
---|