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

Add Quiver Styles #6

Merged
merged 4 commits into from
Oct 25, 2021
Merged
Show file tree
Hide file tree
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: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,20 @@ A \arrow{rd} \arrow{r} & B \\

For more usage details, check out the
[TikzPictures.jl repository](https://github.com/JuliaTeX/TikzPictures.jl).

## Quiver Support

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.
The `QuiverCD` function will append the quiver.sty file to your TikzCD diagram.

```julia
using TikzCDs: Styles
triangle = L""" A &&& Q \\
\\
&&& P
\arrow["h", from=1-4, to=3-4]
\arrow["f", from=1-1, to=1-4]
\arrow["g"', from=1-1, to=3-4]
"""
tridiagram = TikzCD(triangle, preamble=Styles.Quiver)
```
35 changes: 35 additions & 0 deletions src/Styles.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
module Styles

using LaTeXStrings

export Quiver

Quiver = L"""
% contents of quiver.sty
% `tikz-cd` is necessary to draw commutative diagrams.
\RequirePackage{tikz-cd}
% `amssymb` is necessary for `\lrcorner` and `\ulcorner`.
\RequirePackage{amssymb}
% `calc` is necessary to draw curved arrows.
\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}}
"""

end
2 changes: 2 additions & 0 deletions src/TikzCDs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,6 @@ function TikzCD(data::AbstractString; preamble="", kw...)
TikzPicture(data; environment="tikzcd", preamble=preamble, kw...)
end

include("Styles.jl")

end
25 changes: 24 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
# BASED ON TIKZPICTURES.JL TESTS

using TikzCDs
using TikzCDs: Styles
using Test

for file in ["testCD.pdf", "testCDDoc.pdf", "testCD.tex"]
for file in ["testCD.pdf", "testCDDoc.pdf", "testCD.tex", "triangle.pdf", "triangle.svg"]
if isfile(file)
rm(file)
end
Expand Down Expand Up @@ -50,3 +51,25 @@ if success(`lualatex -v`)
else
@warn "lualatex is missing; can not test compilation"
end

# Test q.uiver.app support
function testrender(diagram, name::String)
if success(`lualatex -v`)
save(PDF(name), diagram)
@test isfile("$name.pdf")
save(SVG(name), diagram)
else
@warn "lualatex is missing; can not test compilation"
end
end


triangle = L""" A &&& Q \\
\\
&&& P
\arrow["h", from=1-4, to=3-4]
\arrow["f", from=1-1, to=1-4]
\arrow["g"', from=1-1, to=3-4]
"""
tridiagram = TikzCD(triangle, preamble=Styles.Quiver)
testrender(tridiagram, "triangle")