latex bot discord
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
using Godot;


[Tool]
public class LaTeX : Sprite {
	// The following wordy declarations ensure that changing the properties 
	// inside the editor causes the expression to re-render.
	
	public string LatexExpression;
	[Export(PropertyHint.MultilineText)]
	private string _latexExpression {
		get {return LatexExpression;}
		set {
			// This runs when LatexExpression is set in the editor.
			
			LatexExpression = value;
			Render();
		}
	}
	
	public float FontSize = 40f;
	[Export(PropertyHint.Range, "10,60,1,or_greater,or_lesser")]
	private float _fontSize {
		get {return FontSize;}
		set {
			FontSize = value;
			Render();
		}
	} 
	
	public Color MathColor = new Color(0,0,0,1);
	[Export]
	private Color _mathColor {
		get {return MathColor;}
		set {
			MathColor = value;
			Render();
		}
	} 
	
	public bool AntiAliasing = true;
	[Export]
	private bool _antiAliasing {
		get {return AntiAliasing;}
		set {
			AntiAliasing = value;
			Render();
		}
	}
	
	public bool Fill = true;
	[Export]
	private bool _fill {
		get {return Fill;}
		set {
			Fill = value;
			Render();
		}
	}
	
	public bool ShowError = true;
	[Export]
	private bool _showError {
		get {return ShowError;}
		set {
			ShowError = value;
			Render();
		}
	}
	
	// These are the measures of the generated image.
	public float Width;
	public float Height;
	public float OffsetX;
	public float OffsetY;
	
	// You may call this from outside to re-render the expression.
	// This is not done automatically so that you can change the values very
	// often, say multiple times a millisecond, without significant slowdown.
	public void Render() {
		var texture = new LaTeXture();
		texture.LatexExpression = this.LatexExpression;
		texture.FontSize = this.FontSize;
		texture.AntiAliasing = this.AntiAliasing;
		texture.Fill = this.Fill;
		texture.MathColor = this.MathColor;
		texture.ShowError = this.ShowError;
		texture.Render();
		this.Texture = texture;
		this.Width = texture.Width;
		this.Height = texture.Height;
		this.OffsetX = texture.OffsetX;
		this.OffsetY = texture.OffsetY;
	}
	
	public override void _Ready() {
		Render();
	}
}