source: trunk/SRC/Textoidl/textoidl.pro @ 325

Last change on this file since 325 was 325, checked in by pinsard, 16 years ago

modification of some headers (+some corrections) to prepare usage of the new idldoc

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