Don't leave hanging katexserver.
This commit is contained in:
parent
b4a123e817
commit
e07141fe10
2 changed files with 11 additions and 5 deletions
|
@ -48,14 +48,14 @@ doc = doc.walk(transform, context)
|
|||
# setting out to TeX
|
||||
doc.content = [Group(*doc.content, metadata={"language":language})]
|
||||
|
||||
# Initialize KaTeX client (this runs the node app and connects to a unix socket)
|
||||
katexClient = KatexClient()
|
||||
# Initialize the image processor (this just keeps some basic state)
|
||||
imageProcessor = ImageProcessor(args.img_public_dir, args.img_web_path, *args.img_lookup_dirs)
|
||||
|
||||
# Generate HTML and TeX out of the transformed document
|
||||
open(args.output_html, "w").write(html(doc, katexClient, imageProcessor))
|
||||
open(args.output_tex, "w").write(tex(doc, imageProcessor))
|
||||
# Initialize KaTeX client (this runs the node app and connects to a unix socket)
|
||||
with KatexClient() as katexClient:
|
||||
# Generate HTML and TeX out of the transformed document
|
||||
open(args.output_html, "w").write(html(doc, katexClient, imageProcessor))
|
||||
open(args.output_tex, "w").write(tex(doc, imageProcessor))
|
||||
|
||||
if args.debug:
|
||||
print(show(doc))
|
||||
|
|
6
katex.py
6
katex.py
|
@ -56,3 +56,9 @@ class KatexClient:
|
|||
|
||||
def endgroup(self):
|
||||
self._client.sendall("endgroup\n".encode("utf-8"))
|
||||
|
||||
def __enter__(self):
|
||||
return self
|
||||
|
||||
def __exit__(self, type, value, tb):
|
||||
self._server_process.terminate()
|
||||
|
|
Loading…
Reference in a new issue