diff --git a/main.py b/main.py
index 1b042e4..9f9d530 100644
--- a/main.py
+++ b/main.py
@@ -36,11 +36,12 @@ async def send_png(room: MatrixRoom, filename: str) -> None:
# Our message callback. It should be passed through a router.
async def msg_cb(room: MatrixRoom, event: RoomMessageText) -> None:
- if event.body.startswith("$"):
- import latex
-
+ import re
+ import latex
+ for tex in re.findall('((?:\$[^\$]+\$)|(?:\$\$[^\$]+\$\$))', event.body, re.M):
+ print("Text:", tex)
try:
- filename = latex.render("", event.body)
+ filename = latex.render("", tex)
await send_png(room, filename)
except FileNotFoundError as e:
content = {
@@ -48,7 +49,6 @@ async def msg_cb(room: MatrixRoom, event: RoomMessageText) -> None:
"body": f"Couldn't parse LaTeX correctly.\n```{e.args[0]}\n```",
"formatted_body": f"Couldn't parse LaTeX correctly.
{e.args[0]}
",
}
-
await client.room_send(room.room_id, message_type="m.room.message", content=content)
except OSError:
content = {
@@ -58,6 +58,7 @@ 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