aboutsummaryrefslogtreecommitdiffstats
path: root/bot/exts/fun/latex/_renderer.py
diff options
context:
space:
mode:
authorGravatar Shakya Majumdar <[email protected]>2022-01-18 19:30:16 +0530
committerGravatar Shakya Majumdar <[email protected]>2022-01-18 19:30:16 +0530
commita10c07a85a2387a26103aafcabb7bd3e789624c3 (patch)
tree66615e1e651bcc7fb9ddabbca6d6d67a5bb69884 /bot/exts/fun/latex/_renderer.py
parentfix path to cache in gitignore (diff)
rewrite, use the rtex api instead of mpl
Diffstat (limited to 'bot/exts/fun/latex/_renderer.py')
-rw-r--r--bot/exts/fun/latex/_renderer.py47
1 files changed, 0 insertions, 47 deletions
diff --git a/bot/exts/fun/latex/_renderer.py b/bot/exts/fun/latex/_renderer.py
deleted file mode 100644
index fb72b94c..00000000
--- a/bot/exts/fun/latex/_renderer.py
+++ /dev/null
@@ -1,47 +0,0 @@
-import sys
-from pathlib import Path
-from typing import BinaryIO
-
-import matplotlib.pyplot as plt
-
-# configure fonts and colors for matplotlib
-plt.rcParams.update(
- {
- "font.size": 16,
- "mathtext.fontset": "cm", # Computer Modern font set
- "mathtext.rm": "serif",
- "figure.facecolor": "36393F", # matches Discord's dark mode background color
- "text.color": "white",
- }
-)
-
-
-def render(text: str, file_handle: BinaryIO) -> None:
- """
- Saves rendered image in `file_handle`.
-
- In case the input is invalid latex, it prints the error to `stderr`.
- """
- fig = plt.figure()
- fig.text(0, 1, text, horizontalalignment="left", verticalalignment="top")
- try:
- plt.savefig(file_handle, bbox_inches="tight", dpi=600)
- except ValueError as err:
- # get rid of traceback, keeping just the latex error
- sys.exit(err)
-
-
-def main() -> None:
- """
- Renders a latex query and saves the output in a specified file.
-
- Expects two command line arguments: the query and the path to the output file.
- """
- query = sys.argv[1]
- out_file_path = Path(sys.argv[2])
- with open(out_file_path, "wb") as out_file:
- render(query, out_file)
-
-
-if __name__ == "__main__":
- main()