From 38ba8d9d0c471753c9208d757d3e5e76f091d0ea Mon Sep 17 00:00:00 2001 From: thxo <21995564+thxo@users.noreply.github.com> Date: Fri, 9 Apr 2021 16:39:46 -0700 Subject: [PATCH] Tex command: more helpful error messages (#416) * replace error message with common mistakes * explicitly mention document mode in docstring * add changelog fixes #415 Co-authored-by: thxo --- CHANGELOG.md | 2 ++ exts/tex.py | 11 +++++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 46d50ba..cb7db6c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ## [Unreleased] +### Added +- Helpful LaTeX hints for rendering errors in `?tex`. ## [2.7.0] - 2021-04-03 diff --git a/exts/tex.py b/exts/tex.py index e521cda..430fe6c 100644 --- a/exts/tex.py +++ b/exts/tex.py @@ -28,7 +28,10 @@ class TexCog(commands.Cog): @commands.command(name="tex", aliases=["latex"], category=cmn.Cats.UTILS) async def tex(self, ctx: commands.Context, *, expr: str): - """Renders a LaTeX expression.""" + """Renders a LaTeX expression. + + In paragraph mode by default. To render math, add `$` around math expressions. + """ payload = { "format": "png", "code": self.template.replace("#CONTENT#", expr), @@ -45,7 +48,11 @@ class TexCog(commands.Cog): if render_result["status"] != "success": embed = cmn.embed_factory(ctx) embed.title = "LaTeX Rendering Failed!" - embed.description = render_result.get("description", "Unknown error") + embed.description = ("Here are some common reasons:\n" + "• Did you forget to use math mode? Surround math expressions with `$`," + " like `$x^3$`.\n" + "• Are you using a command from a package? It might not be available.\n" + "• Are you including the document headers? We already did that for you.") embed.colour = cmn.colours.bad await ctx.send(embed=embed) return