Skip to content

Commit 8dbe7f9

Browse files
committed
convert_markdown_to_pdf
1 parent 3b9c67f commit 8dbe7f9

File tree

3 files changed

+22
-3
lines changed

3 files changed

+22
-3
lines changed

src/math_spec_mapping/Reports/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from .boundary_actions import write_out_boundary_actions
33
from .policies import write_out_policies
44
from .mechanisms import write_out_mechanisms
5-
from .general import load_svg_graphviz
5+
from .general import load_svg_graphviz, convert_markdown_to_pdf
66
from .html import (
77
write_basic_report_full,
88
write_action_chain_reports,

src/math_spec_mapping/Reports/general.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from graphviz import Digraph
22
import os
3+
import pypandoc
34

45

56
def load_svg_graphviz(graph: Digraph, overwrite: bool = False) -> str:
@@ -23,7 +24,7 @@ def load_svg_graphviz(graph: Digraph, overwrite: bool = False) -> str:
2324
assert "{}.gv".format(graph.name) not in os.listdir(".")
2425

2526
# Render the graph
26-
graph.render(directory=".", format='svg')
27+
graph.render(directory=".", format="svg")
2728

2829
# Read the svg
2930
with open("./{}.gv.svg".format(graph.name), "r") as f:
@@ -35,6 +36,7 @@ def load_svg_graphviz(graph: Digraph, overwrite: bool = False) -> str:
3536

3637
return svg
3738

39+
3840
def write_header() -> str:
3941
out = '<p>For explanations of generalized dynamical systems as well as how the mathematical specification library works in detail, please consult the documentation <a href="https://github.com/BlockScience/MSML/tree/main/docs">here</a></p>'
4042
out += "Graph Legend:<br/>"
@@ -43,4 +45,20 @@ def write_header() -> str:
4345
out += "Red Square: Policy<br/>"
4446
out += "Blue Circle: Mechanism<br/>"
4547
out += "Transparent Circle: State Variable"
46-
return out
48+
return out
49+
50+
51+
def convert_markdown_to_pdf(md_path, pdf_path, pdflatex_path=None):
52+
if pdflatex_path:
53+
pypandoc.convert_file(
54+
md_path,
55+
"pdf",
56+
outputfile=pdf_path,
57+
extra_args=["--pdf-engine={}".format(pdflatex_path)],
58+
)
59+
else:
60+
pypandoc.convert_file(
61+
md_path,
62+
"pdf",
63+
outputfile=pdf_path,
64+
)

src/math_spec_mapping/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
write_initial_state_variables_tables,
3030
write_parameter_table_markdown,
3131
write_glossary_report,
32+
convert_markdown_to_pdf,
3233
)
3334
from .schema import schema
3435
from .Convenience import (

0 commit comments

Comments
 (0)