Converts TeX-like notation for Greek symbols to unicode characters. @param s the string in TeX-like notation @return
(String s)
| 78 | * @return |
| 79 | */ |
| 80 | public static String parseTeX(String s) { |
| 81 | int pt; |
| 82 | // BH 2020.06.27 no need for regex (String.split) -- just a simple check |
| 83 | if (s == null || (pt = s.indexOf("$\\")) < 0) { |
| 84 | return s; |
| 85 | } |
| 86 | int off = 1; |
| 87 | while (pt >= 0) { |
| 88 | int pt1 = s.indexOf("$", pt + 1); |
| 89 | if (pt1 < 0) { |
| 90 | pt1 = s.length(); |
| 91 | off = 0; |
| 92 | } |
| 93 | String ch = charMap.get(s.substring(pt + 1, pt1)); |
| 94 | s = s.substring(0, pt) + (ch == null ? s.substring(pt + 2, pt1) : ch) + s.substring(pt1 + off); |
| 95 | pt = (off == 0 ? -1 : s.indexOf("$\\", pt + 1)); |
| 96 | } |
| 97 | return s; |
| 98 | // OSPLog.debug("TeXParser.parse " + s + " " + ++np); |
| 99 | // String[] chunks = s.split("\\$"); //$NON-NLS-1$ |
| 100 | // // boolean mathMode=(s.charAt(0)=='$'); |
| 101 | // boolean mathMode = false; |
| 102 | // for (int i = 0; i < chunks.length; i++) { |
| 103 | // if (mathMode) { |
| 104 | // String val = charMap.get(chunks[i].trim()); |
| 105 | // if (val != null) { |
| 106 | // chunks[i] = val; |
| 107 | // } |
| 108 | // } |
| 109 | // mathMode = !mathMode; |
| 110 | // } |
| 111 | // String outStr = ""; //$NON-NLS-1$ |
| 112 | // for (int i = 0; i < chunks.length; i++) { |
| 113 | // outStr += chunks[i]; |
| 114 | // } |
| 115 | // return outStr; |
| 116 | } |
| 117 | |
| 118 | |
| 119 |