Last active
January 22, 2025 09:39
-
-
Save ddkasa/c28e4fb6acc48aad14e3bcf5b86bce52 to your computer and use it in GitHub Desktop.
Textual Latex Parsing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from __future__ import annotations | |
import sys | |
from pylatexenc.latex2text import LatexNodes2Text | |
from textual import on | |
from textual.app import App, ComposeResult | |
from textual.widgets import Static, TextArea | |
class LatexApp(App[None]): | |
CSS = """ | |
Screen { | |
layout: horizontal; | |
Static { | |
width: 66%; | |
padding: 2 5; | |
} | |
} | |
""" | |
def compose(self) -> ComposeResult: | |
yield TextArea(theme="css") | |
yield Static(id="content") | |
@on(TextArea.Changed) | |
def _parse_latex(self, message: TextArea.Changed) -> None: | |
latex = LatexNodes2Text().latex_to_text(message.text_area.text) | |
self.query_one(Static).update(latex) | |
def main() -> None: | |
sys.exit(LatexApp().run()) | |
if __name__ == "__main__": | |
main() |
Comments are disabled for this gist.