forked from AlgebraicJulia/ACT2023Tutorials
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfilters.lua
202 lines (182 loc) · 7.27 KB
/
filters.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
local system = require "pandoc.system"
local tikz_doc_templates = {
tikzcd = {
[[
\documentclass[tikz]{standalone}
\usepackage{amsmath,amssymb}
\usetikzlibrary{decorations.markings}
\tikzset{mid vert/.style={/utils/exec=\tikzset{every node/.append style={outer sep=0.8ex}},
postaction=decorate,decoration={markings,
mark=at position 0.5 with {\draw[-] (0,#1) -- (0,-#1);}}},
mid vert/.default=0.75ex}
\usetikzlibrary{cd}
\usetikzlibrary{calc}
% `pathmorphing` is necessary to draw squiggly arrows.
\usetikzlibrary{decorations.pathmorphing}
% A TikZ style for curved arrows of a fixed height, due to AndréC.
\tikzset{curve/.style={settings={#1},to path={(\tikztostart)
.. controls ($(\tikztostart)!\pv{pos}!(\tikztotarget)!\pv{height}!270:(\tikztotarget)$)
and ($(\tikztostart)!1-\pv{pos}!(\tikztotarget)!\pv{height}!270:(\tikztotarget)$)
.. (\tikztotarget)\tikztonodes}},
settings/.code={\tikzset{quiver/.cd,#1}
\def\pv##1{\pgfkeysvalueof{/tikz/quiver/##1}}},
quiver/.cd,pos/.initial=0.35,height/.initial=0}
% TikZ arrowhead/tail styles.
\tikzset{tail reversed/.code={\pgfsetarrowsstart{tikzcd to}}}
\tikzset{2tail/.code={\pgfsetarrowsstart{Implies[reversed]}}}
\tikzset{2tail reversed/.code={\pgfsetarrowsstart{Implies}}}
% TikZ arrow styles.
\tikzset{no body/.style={/tikz/dash pattern=on 0 off 1mm}}
\begin{document}
\begin{tikzpicture}
\node[scale=2] (OWEKW6Ur) {
\begin{tikzcd}
]],
[[
\end{tikzcd}
};
\end{tikzpicture}
\end{document}
]],
},
tikz = {
[[
\documentclass[tikz]{standalone}
\usetikzlibrary{graphs, graphdrawing}
\usegdlibrary{trees}
\begin{document}
\begin{tikzpicture}
\node[scale=2] (OWEKW6Ur) {
]],
[[
};
\end{tikzpicture}
\end{document}
]],
},
tikzit = {
[[
\documentclass[tikz]{standalone}
\usepackage{amsmath}
% Official TikZiT style file: https://tikzit.github.io/tikzit.sty
\usetikzlibrary{backgrounds}
\usetikzlibrary{arrows}
\usetikzlibrary{shapes,shapes.geometric,shapes.misc}
% this style is applied by default to any tikzpicture included via \tikzfig
\tikzstyle{tikzfig}=[baseline=-0.25em,scale=0.5]
% these are dummy properties used by TikZiT, but ignored by LaTex
\pgfkeys{/tikz/tikzit fill/.initial=0}
\pgfkeys{/tikz/tikzit draw/.initial=0}
\pgfkeys{/tikz/tikzit shape/.initial=0}
\pgfkeys{/tikz/tikzit category/.initial=0}
% standard layers used in .tikz files
\pgfdeclarelayer{edgelayer}
\pgfdeclarelayer{nodelayer}
\pgfsetlayers{background,edgelayer,nodelayer,main}
% style for blank nodes
\tikzstyle{none}=[inner sep=0mm]
% include a .tikz file
\newcommand{\tikzfig}[1]{%
{\tikzstyle{every picture}=[tikzfig]
\IfFileExists{#1.tikz}
{\input{#1.tikz}}
{%
\IfFileExists{./figures/#1.tikz}
{\input{./figures/#1.tikz}}
{\tikz[baseline=-0.5em]{\node[draw=red,font=\color{red},fill=red!10!white] {\textit{#1}};}}%
}}%
}
% the same as \tikzfig, but in a {center} environment
\newcommand{\ctikzfig}[1]{%
\begin{center}\rm
\tikzfig{#1}
\end{center}}
% fix strange self-loops, which are PGF/TikZ default
\tikzstyle{every loop}=[]
% TiKZ style file generated by TikZiT. You may edit this file manually,
% but some things (e.g. comments) may be overwritten. To be readable in
% TikZiT, the only non-comment lines must be of the form:
% \tikzstyle{NAME}=[PROPERTY LIST]
% Node styles
\tikzstyle{variable_node}=[fill={rgb,255: red,108; green,154; blue,195}, draw=black, shape=circle, text=white]
\tikzstyle{block}=[fill={rgb,255: red,226; green,143; blue,65}, draw=black, shape=rectangle, text=white]
\tikzstyle{Ob}=[fill=none, draw=none, shape=rectangle]
\tikzstyle{table}=[fill={rgb,255: red,224; green,229; blue,205}, draw={rgb,255: red,95; green,96; blue,98}, shape=rectangle, rounded corners]
\tikzstyle{title}=[fill=white, draw={rgb,255: red,128; green,190; blue,99}, shape=rectangle, text=black, line width=1mm, minimum width=8cm, minimum height=1cm]
\tikzstyle{blockprime}=[fill={rgb,255: red,108; green,154; blue,195}, draw=black, shape=rectangle, text=white]
\tikzstyle{Hom3by3}=[fill=white, draw=black, shape=rectangle, minimum height=20mm]
\tikzstyle{finsetdot}=[fill=black, draw=black, shape=circle]
\tikzstyle{Hom1x3}=[fill=white, draw=black, shape=rectangle]
\tikzstyle{new edge style 1}=[line width=0.6mm]
\tikzstyle{Hom1x3_rounded}=[fill=white, draw=black, shape=rectangle, rounded corners]
\tikzstyle{outerbox6x17}=[fill=none, draw=black, shape=rectangle, minimum height=6cm, minimum width=17cm, rounded corners]
\tikzstyle{outerbox}=[fill=none, draw=black, shape=rectangle, rounded corners, minimum height=4cm, minimum width=6cm]
\tikzstyle{add}=[fill=white, draw=black, shape=circle]
\tikzstyle{rel_dagger}=[fill=white, draw=black, shape=trapezium, rounded corners, shape border rotate=90, minimum width=1.5cm]
\tikzstyle{rel}=[fill=white, draw=black, shape=trapezium, rounded corners, shape border rotate=270, minimum width=1.5cm]
\tikzstyle{mhom3x1}=[fill=white, draw=black, shape=rectangle, rounded corners, minimum height=10mm]
% Edge styles
\tikzstyle{new edge style 0}=[->, draw={rgb,255: red,127; green,129; blue,131}, line width=0.6mm]
\tikzstyle{arrow}=[draw={rgb,255: red,177; green,179; blue,182}, ->, line width=0.4mm]
\tikzstyle{undirected}=[-, draw={rgb,255: red,177; green,179; blue,182}, line width=0.6mm]
\tikzstyle{cospan_edge}=[->, draw=black, dashed, line width=0.4mm]
\tikzstyle{undirected edge}=[-, line width=0.6mm, draw={rgb,255: red,177; green,179; blue,182}]
\tikzstyle{blueline}=[-, draw={rgb,255: red,108; green,154; blue,195}, line width=0.7mm]
\tikzstyle{functor}=[->, draw=black, line width=1.2mm]
\begin{document}
\begin{tikzpicture}
]],
[[
\end{tikzpicture}
\end{document}
]],
},
}
function trim(s) return (s:gsub("^%s*(.-)%s*$", "%1")) end
local function tikz2image(src, template, outfile)
system.with_temporary_directory("tikz2image", function(tmpdir)
system.with_working_directory(tmpdir, function()
local f = io.open("tikz.tex", "w")
f:write(template[1] .. trim(src) .. template[2])
f:close()
os.execute "lualatex tikz.tex"
os.execute "pdf2svg tikz.pdf tikz.svg"
os.execute("mv tikz.svg " .. outfile)
end)
end)
end
local function graphviz2image(src, outfile)
system.with_temporary_directory("graphviz2image", function(tmpdir)
system.with_working_directory(tmpdir, function()
local f = io.open("graphviz.dot", "w")
f:write(trim(src))
f:close()
os.execute "dot -Tsvg graphviz.dot -o graphviz.svg"
os.execute("mv graphviz.svg " .. outfile)
end)
end)
end
local function file_exists(name)
local f = io.open(name, "r")
if f ~= nil then
io.close(f)
return true
else
return false
end
end
function CodeBlock(el)
if el.classes[1] == "graphviz" then
local fbasename = "graphviz_build_" .. pandoc.sha1(el.text) .. ".svg"
local fname = system.get_working_directory() .. "/" .. fbasename
if not file_exists(fname) then graphviz2image(el.text, fname) end
return pandoc.Div(pandoc.Image({}, fbasename), { class = "graphvizz" })
elseif tikz_doc_templates[el.classes[1]] ~= nil then
local fbasename = "tikz_build_" .. pandoc.sha1(el.text) .. ".svg"
local fname = system.get_working_directory() .. "/" .. fbasename
if not file_exists(fname) then tikz2image(el.text, tikz_doc_templates[el.classes[1]], fname) end
return pandoc.Div(pandoc.Image({}, fbasename), { class = "tikzcd" })
else
return el
end
end