|
|
@ -28,22 +28,16 @@ class KatexClient: |
|
|
|
raise Exception("npm not found. Node.js is required to use KaTeX.") |
|
|
|
else: |
|
|
|
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) |
|
|
|
|
|
|
|
# Wait for the node program to create the socket file |
|
|
|
while not os.path.exists(self._socket_file): |
|
|
|
time.sleep(0.01) |
|
|
|
ok = self._server_process.stdout.readline() |
|
|
|
if ok != b"OK\n": |
|
|
|
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) |
|
|
|
time.sleep(0.01) |
|
|
|
except ConnectionRefusedError: |
|
|
|
continue |
|
|
|
break |
|
|
|
|
|
|
|
def render(self, tex: str, options: Dict={}): |
|
|
|
# Send formulas to translate |
|
|
|