mirror of
https://git.freetards.xyz/array.in.a.matrix/TexLiLy.git
synced 2025-04-02 13:21:42 -04:00
[ADD] Allow multiple TeX expressions to be put using regexes.
This commit is contained in:
parent
2041487fa0
commit
d267bede14
1 changed files with 6 additions and 5 deletions
9
main.py
9
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 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.<br><code><pre>{e.args[0]}</pre></code>",
|
||||
}
|
||||
|
||||
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
|
||||
|
|
Loading…
Add table
Reference in a new issue