From 3a6509f797d75b0927b1d006c7d7751e7053399c Mon Sep 17 00:00:00 2001 From: ElifUskuplu <77177090+ElifUskuplu@users.noreply.github.com> Date: Tue, 28 Jan 2025 10:36:53 -0500 Subject: [PATCH 1/2] Update depgraph.py create a .dot file for the graph independently convert .dot file to a .tex file including the dependency graph tikz-picture --- plastexdepgraph/Packages/depgraph.py | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/plastexdepgraph/Packages/depgraph.py b/plastexdepgraph/Packages/depgraph.py index ac45614..a18fb9b 100644 --- a/plastexdepgraph/Packages/depgraph.py +++ b/plastexdepgraph/Packages/depgraph.py @@ -49,6 +49,7 @@ import string from pathlib import Path from typing import Optional +from dot2tex import dot2tex from jinja2 import Template from pygraphviz import AGraph @@ -268,7 +269,7 @@ def ProcessOptions(options, document): jobname = document.userdata['jobname'] outdir = document.config['files']['directory'] outdir = string.Template(outdir).substitute({'jobname': jobname}) - + def update_proofs() -> None: for proof in document.getElementsByTagName('proof'): proved = proof.userdata.setdefault('proves', find_proved_thm(proof)) @@ -328,6 +329,16 @@ def makegraphs() -> None: graph_tpl = Template(default_tpl_path.read_text()) reduce_graph = not options.get('nonreducedgraph', False) + + def dot_to_tikz(dot_filename): + tikz_filename = dot_filename.replace('.dot', '.tex') + with open(dot_filename, 'r') as dot_file: + dot_content = dot_file.read() + tikz_code = dot2tex(dot_content, format='tikz', crop=True) + with open(tikz_filename, 'w') as tikz_file: + tikz_file.write(tikz_code) + log.info(f"TikZ-picture file saved: {tikz_filename}") + return tikz_filename def make_graph_html(document): files = [] @@ -341,6 +352,11 @@ def make_graph_html(document): dot = graph.to_dot(document.userdata['dep_graph'].get('shapes', {'definition': 'box'})) if reduce_graph: dot = dot.tred() + dot_filename = f"{jobname}_dep_graph.dot" + with open(dot_filename, 'w') as dot_file: + dot_file.write(dot.to_string()) + log.info(f"DOT file saved: {dot_filename}") + tikz_filename = dot_to_tikz(dot_filename) graph_tpl.stream(graph=graph, dot=dot.to_string(), context=document.context, @@ -371,4 +387,3 @@ def make_graph_html(document): document.userdata['dep_graph']['legend'] = [('Boxes', 'definitions'), ('Ellipses', 'theorems and lemmas')] document.userdata['dep_graph']['extra_modal_links'] = [] - From 5a2d854337f3abeaa5389792d500b02918f773fa Mon Sep 17 00:00:00 2001 From: ElifUskuplu <77177090+ElifUskuplu@users.noreply.github.com> Date: Tue, 28 Jan 2025 10:40:13 -0500 Subject: [PATCH 2/2] Update depgraph.py --- plastexdepgraph/Packages/depgraph.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plastexdepgraph/Packages/depgraph.py b/plastexdepgraph/Packages/depgraph.py index a18fb9b..3f65473 100644 --- a/plastexdepgraph/Packages/depgraph.py +++ b/plastexdepgraph/Packages/depgraph.py @@ -269,7 +269,7 @@ def ProcessOptions(options, document): jobname = document.userdata['jobname'] outdir = document.config['files']['directory'] outdir = string.Template(outdir).substitute({'jobname': jobname}) - + def update_proofs() -> None: for proof in document.getElementsByTagName('proof'): proved = proof.userdata.setdefault('proves', find_proved_thm(proof))