mirror of
https://git.freetards.xyz/array.in.a.matrix/TexLiLy.git
synced 2025-04-02 13:21:42 -04:00
[FIX] Allow display math mode.
This commit is contained in:
parent
d267bede14
commit
062885ab2b
2 changed files with 9 additions and 5 deletions
5
latex.py
5
latex.py
|
@ -1,7 +1,8 @@
|
|||
# Converts a TeX file into a PNG/SVG file.
|
||||
template = r"""
|
||||
\documentclass[utf8]{{standalone}}
|
||||
\documentclass[utf8,preview]{{standalone}}
|
||||
\usepackage{{amsmath}}
|
||||
\usepackage[active,tightpage]{{preview}}
|
||||
\usepackage[utf8]{{inputenc}}
|
||||
% TODO: Add user packages here.
|
||||
\begin{{document}}
|
||||
|
@ -19,9 +20,9 @@ def render(user: str, source: str, png: bool = True) -> str:
|
|||
fmt = template.format(content=source)
|
||||
|
||||
tmp = tempfile.NamedTemporaryFile(delete=False)
|
||||
print(tmp.name)
|
||||
tmp.write(bytes(fmt, encoding="utf8"))
|
||||
tmp.close()
|
||||
print(tmp.name)
|
||||
# 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", capture_output=True)
|
||||
|
|
9
main.py
9
main.py
|
@ -2,11 +2,11 @@ from nio import *
|
|||
|
||||
import asyncio
|
||||
import yaml
|
||||
import os
|
||||
|
||||
|
||||
async def send_png(room: MatrixRoom, filename: str) -> None:
|
||||
import imagesize
|
||||
import os
|
||||
basename = os.path.basename(filename)
|
||||
w, h = imagesize.get(filename)
|
||||
|
||||
|
@ -38,7 +38,10 @@ async def send_png(room: MatrixRoom, filename: str) -> None:
|
|||
async def msg_cb(room: MatrixRoom, event: RoomMessageText) -> None:
|
||||
import re
|
||||
import latex
|
||||
for tex in re.findall('((?:\$[^\$]+\$)|(?:\$\$[^\$]+\$\$))', event.body, re.M):
|
||||
if event.sender == client.user_id:
|
||||
return
|
||||
|
||||
for tex in re.findall(r'((?:\$[^\$]+\$)|(?:\$\$[^\$]+\$\$)|(?:\\\[[^\]]+\\\]))', event.body, re.M):
|
||||
print("Text:", tex)
|
||||
try:
|
||||
filename = latex.render("", tex)
|
||||
|
@ -92,7 +95,7 @@ async def main() -> None:
|
|||
client.user_id = user
|
||||
|
||||
# Bad kludge!
|
||||
await client.sync(timeout=300000)
|
||||
await client.sync(timeout=3000)
|
||||
|
||||
# Register all of the callbacks
|
||||
client.add_event_callback(msg_cb, RoomMessageText)
|
||||
|
|
Loading…
Add table
Reference in a new issue