Skip to content

Commit b39055e

Browse files
authored
Merge pull request #6 from JuliaTeX/styles
Add Quiver Styles
2 parents dbda1d2 + 36b584e commit b39055e

4 files changed

Lines changed: 78 additions & 1 deletion

File tree

README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,20 @@ A \arrow{rd} \arrow{r} & B \\
2929

3030
For more usage details, check out the
3131
[TikzPictures.jl repository](https://github.com/JuliaTeX/TikzPictures.jl).
32+
33+
## Quiver Support
34+
35+
You can use [Quiver](q.uiver.app) to draw your diagrams and then render them with TikzCD by taking the body of the tikzcd from the exported tex file.
36+
The `QuiverCD` function will append the quiver.sty file to your TikzCD diagram.
37+
38+
```julia
39+
using TikzCDs: Styles
40+
triangle = L""" A &&& Q \\
41+
\\
42+
&&& P
43+
\arrow["h", from=1-4, to=3-4]
44+
\arrow["f", from=1-1, to=1-4]
45+
\arrow["g"', from=1-1, to=3-4]
46+
"""
47+
tridiagram = TikzCD(triangle, preamble=Styles.Quiver)
48+
```

src/Styles.jl

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
module Styles
2+
3+
using LaTeXStrings
4+
5+
export Quiver
6+
7+
Quiver = L"""
8+
% contents of quiver.sty
9+
% `tikz-cd` is necessary to draw commutative diagrams.
10+
\RequirePackage{tikz-cd}
11+
% `amssymb` is necessary for `\lrcorner` and `\ulcorner`.
12+
\RequirePackage{amssymb}
13+
% `calc` is necessary to draw curved arrows.
14+
\usetikzlibrary{calc}
15+
% `pathmorphing` is necessary to draw squiggly arrows.
16+
\usetikzlibrary{decorations.pathmorphing}
17+
18+
% A TikZ style for curved arrows of a fixed height, due to AndréC.
19+
\tikzset{curve/.style={settings={#1},to path={(\tikztostart)
20+
.. controls ($(\tikztostart)!\pv{pos}!(\tikztotarget)!\pv{height}!270:(\tikztotarget)$)
21+
and ($(\tikztostart)!1-\pv{pos}!(\tikztotarget)!\pv{height}!270:(\tikztotarget)$)
22+
.. (\tikztotarget)\tikztonodes}},
23+
settings/.code={\tikzset{quiver/.cd,#1}
24+
\def\pv##1{\pgfkeysvalueof{/tikz/quiver/##1}}},
25+
quiver/.cd,pos/.initial=0.35,height/.initial=0}
26+
27+
% TikZ arrowhead/tail styles.
28+
\tikzset{tail reversed/.code={\pgfsetarrowsstart{tikzcd to}}}
29+
\tikzset{2tail/.code={\pgfsetarrowsstart{Implies[reversed]}}}
30+
\tikzset{2tail reversed/.code={\pgfsetarrowsstart{Implies}}}
31+
% TikZ arrow styles.
32+
\tikzset{no body/.style={/tikz/dash pattern=on 0 off 1mm}}
33+
"""
34+
35+
end

src/TikzCDs.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,6 @@ function TikzCD(data::AbstractString; preamble="", kw...)
2121
TikzPicture(data; environment="tikzcd", preamble=preamble, kw...)
2222
end
2323

24+
include("Styles.jl")
25+
2426
end

test/runtests.jl

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
# BASED ON TIKZPICTURES.JL TESTS
22

33
using TikzCDs
4+
using TikzCDs: Styles
45
using Test
56

6-
for file in ["testCD.pdf", "testCDDoc.pdf", "testCD.tex"]
7+
for file in ["testCD.pdf", "testCDDoc.pdf", "testCD.tex", "triangle.pdf", "triangle.svg"]
78
if isfile(file)
89
rm(file)
910
end
@@ -50,3 +51,25 @@ if success(`lualatex -v`)
5051
else
5152
@warn "lualatex is missing; can not test compilation"
5253
end
54+
55+
# Test q.uiver.app support
56+
function testrender(diagram, name::String)
57+
if success(`lualatex -v`)
58+
save(PDF(name), diagram)
59+
@test isfile("$name.pdf")
60+
save(SVG(name), diagram)
61+
else
62+
@warn "lualatex is missing; can not test compilation"
63+
end
64+
end
65+
66+
67+
triangle = L""" A &&& Q \\
68+
\\
69+
&&& P
70+
\arrow["h", from=1-4, to=3-4]
71+
\arrow["f", from=1-1, to=1-4]
72+
\arrow["g"', from=1-1, to=3-4]
73+
"""
74+
tridiagram = TikzCD(triangle, preamble=Styles.Quiver)
75+
testrender(tridiagram, "triangle")

0 commit comments

Comments
 (0)