-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
37 lines (29 loc) · 1.23 KB
/
Program.cs
File metadata and controls
37 lines (29 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
using TeXpressions.Core;
using TeXpressions.Core.Common;
using TeXpressions.Parsing;
/*
See readme.md for more explanation of what's happening here.
*/
var texpr = ParseUtility.ParseInlineExpression<TeXpression<double>>(@"$\frac{2 \times 10}{4}$");
// the @ before the string makes it a verbatim string, so backslash \ doesn't get escaped
// slightly cleaner than the alternative "$\\frac{2 \\times 10}{4}$" :)
Console.WriteLine($"The expression back to inline LaTeX: ${texpr.ToLaTeX()}$");
Console.WriteLine($"And it evaluates to: {texpr.Evaluate()}");
/* Output
The expression back to inline LaTeX: $\frac{2 \times 10}{4}$
And it evaluates to: 5
*/
Console.WriteLine();
var texpr2 = Numeric.Divide( // Root: BinaryTeXpression
Numeric.Multiply( // Root.Left: BinaryTeXpression
Numeric.Constant(2), // Root.Left.Left: ConstantTeXpression
Numeric.Constant(10) // Root.Left.Right: ConstantTeXpression
),
Numeric.Constant(4) // Root.Right: ConstantTeXpression
);
Console.WriteLine($"texpr2 back to inline LaTeX: ${texpr2.ToLaTeX()}$");
Console.WriteLine($"This one evaluates to: {texpr2.Evaluate()}");
/* Output
texpr2 back to inline LaTeX: $\frac{2 \times 10}{4}$
This one evaluates to: 5
*/