Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion plastexdepgraph/Packages/depgraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 = []
Expand All @@ -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,
Expand Down Expand Up @@ -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'] = []