|
@ -28,22 +28,16 @@ class KatexClient: |
|
|
raise Exception("npm not found. Node.js is required to use KaTeX.") |
|
|
raise Exception("npm not found. Node.js is required to use KaTeX.") |
|
|
else: |
|
|
else: |
|
|
raise e |
|
|
raise e |
|
|
self._server_process = subprocess.Popen(["node", srcdir + "/katex-server/index.mjs", self._socket_file]) |
|
|
|
|
|
|
|
|
self._server_process = subprocess.Popen(["node", srcdir + "/katex-server/index.mjs", self._socket_file], stdout=subprocess.PIPE) |
|
|
|
|
|
|
|
|
self._client = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) |
|
|
self._client = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) |
|
|
|
|
|
|
|
|
# Wait for the node program to create the socket file |
|
|
ok = self._server_process.stdout.readline() |
|
|
while not os.path.exists(self._socket_file): |
|
|
if ok != b"OK\n": |
|
|
time.sleep(0.01) |
|
|
raise Exception("Failed to connect to katex-server") |
|
|
|
|
|
|
|
|
# Wait for the node program to start accepting connections |
|
|
|
|
|
while True: |
|
|
|
|
|
try: |
|
|
|
|
|
self._client.connect(self._socket_file) |
|
|
self._client.connect(self._socket_file) |
|
|
time.sleep(0.01) |
|
|
|
|
|
except ConnectionRefusedError: |
|
|
|
|
|
continue |
|
|
|
|
|
break |
|
|
|
|
|
|
|
|
|
|
|
def render(self, tex: str, options: Dict={}): |
|
|
def render(self, tex: str, options: Dict={}): |
|
|
# Send formulas to translate |
|
|
# Send formulas to translate |
|
|