Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convenience methods for using dot2tex to make latex figures #1282

Open
mpharrigan opened this issue Aug 13, 2024 · 3 comments
Open

Convenience methods for using dot2tex to make latex figures #1282

mpharrigan opened this issue Aug 13, 2024 · 3 comments
Labels
Milestone

Comments

@mpharrigan
Copy link
Collaborator

We use graphviz. There exists a package dot2tex that can generate latex code and/or pdf figures from graphviz. This has the benefit of supporting latex math. Here's a little code snippet. I had to hack into the call graph drawer code to use sympy.printing.latex so the dot file contains raw latex-math

def to_latex_pdf(g, fn_prefix):
    dot = GraphvizCallGraph(g, edgelabel_fmt='latex').get_graph()
    with open(f'{fn_prefix}.dot', 'w') as f:
        f.write(dot.to_string())

    subprocess.check_call(['dot', '-Txdot', f'-o{fn_prefix}.xdot', f'{fn_prefix}.dot'])
    subprocess.check_call(['dot2tex', '-traw', f'{fn_prefix}.xdot', '-o', f'{fn_prefix}.tex'])
    subprocess.check_call(['pdflatex', f'{fn_prefix}.tex'])
    subprocess.check_call(['pdfcrop', f'{fn_prefix}.pdf', f'{fn_prefix}.pdf'])
@mpharrigan mpharrigan added this to the After v1.0 milestone Aug 13, 2024
@tanujkhattar
Copy link
Collaborator

The motivation is to draw latex figures for the call graph; correct?

@mpharrigan
Copy link
Collaborator Author

yes. conceivably this could be used for the decomposition-graph as well

@mpharrigan
Copy link
Collaborator Author

Sadly, dot2tex says it's unmaintained and does not support the tables-within-nodes we use for the costing graphs. You can use the existing code to write an SVG file but it won't render latex math

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants