Code Monkey home page Code Monkey logo

manim-onlinetex's Introduction

manim-onlinetex

A Manim Plugin that renders LaTeX for Mobjects like Tex and MathTex via online services. This plugin will try to render the LaTeX required by such Mobjects via LaTeXCluster, and if for some reason LaTeXCluster is down, will attempt to use QuickLaTeX.

Usage instructions

Import the contents of manim_onlinetex AFTER manim has been imported, like so:

from manim import *
from manim_onlinetex import *

Then, use a Mobject that requires LaTeX rendering. If the Plugin is doing its job, then the Tex folder of your media directory should have the source .tex file, the final .svg file, and no intermediary files (like .dvi files), since that's all handled by the online service.

Limitations

Please avoid clearing the Tex directory of your media directory. This is so you don't contact the external LaTeX rendering APIs too often and put an unnecessary strain on their servers.

manim-onlinetex's People

Contributors

aathish04 avatar citrusmunch avatar darylgolden avatar jsonvillanueva avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

manim-onlinetex's Issues

Issue with LaTeXCluster

Please correct me if I am wrong, but the LaTeXCluster website does not seem to exist anymore. It was renamed and has this link: https://www.latex4technics.com/. This results in the following errors during rendering:

"SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed:
Hostname mismatch, certificate is not valid for 'www.latexcluster.org'. (_ssl.c:1129)"

and

"URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: Hostname
mismatch, certificate is not valid for 'www.latexcluster.org'. (_ssl.c:1129)>"

It does not switch to QuickLaTeX instead, preventing rendering. Is it possible to fix this somehow? Thank you in advance!

Don't use `urllib`

This could create errors when system SSL certificates or one distributed with Python isn't up to date. For example,

