diff --git a/latex.py b/latex.py index 6f288a0..8ccf572 100644 --- a/latex.py +++ b/latex.py @@ -1,7 +1,8 @@ # Converts a TeX file into a PNG/SVG file. template = r""" -\documentclass{{standalone}} +\documentclass[utf8]{{standalone}} \usepackage{{amsmath}} + \usepackage[utf8]{{inputenc}} % TODO: Add user packages here. \begin{{document}} % The user content goes here. @@ -24,7 +25,7 @@ def render(user: str, source: str, png: bool = True) -> str: # Parse our templated file thru' LaTeX and dvipng. # TODO: Allow arbitrary DPI and foreground color. ret = subprocess.run(["latex", "-halt-on-error", tmp.name], cwd="/tmp").returncode - if ret is not 0: + if ret != 0: raise FileNotFoundError("DVI couldn't be built.") if png: diff --git a/main.py b/main.py index 2b786a2..c940ab7 100644 --- a/main.py +++ b/main.py @@ -50,6 +50,8 @@ async def msg_cb(room: MatrixRoom, event: RoomMessageText) -> None: await client.room_send(room.room_id, message_type="m.room.message", content=content) # Our file callback. + + async def file_cb(room: MatrixRoom, event: RoomMessageFile) -> None: url = event.url filename = event.body @@ -68,13 +70,14 @@ async def main() -> None: user = str(config["user"]) token = str(config["token"]) # path = str(config["path"]) # not used - # if config file does not exist, quit + # if config file does not exist, quit except FileNotFoundError: - print("No config file found.\nPlease create a file named `texlily.yaml` and read the README file.") - quit() + print("No config file found.") + print("Please create a file named `texlily.yaml` and read the README file.") + quit() except TypeError: - print("Invalid configuration file.") - quit() + print("Invalid configuration file.") + quit() client = AsyncClient(homeserver) client.access_token = token