2018-01-18 08:09:39 +00:00
|
|
|
from telegram.ext import RegexHandler
|
|
|
|
from .rendering import get_png
|
|
|
|
from .static import static_content
|
|
|
|
|
2018-01-18 09:47:45 +00:00
|
|
|
import logging
|
|
|
|
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
2018-01-18 08:09:39 +00:00
|
|
|
def handle_exception_in_get_png(bot, update, exception, text):
|
|
|
|
update.message.reply_text("**Error** while processing '__{}__'.\n\nException was: **{}**.".format(text, exception), parse_mode = "Markdown")
|
|
|
|
|
|
|
|
def render_math(bot, update):
|
|
|
|
text = update.message.text[len("/rmath"):]
|
2018-01-18 09:47:45 +00:00
|
|
|
tex = text
|
2018-01-18 08:09:39 +00:00
|
|
|
|
|
|
|
try:
|
|
|
|
png = get_png(tex)
|
|
|
|
except Exception as e:
|
|
|
|
handle_exception_in_get_png(bot, update, e, tex)
|
|
|
|
return
|
|
|
|
|
|
|
|
update.message.reply_photo(png, caption = "{}".format(text))
|
|
|
|
|
|
|
|
def render_math_caption(bot, update):
|
|
|
|
text = update.message.text[len("/rmath"):]
|
|
|
|
|
|
|
|
if( not ("<" in text and ">" in text)):
|
|
|
|
update.message.reply_text("**Error**: missing caption seperators: < and >", parse_mode = "Markdown")
|
|
|
|
return
|
|
|
|
|
|
|
|
caption = text[text.index("<") + 1:text.index(">")]
|
|
|
|
text = text[text.index(">") + 1:]
|
|
|
|
|
2018-01-18 09:47:45 +00:00
|
|
|
tex = text
|
2018-01-18 08:09:39 +00:00
|
|
|
|
|
|
|
try:
|
|
|
|
png = get_png(tex)
|
|
|
|
except Exception as e:
|
|
|
|
handle_exception_in_get_png(bot, update, e, tex)
|
|
|
|
return
|
|
|
|
|
|
|
|
update.message.reply_photo(png, caption = "{}\n\nLaTeX: {}".format(caption, text))
|
|
|
|
|
|
|
|
def help(bot, update):
|
|
|
|
update.message.reply_text(static_content.help_text, parse_mode = "Markdown")
|
|
|
|
|