latex bot discord
smallen
| -rw-r--r-- | Latex.gd | 7 | ||||
| -rw-r--r-- | addons/GodoTeX/LaTeXture.cs | 2 |
2 files changed, 7 insertions, 2 deletions
@@ -3,6 +3,8 @@ class_name LaTeXbot const laTeXture := preload("./addons/GodoTeX/LaTeXture.cs") +var max_height := 200 + func compile(source: String) -> RegEx: var reg := RegEx.new() reg.compile(source) @@ -57,7 +59,7 @@ func _on_message_create(_bot: DiscordBot, message: Message, _channel: Dictionary return var img := latex2img(msg) - reply(message, "Tex:", {"files": [{"name": "latex.png", "media_type": "image/png", "data": img}]}) + reply(message, "", {"files": [{"name": "latex.png", "media_type": "image/png", "data": img}]}) func _on_interaction_create(_bot: DiscordBot, interaction: DiscordInteraction) -> void: if not interaction.is_command(): @@ -87,5 +89,8 @@ func latex2img(latex: String) -> PoolByteArray: tex.Fill = true tex.FontSize = 80 tex.Render() + while tex.get_height() > max_height: + tex.FontSize /= 2 + tex.Render() print_debug("took %.2f seconds" % ((Time.get_ticks_usec() - t) / 1000000.0)) return tex.get_data().save_png_to_buffer() diff --git a/addons/GodoTeX/LaTeXture.cs b/addons/GodoTeX/LaTeXture.cs index 87bd293..d0defef 100644 --- a/addons/GodoTeX/LaTeXture.cs +++ b/addons/GodoTeX/LaTeXture.cs @@ -31,7 +31,7 @@ public class LaTeXture : ImageTexture { paintStyle = CSharpMath.Rendering.FrontEnd.PaintStyle.Fill; } - this.Painter = new MathPainter {AntiAlias = this.AntiAliasing, TextColor = new SKColor(r, g, b, a), FontSize = this.FontSize, LaTeX = @"\raisebox{40mu}{}\raisebox{-40mu}{}" + this.LatexExpression + @"\:\raisebox{1mu}", DisplayErrorInline = this.ShowError, PaintStyle = paintStyle}; + this.Painter = new MathPainter {AntiAlias = this.AntiAliasing, TextColor = new SKColor(r, g, b, a), FontSize = this.FontSize, LaTeX = this.LatexExpression, DisplayErrorInline = this.ShowError, PaintStyle = paintStyle}; var measure = this.Painter.Measure(); this.Width = measure.Width; |