Traceback (most recent call last):
╭──────────────────────────────────────────────────────────────────────────────────────╮
│ File "C:\python38\lib\urllib\request.py", line 1350, in do_open                      │
│    1347                                                                              │
│    1348         try:                                                                 │
│    1349             try:                                                             │
│  ❱ 1350                 h.request(req.get_method(), req.selector, req.data, headers, │
│    1351                           encode_chunked=req.has_header('Transfer-encoding'))│
│    1352             except OSError as err: # timeout error                           │1353                 raise URLError(err)                                          │
│ File "C:\python38\lib\http\client.py", line 1255, in request                         │
│    1252     def request(self, method, url, body=None, headers={}, *,                 │
│    1253                 encode_chunked=False):                                       │
│    1254         """Send a complete request to the server."""                         │
│  ❱ 1255         self._send_request(method, url, body, headers, encode_chunked)       │
│    1256                                                                              │
│    1257     def _send_request(self, method, url, body, headers, encode_chunked):     │
│    1258         # Honor explicitly requested Host: and Accept-Encoding: headers.     │File "C:\python38\lib\http\client.py", line 1301, in _send_request                   │
│    1298             # RFC 2616 Section 3.7.1 says that text default has a            │1299             # default charset of iso-8859-1.                                 │1300             body = _encode(body, 'body')                                     │
│  ❱ 1301         self.endheaders(body, encode_chunked=encode_chunked)                 │
│    1302                                                                              │
│    1303     def getresponse(self):                                                   │
│    1304         """Get the response from the server.                                 │
│ File "C:\python38\lib\http\client.py", line 1250, in endheaders                      │
│    1247             self.__state = _CS_REQ_SENT                                      │
│    1248         else:                                                                │
│    1249             raise CannotSendHeader()                                         │
│  ❱ 1250         self._send_output(message_body, encode_chunked=encode_chunked)       │
│    1251                                                                              │
│    1252     def request(self, method, url, body=None, headers={}, *,                 │
│    1253                 encode_chunked=False):                                       │
│ File "C:\python38\lib\http\client.py", line 1010, in _send_output                    │
│    1007         self._buffer.extend((b"", b""))                                      │
│    1008         msg = b"\r\n".join(self._buffer)                                     │
│    1009         del self._buffer[:]                                                  │
│  ❱ 1010         self.send(msg)                                                       │
│    1011                                                                              │
│    1012         if message_body is not None:                                         │
│    1013                                                                              │
│ File "C:\python38\lib\http\client.py", line 950, in send                             │
│     947                                                                              │
│     948         if self.sock is None:                                                │
│     949             if self.auto_open:                                               │
│  ❱  950                 self.connect()                                               │
│     951             else:                                                            │
│     952                 raise NotConnected()                                         │
│     953                                                                              │
│ File "C:\python38\lib\http\client.py", line 1424, in connect                         │
│    1421             else:                                                            │
│    1422                 server_hostname = self.host                                  │
│    1423                                                                              │
│  ❱ 1424             self.sock = self._context.wrap_socket(self.sock,                 │
│    1425                                                   server_hostname=server_host│
│    1426                                                                              │
│    1427     __all__.append("HTTPSConnection")                                        │
│ File "C:\python38\lib\ssl.py", line 500, in wrap_socket                              │
│     497                     server_hostname=None, session=None):                     │
│     498         # SSLSocket class handles server_hostname encoding before it calls   │
│     499         # ctx._wrap_socket()                                                 │
│  ❱  500         return self.sslsocket_class._create(                                 │
│     501             sock=sock,                                                       │
│     502             server_side=server_side,                                         │
│     503             do_handshake_on_connect=do_handshake_on_connect,                 │
│ File "C:\python38\lib\ssl.py", line 1040, in _create                                 │
│    1037                     if timeout == 0.0:                                       │
│    1038                         # non-blocking                                       │
│    1039                         raise ValueError("do_handshake_on_connect should not │
│  ❱ 1040                     self.do_handshake()                                      │
│    1041             except (OSError, ValueError):                                    │
│    1042                 self.close()                                                 │
│    1043                 raise                                                        │
│ File "C:\python38\lib\ssl.py", line 1309, in do_handshake                            │
│    1306         try:                                                                 │
│    1307             if timeout == 0.0 and block:                                     │
│    1308                 self.settimeout(None)                                        │
│  ❱ 1309             self._sslobj.do_handshake()                                      │
│    1310         finally:                                                             │
│    1311             self.settimeout(timeout)                                         │
│    1312                                                                              │
╰──────────────────────────────────────────────────────────────────────────────────────╯
SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: certificate has expired (_ssl.c:1125)

During handling of the above exception, another exception occurred:


Traceback (most recent call last):
╭──────────────────────────────────────────────────────────────────────────────────────╮
│ File "C:\python38\lib\site-packages\manim\cli\render\commands.py", line 139, in      │
│render                                                                                │
│    136         for SceneClass in scene_classes_from_file(file):                      │
│    137             try:                                                              │
│    138                 scene = SceneClass()                                          │
│  ❱ 139                 scene.render()                                                │
│    140             except Exception:                                                 │
│    141                 error_console.print_exception()                               │
│    142                 sys.exit(1)                                                   │
│ File "C:\python38\lib\site-packages\manim\scene\scene.py", line 219, in render       │
│     216         """                                                                  │
│     217         self.setup()                                                         │
│     218         try:                                                                 │
│  ❱  219             self.construct()                                                 │
│     220         except EndSceneEarlyException:                                       │
│     221             pass                                                             │
│     222         except RerunSceneException as e:                                     │
│ File "C:\manim\Manim_7_July\YouTube_Tutorials\Latex.py", line 16, in construct       │
│    13 class Testing(Scene):                                                          │
│    14     def construct(self):                                                       │
│    15                                                                                │
│  ❱ 16         eq1 = MathTex("a+b=2")                                                 │
│    17         eq2 = MathTex("p1")                                                    │
│    18                                                                                │
│    19         self.play(Write(eq1))                                                  │
│ File "C:\python38\lib\site-packages\manim\mobject\svg\tex_mobject.py", line 282, in  │
│__init__                                                                              │
│    279         self.brace_notation_split_occurred = False                            │
│    280         self.tex_strings = self.break_up_tex_strings(tex_strings)             │
│    281         try:                                                                  │
│  ❱ 282             super().__init__(                                                 │
│    283                 self.arg_separator.join(self.tex_strings),                    │
│    284                 tex_environment=self.tex_environment,                         │
│    285                 tex_template=self.tex_template,                               │
│ File "C:\python38\lib\site-packages\manim\mobject\svg\tex_mobject.py", line 89, in   │
│__init__                                                                              │
│     86                                                                               │
│     87         assert isinstance(tex_string, str)                                    │
│     88         self.tex_string = tex_string                                          │
│  ❱  89         file_name = tex_to_svg_file(                                          │
│     90             self.get_modified_expression(tex_string),                         │
│     91             environment=self.tex_environment,                                 │
│     92             tex_template=self.tex_template,                                   │
│ File "C:\python38\lib\site-packages\manim_onlinetex\manim_onlinetex.py", line 43, in │
│tex_to_svg_file_online                                                                │
│     40     try:                                                                      │
│     41         hostid = (                                                            │
│     42             1                                                                 │
│  ❱  43             if urllib.request.urlopen("https://www.latexcluster.org").getcode(│
│     44             else 0                                                            │
│     45         )                                                                     │
│     46     except urllib.error.HTTPError:                                            │
│ File "C:\python38\lib\urllib\request.py", line 222, in urlopen                       │
│     219         _opener = opener = build_opener()                                    │
│     220     else:                                                                    │
│     221         opener = _opener                                                     │
│  ❱  222     return opener.open(url, data, timeout)                                   │
│     223                                                                              │
│     224 def install_opener(opener):                                                  │
│     225     global _opener                                                           │
│ File "C:\python38\lib\urllib\request.py", line 525, in open                          │
│     522             req = meth(req)                                                  │
│     523                                                                              │
│     524         sys.audit('urllib.Request', req.full_url, req.data, req.headers, req.│
│  ❱  525         response = self._open(req, data)                                     │
│     526                                                                              │
│     527         # post-process response                                              │528         meth_name = protocol+"_response"                                     │
│ File "C:\python38\lib\urllib\request.py", line 542, in _open                         │
│     539             return result                                                    │
│     540                                                                              │
│     541         protocol = req.type                                                  │
│  ❱  542         result = self._call_chain(self.handle_open, protocol, protocol +     │
│     543                                   '_open', req)                              │
│     544         if result:                                                           │
│     545             return result                                                    │
│ File "C:\python38\lib\urllib\request.py", line 502, in _call_chain                   │
│     499         handlers = chain.get(kind, ())                                       │
│     500         for handler in handlers:                                             │
│     501             func = getattr(handler, meth_name)                               │
│  ❱  502             result = func(*args)                                             │
│     503             if result is not None:                                           │
│     504                 return result                                                │
│     505                                                                              │
│ File "C:\python38\lib\urllib\request.py", line 1393, in https_open                   │
│    1390             self._check_hostname = check_hostname                            │
│    1391                                                                              │
│    1392         def https_open(self, req):                                           │
│  ❱ 1393             return self.do_open(http.client.HTTPSConnection, req,            │
│    1394                 context=self._context, check_hostname=self._check_hostname)  │
│    1395                                                                              │
│    1396         https_request = AbstractHTTPHandler.do_request_                      │
│ File "C:\python38\lib\urllib\request.py", line 1353, in do_open                      │
│    1350                 h.request(req.get_method(), req.selector, req.data, headers, │
│    1351                           encode_chunked=req.has_header('Transfer-encoding'))│
│    1352             except OSError as err: # timeout error                           │
│  ❱ 1353                 raise URLError(err)                                          │
│    1354             r = h.getresponse()                                              │
│    1355         except:                                                              │
│    1356             h.close()                                                        │
╰──────────────────────────────────────────────────────────────────────────────────────╯
URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: certificate has expired (_ssl.c:1125)>

Use requests library instead. Just FYI, manim also depends on requests to check for updates.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.