source: branches/symbreg-factors-2650/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Formatters/SymbolicDataAnalysisExpressionLatexFormatter.cs @ 14277

Last change on this file since 14277 was 14277, checked in by gkronber, 5 years ago

#2650: merged r14245:14273 from trunk to branch (fixing conflicts in RegressionSolutionTargetResponseGradientView)

File size: 22.6 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2016 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using System;
23using System.Collections.Generic;
24using System.Linq;
25using System.Text;
26using HeuristicLab.Common;
27using HeuristicLab.Core;
28using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
29using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
30
31namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
32  [Item("LaTeX String Formatter", "Formatter for symbolic expression trees for import into LaTeX documents.")]
33  [StorableClass]
34  public sealed class SymbolicDataAnalysisExpressionLatexFormatter : NamedItem, ISymbolicExpressionTreeStringFormatter {
35    private readonly List<KeyValuePair<string, double>> constants;
36    private int constIndex;
37    private int targetCount;
38    private int currentLag;
39    private string targetVariable;
40    private bool containsTimeSeriesSymbol;
41
42    [StorableConstructor]
43    private SymbolicDataAnalysisExpressionLatexFormatter(bool deserializing) : base(deserializing) { }
44    private SymbolicDataAnalysisExpressionLatexFormatter(SymbolicDataAnalysisExpressionLatexFormatter original, Cloner cloner)
45      : base(original, cloner) {
46      constants = new List<KeyValuePair<string, double>>(original.constants);
47      constIndex = original.constIndex;
48      currentLag = original.currentLag;
49      targetCount = original.targetCount;
50    }
51    public SymbolicDataAnalysisExpressionLatexFormatter()
52      : base() {
53      Name = ItemName;
54      Description = ItemDescription;
55      constants = new List<KeyValuePair<string, double>>();
56    }
57
58    public override IDeepCloneable Clone(Cloner cloner) {
59      return new SymbolicDataAnalysisExpressionLatexFormatter(this, cloner);
60    }
61
62    public string Format(ISymbolicExpressionTree symbolicExpressionTree) {
63      return Format(symbolicExpressionTree, null);
64    }
65    public string Format(ISymbolicExpressionTree symbolicExpressionTree, string targetVariable) {
66      try {
67        StringBuilder strBuilder = new StringBuilder();
68        constants.Clear();
69        constIndex = 0;
70        this.targetVariable = targetVariable;
71        containsTimeSeriesSymbol = symbolicExpressionTree.IterateNodesBreadth().Any(n => IsTimeSeriesSymbol(n.Symbol));
72        strBuilder.AppendLine(FormatRecursively(symbolicExpressionTree.Root));
73        return strBuilder.ToString();
74      } catch (NotImplementedException ex) {
75        return ex.Message + Environment.NewLine + ex.StackTrace;
76      }
77    }
78    static bool IsTimeSeriesSymbol(ISymbol s) {
79      return s is TimeLag || s is Integral || s is Derivative || s is LaggedVariable;
80    }
81
82    private string FormatRecursively(ISymbolicExpressionTreeNode node) {
83      StringBuilder strBuilder = new StringBuilder();
84      currentLag = 0;
85      FormatBegin(node, strBuilder);
86
87      if (node.SubtreeCount > 0) {
88        strBuilder.Append(FormatRecursively(node.GetSubtree(0)));
89      }
90      int i = 1;
91      foreach (var subTree in node.Subtrees.Skip(1)) {
92        FormatSep(node, strBuilder, i);
93        // format the whole subtree
94        strBuilder.Append(FormatRecursively(subTree));
95        i++;
96      }
97
98      FormatEnd(node, strBuilder);
99
100      return strBuilder.ToString();
101    }
102
103    private void FormatBegin(ISymbolicExpressionTreeNode node, StringBuilder strBuilder) {
104      if (node.Symbol is Addition) {
105        strBuilder.Append(@" \left( ");
106      } else if (node.Symbol is Subtraction) {
107        if (node.SubtreeCount == 1) {
108          strBuilder.Append(@"- \left( ");
109        } else {
110          strBuilder.Append(@" \left( ");
111        }
112      } else if (node.Symbol is Multiplication) {
113      } else if (node.Symbol is Division) {
114        if (node.SubtreeCount == 1) {
115          strBuilder.Append(@" \cfrac{1");
116        } else {
117          strBuilder.Append(@" \cfrac{ ");
118        }
119      } else if (node.Symbol is Average) {
120        // skip output of (1/1) if only one subtree
121        if (node.SubtreeCount > 1) {
122          strBuilder.Append(@" \cfrac{1}{" + node.SubtreeCount + @"}");
123        }
124        strBuilder.Append(@" \left( ");
125      } else if (node.Symbol is Logarithm) {
126        strBuilder.Append(@"\log \left( ");
127      } else if (node.Symbol is Exponential) {
128        strBuilder.Append(@"\exp \left( ");
129      } else if (node.Symbol is Square) {
130        strBuilder.Append(@"\left(");
131      } else if (node.Symbol is SquareRoot) {
132        strBuilder.Append(@"\sqrt{");
133      } else if (node.Symbol is Sine) {
134        strBuilder.Append(@"\sin \left( ");
135      } else if (node.Symbol is Cosine) {
136        strBuilder.Append(@"\cos \left( ");
137      } else if (node.Symbol is Tangent) {
138        strBuilder.Append(@"\tan \left( ");
139      } else if (node.Symbol is AiryA) {
140        strBuilder.Append(@"\operatorname{airy}_a \left( ");
141      } else if (node.Symbol is AiryB) {
142        strBuilder.Append(@"\operatorname{airy}_b \left( ");
143      } else if (node.Symbol is Bessel) {
144        strBuilder.Append(@"\operatorname{bessel}_1 \left( ");
145      } else if (node.Symbol is CosineIntegral) {
146        strBuilder.Append(@"\operatorname{cosInt} \left( ");
147      } else if (node.Symbol is Dawson) {
148        strBuilder.Append(@"\operatorname{dawson} \left( ");
149      } else if (node.Symbol is Erf) {
150        strBuilder.Append(@"\operatorname{erf} \left( ");
151      } else if (node.Symbol is ExponentialIntegralEi) {
152        strBuilder.Append(@"\operatorname{expInt}_i \left( ");
153      } else if (node.Symbol is FresnelCosineIntegral) {
154        strBuilder.Append(@"\operatorname{fresnel}_\operatorname{cosInt} \left( ");
155      } else if (node.Symbol is FresnelSineIntegral) {
156        strBuilder.Append(@"\operatorname{fresnel}_\operatorname{sinInt} \left( ");
157      } else if (node.Symbol is Gamma) {
158        strBuilder.Append(@"\Gamma \left( ");
159      } else if (node.Symbol is HyperbolicCosineIntegral) {
160        strBuilder.Append(@"\operatorname{hypCosInt} \left( ");
161      } else if (node.Symbol is HyperbolicSineIntegral) {
162        strBuilder.Append(@"\operatorname{hypSinInt} \left( ");
163      } else if (node.Symbol is Norm) {
164        strBuilder.Append(@"\operatorname{norm} \left( ");
165      } else if (node.Symbol is Psi) {
166        strBuilder.Append(@"\operatorname{digamma} \left( ");
167      } else if (node.Symbol is SineIntegral) {
168        strBuilder.Append(@"\operatorname{sinInt} \left( ");
169      } else if (node.Symbol is GreaterThan) {
170        strBuilder.Append(@"  \left( ");
171      } else if (node.Symbol is LessThan) {
172        strBuilder.Append(@"  \left( ");
173      } else if (node.Symbol is And) {
174        strBuilder.Append(@"  \left( \left( ");
175      } else if (node.Symbol is Or) {
176        strBuilder.Append(@"   \left( \left( ");
177      } else if (node.Symbol is Not) {
178        strBuilder.Append(@" \neg \left( ");
179      } else if (node.Symbol is IfThenElse) {
180        strBuilder.Append(@" \operatorname{if}  \left( ");
181      } else if (node.Symbol is Constant) {
182        var constName = "c_{" + constIndex + "}";
183        constIndex++;
184        strBuilder.Append(constName + " ");
185        var constNode = node as ConstantTreeNode;
186        constants.Add(new KeyValuePair<string, double>(constName, constNode.Value));
187      } else if (node.Symbol is FactorVariable) {
188        var factorNode = node as FactorVariableTreeNode;
189        var constName = "c_{" + constIndex + "}";
190        strBuilder.Append(constName + " ");
191        foreach (var e in factorNode.Symbol.GetVariableValues(factorNode.VariableName)
192          .Zip(factorNode.Weights, Tuple.Create)) {
193          constants.Add(new KeyValuePair<string, double>("c_{" + constIndex + ", " + EscapeLatexString(factorNode.VariableName) + "=" + EscapeLatexString(e.Item1) + "}", e.Item2));
194        }
195        constIndex++;
196      } else if (node.Symbol is BinaryFactorVariable) {
197        var binFactorNode = node as BinaryFactorVariableTreeNode;
198        if (!binFactorNode.Weight.IsAlmost((1.0))) {
199          var constName = "c_{" + constIndex + "}";
200          strBuilder.Append(constName + "  \\cdot");
201          constants.Add(new KeyValuePair<string, double>(constName, binFactorNode.Weight));
202          constIndex++;
203        }
204        strBuilder.Append(EscapeLatexString(binFactorNode.VariableName));
205        strBuilder.Append(LagToString(currentLag));
206        strBuilder.Append(" = " + EscapeLatexString(binFactorNode.VariableValue));
207      } else if (node.Symbol is LaggedVariable) {
208        var laggedVarNode = node as LaggedVariableTreeNode;
209        if (!laggedVarNode.Weight.IsAlmost(1.0)) {
210          var constName = "c_{" + constIndex + "}";
211          strBuilder.Append(constName + "  \\cdot");
212          constants.Add(new KeyValuePair<string, double>(constName, laggedVarNode.Weight));
213          constIndex++;
214        }
215        strBuilder.Append(EscapeLatexString(laggedVarNode.VariableName));
216        strBuilder.Append(LagToString(currentLag + laggedVarNode.Lag));
217
218      } else if (node.Symbol is Variable) {
219        var varNode = node as VariableTreeNode;
220        if (!varNode.Weight.IsAlmost((1.0))) {
221          var constName = "c_{" + constIndex + "}";
222          strBuilder.Append(constName + "  \\cdot");
223          constants.Add(new KeyValuePair<string, double>(constName, varNode.Weight));
224          constIndex++;
225        }
226        strBuilder.Append(EscapeLatexString(varNode.VariableName));
227        strBuilder.Append(LagToString(currentLag));
228      } else if (node.Symbol is ProgramRootSymbol) {
229        strBuilder
230          .AppendLine("\\begin{align*}")
231          .AppendLine("\\nonumber");
232      } else if (node.Symbol is Defun) {
233        var defunNode = node as DefunTreeNode;
234        strBuilder.Append(defunNode.FunctionName + " & = ");
235      } else if (node.Symbol is InvokeFunction) {
236        var invokeNode = node as InvokeFunctionTreeNode;
237        strBuilder.Append(invokeNode.Symbol.FunctionName + @" \left( ");
238      } else if (node.Symbol is StartSymbol) {
239        FormatStartSymbol(strBuilder);
240      } else if (node.Symbol is Argument) {
241        var argSym = node.Symbol as Argument;
242        strBuilder.Append(" ARG+" + argSym.ArgumentIndex + " ");
243      } else if (node.Symbol is Derivative) {
244        strBuilder.Append(@" \cfrac{d \left( ");
245      } else if (node.Symbol is TimeLag) {
246        var laggedNode = node as ILaggedTreeNode;
247        currentLag += laggedNode.Lag;
248      } else if (node.Symbol is Power) {
249        strBuilder.Append(@" \left( ");
250      } else if (node.Symbol is Root) {
251        strBuilder.Append(@" \left( ");
252      } else if (node.Symbol is Integral) {
253        // actually a new variable for t is needed in all subtrees (TODO)
254        var laggedTreeNode = node as ILaggedTreeNode;
255        strBuilder.Append(@"\sum_{t=" + (laggedTreeNode.Lag + currentLag) + @"}^0 \left( ");
256      } else if (node.Symbol is VariableCondition) {
257        var conditionTreeNode = node as VariableConditionTreeNode;
258        var constName = "c_{" + constants.Count + "}";
259        string p = @"1 /  1 + \exp  - " + constName + " ";
260        constants.Add(new KeyValuePair<string, double>(constName, conditionTreeNode.Slope));
261        constIndex++;
262        var const2Name = "c_{" + constants.Count + @"}";
263        p += @" \cdot " + EscapeLatexString(conditionTreeNode.VariableName) + LagToString(currentLag) + " - " + const2Name + "   ";
264        constants.Add(new KeyValuePair<string, double>(const2Name, conditionTreeNode.Threshold));
265        constIndex++;
266        strBuilder.Append(@" \left( " + p + @"\cdot ");
267      } else {
268        throw new NotImplementedException("Export of " + node.Symbol + " is not implemented.");
269      }
270    }
271
272    private void FormatSep(ISymbolicExpressionTreeNode node, StringBuilder strBuilder, int step) {
273      if (node.Symbol is Addition) {
274        strBuilder.Append(" + ");
275      } else if (node.Symbol is Subtraction) {
276        strBuilder.Append(" - ");
277      } else if (node.Symbol is Multiplication) {
278        strBuilder.Append(@" \cdot ");
279      } else if (node.Symbol is Division) {
280        if (step + 1 == node.SubtreeCount)
281          strBuilder.Append(@"}{");
282        else
283          strBuilder.Append(@" }{ \cfrac{ ");
284      } else if (node.Symbol is Average) {
285        strBuilder.Append(@" + ");
286      } else if (node.Symbol is Logarithm) {
287        throw new InvalidOperationException();
288      } else if (node.Symbol is Exponential) {
289        throw new InvalidOperationException();
290      } else if (node.Symbol is Square) {
291        throw new InvalidOperationException();
292      } else if (node.Symbol is SquareRoot) {
293        throw new InvalidOperationException();
294      } else if (node.Symbol is Sine) {
295        throw new InvalidOperationException();
296      } else if (node.Symbol is Cosine) {
297        throw new InvalidOperationException();
298      } else if (node.Symbol is Tangent) {
299        throw new InvalidOperationException();
300      } else if (node.Symbol is AiryA) {
301        throw new InvalidOperationException();
302      } else if (node.Symbol is AiryB) {
303        throw new InvalidOperationException();
304      } else if (node.Symbol is Bessel) {
305        throw new InvalidOperationException();
306      } else if (node.Symbol is CosineIntegral) {
307        throw new InvalidOperationException();
308      } else if (node.Symbol is Dawson) {
309        throw new InvalidOperationException();
310      } else if (node.Symbol is Erf) {
311        throw new InvalidOperationException();
312      } else if (node.Symbol is ExponentialIntegralEi) {
313        throw new InvalidOperationException();
314      } else if (node.Symbol is FresnelCosineIntegral) {
315        throw new InvalidOperationException();
316      } else if (node.Symbol is FresnelSineIntegral) {
317        throw new InvalidOperationException();
318      } else if (node.Symbol is Gamma) {
319        throw new InvalidOperationException();
320      } else if (node.Symbol is HyperbolicCosineIntegral) {
321        throw new InvalidOperationException();
322      } else if (node.Symbol is HyperbolicSineIntegral) {
323        throw new InvalidOperationException();
324      } else if (node.Symbol is Norm) {
325        throw new InvalidOperationException();
326      } else if (node.Symbol is Psi) {
327        throw new InvalidOperationException();
328      } else if (node.Symbol is SineIntegral) {
329        throw new InvalidOperationException();
330      } else if (node.Symbol is GreaterThan) {
331        strBuilder.Append(@" > ");
332      } else if (node.Symbol is LessThan) {
333        strBuilder.Append(@" < ");
334      } else if (node.Symbol is And) {
335        strBuilder.Append(@" > 0  \right) \land \left(");
336      } else if (node.Symbol is Or) {
337        strBuilder.Append(@" > 0  \right) \lor \left(");
338      } else if (node.Symbol is Not) {
339        throw new InvalidOperationException();
340      } else if (node.Symbol is IfThenElse) {
341        strBuilder.Append(@" , ");
342      } else if (node.Symbol is ProgramRootSymbol) {
343        strBuilder.Append(@"\\" + Environment.NewLine);
344      } else if (node.Symbol is Defun) {
345      } else if (node.Symbol is InvokeFunction) {
346        strBuilder.Append(" , ");
347      } else if (node.Symbol is StartSymbol) {
348        strBuilder.Append(@"\\" + Environment.NewLine);
349        FormatStartSymbol(strBuilder);
350      } else if (node.Symbol is Power) {
351        strBuilder.Append(@"\right) ^ { \operatorname{round} \left(");
352      } else if (node.Symbol is Root) {
353        strBuilder.Append(@"\right) ^ {  \cfrac{1}{ \operatorname{round} \left(");
354      } else if (node.Symbol is VariableCondition) {
355        var conditionTreeNode = node as VariableConditionTreeNode;
356        var const1Name = "c_{" + constants.Count + "}";
357        string p = @"1 / \left( 1 + \exp \left( - " + const1Name + " ";
358        constants.Add(new KeyValuePair<string, double>(const1Name, conditionTreeNode.Slope));
359        constIndex++;
360        var const2Name = "c_{" + constants.Count + "}";
361        p += @" \cdot " + EscapeLatexString(conditionTreeNode.VariableName) + LagToString(currentLag) + " - " + const2Name + " \right) \right) \right)   ";
362        constants.Add(new KeyValuePair<string, double>(const2Name, conditionTreeNode.Threshold));
363        constIndex++;
364        strBuilder.Append(@" +  \left( 1 - " + p + @" \right) \cdot ");
365      } else {
366        throw new NotImplementedException("Export of " + node.Symbol + " is not implemented.");
367      }
368    }
369
370    private void FormatEnd(ISymbolicExpressionTreeNode node, StringBuilder strBuilder) {
371      if (node.Symbol is Addition) {
372        strBuilder.Append(@" \right) ");
373      } else if (node.Symbol is Subtraction) {
374        strBuilder.Append(@" \right) ");
375      } else if (node.Symbol is Multiplication) {
376      } else if (node.Symbol is Division) {
377        strBuilder.Append(" } ");
378        for (int i = 2; i < node.SubtreeCount; i++)
379          strBuilder.Append(" } ");
380      } else if (node.Symbol is Average) {
381        strBuilder.Append(@" \right) ");
382      } else if (node.Symbol is Logarithm) {
383        strBuilder.Append(@" \right) ");
384      } else if (node.Symbol is Exponential) {
385        strBuilder.Append(@" \right) ");
386      } else if (node.Symbol is Square) {
387        strBuilder.Append(@"\right)^2");
388      } else if (node.Symbol is SquareRoot) {
389        strBuilder.Append(@"}");
390      } else if (node.Symbol is Sine) {
391        strBuilder.Append(@" \right) ");
392      } else if (node.Symbol is Cosine) {
393        strBuilder.Append(@" \right) ");
394      } else if (node.Symbol is Tangent) {
395        strBuilder.Append(@" \right) ");
396      } else if (node.Symbol is AiryA) {
397        strBuilder.Append(@" \right) ");
398      } else if (node.Symbol is AiryB) {
399        strBuilder.Append(@" \right) ");
400      } else if (node.Symbol is Bessel) {
401        strBuilder.Append(@" \right) ");
402      } else if (node.Symbol is CosineIntegral) {
403        strBuilder.Append(@" \right) ");
404      } else if (node.Symbol is Dawson) {
405        strBuilder.Append(@" \right) ");
406      } else if (node.Symbol is Erf) {
407        strBuilder.Append(@" \right) ");
408      } else if (node.Symbol is ExponentialIntegralEi) {
409        strBuilder.Append(@" \right) ");
410      } else if (node.Symbol is FresnelCosineIntegral) {
411        strBuilder.Append(@" \right) ");
412      } else if (node.Symbol is FresnelSineIntegral) {
413        strBuilder.Append(@" \right) ");
414      } else if (node.Symbol is Gamma) {
415        strBuilder.Append(@" \right) ");
416      } else if (node.Symbol is HyperbolicCosineIntegral) {
417        strBuilder.Append(@" \right) ");
418      } else if (node.Symbol is HyperbolicSineIntegral) {
419        strBuilder.Append(@" \right) ");
420      } else if (node.Symbol is Norm) {
421        strBuilder.Append(@" \right) ");
422      } else if (node.Symbol is Psi) {
423        strBuilder.Append(@" \right) ");
424      } else if (node.Symbol is SineIntegral) {
425        strBuilder.Append(@" \right) ");
426      } else if (node.Symbol is GreaterThan) {
427        strBuilder.Append(@" \right) ");
428      } else if (node.Symbol is LessThan) {
429        strBuilder.Append(@" \right) ");
430      } else if (node.Symbol is And) {
431        strBuilder.Append(@" > 0 \right) \right) ");
432      } else if (node.Symbol is Or) {
433        strBuilder.Append(@" > 0 \right) \right) ");
434      } else if (node.Symbol is Not) {
435        strBuilder.Append(@" \right) ");
436      } else if (node.Symbol is IfThenElse) {
437        strBuilder.Append(@" \right) ");
438      } else if (node.Symbol is Constant) {
439      } else if (node.Symbol is LaggedVariable) {
440      } else if (node.Symbol is Variable) {
441      } else if (node.Symbol is FactorVariable) {
442      } else if (node.Symbol is BinaryFactorVariable) {
443      } else if (node.Symbol is ProgramRootSymbol) {
444        strBuilder
445          .AppendLine("\\end{align*}")
446          .AppendLine("\\begin{align*}")
447          .AppendLine("\\nonumber");
448        // output all constant values
449        if (constants.Count > 0) {
450          foreach (var constant in constants) {
451            // replace "." with ".&" to align decimal points
452            var constStr = string.Format(System.Globalization.NumberFormatInfo.InvariantInfo, "{0:G5}", constant.Value);
453            if (!constStr.Contains(".")) constStr = constStr + ".0";
454            constStr = constStr.Replace(".", "&.");  // fix problem in rendering of aligned expressions
455            strBuilder.Append(constant.Key + "& = & " + constStr);
456            strBuilder.Append(@"\\");
457          }
458        }
459        strBuilder.AppendLine("\\end{align*}");
460      } else if (node.Symbol is Defun) {
461      } else if (node.Symbol is InvokeFunction) {
462        strBuilder.Append(@" \right) ");
463      } else if (node.Symbol is StartSymbol) {
464      } else if (node.Symbol is Argument) {
465      } else if (node.Symbol is Derivative) {
466        strBuilder.Append(@" \right) }{dt} ");
467      } else if (node.Symbol is TimeLag) {
468        var laggedNode = node as ILaggedTreeNode;
469        currentLag -= laggedNode.Lag;
470      } else if (node.Symbol is Power) {
471        strBuilder.Append(@" \right) } ");
472      } else if (node.Symbol is Root) {
473        strBuilder.Append(@" \right) } } ");
474      } else if (node.Symbol is Integral) {
475        strBuilder.Append(@" \right) ");
476      } else if (node.Symbol is VariableCondition) {
477        strBuilder.Append(@"\right) ");
478      } else {
479        throw new NotImplementedException("Export of " + node.Symbol + " is not implemented.");
480      }
481    }
482
483    private void FormatStartSymbol(StringBuilder strBuilder) {
484      strBuilder.Append(targetVariable ?? "target_" + (targetCount++));
485      if (containsTimeSeriesSymbol)
486        strBuilder.Append("(t)");
487      strBuilder.Append(" & = ");
488    }
489
490    private string LagToString(int lag) {
491      if (lag < 0) {
492        return "(t" + lag + ")";
493      } else if (lag > 0) {
494        return "(t+" + lag + ")";
495      } else return "";
496    }
497
498    private string EscapeLatexString(string s) {
499      return "\\text{" +
500        s
501         .Replace("\\", "\\\\")
502         .Replace("{", "\\{")
503         .Replace("}", "\\}")
504        + "}";
505    }
506  }
507}
Note: See TracBrowser for help on using the repository browser.