Browse Source

Moved Quiver to a separate style

Signed-off-by: Micah Halter <micah@balena.io>
pull/6/head
Micah Halter 1 month ago
parent
commit
36b584e3fa
Signed by: mehalter GPG Key ID: 91C3B7AA970B3213
  1. 5
      README.md
  2. 35
      src/Styles.jl
  3. 37
      src/TikzCDs.jl
  4. 5
      test/runtests.jl

5
README.md

@ -36,6 +36,7 @@ You can use [Quiver](q.uiver.app) to draw your diagrams and then render them wit
The `QuiverCD` function will append the quiver.sty file to your TikzCD diagram.
```julia
using TikzCDs: Styles
triangle = L""" A &&& Q \\
\\
&&& P
@ -43,5 +44,5 @@ triangle = L""" A &&& Q \\
\arrow["f", from=1-1, to=1-4]
\arrow["g"', from=1-1, to=3-4]
"""
tridiagram = QuiverCD(triangle)
```
tridiagram = TikzCD(triangle, preamble=Styles.Quiver)
```

35
src/Styles.jl

@ -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

37
src/TikzCDs.jl

@ -7,7 +7,7 @@ export PDF, TEX, TIKZ, SVG, save, TikzDocument, push!, tikzCommand
import LaTeXStrings: LaTeXString, @L_str, @L_mstr
export LaTeXString, @L_str, @L_mstr
export TikzCD, QuiverCD
export TikzCD
function TikzCD(data::AbstractString; preamble="", kw...)
# check for tikz-cd package being imported
@ -21,39 +21,6 @@ function TikzCD(data::AbstractString; preamble="", kw...)
TikzPicture(data; environment="tikzcd", preamble=preamble, kw...)
end
Quiversty = 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}
include("Styles.jl")
% 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}}
"""
function QuiverCD(data::AbstractString; preamble=Quiversty, kw...)
if !occursin("contents of quiver.sty", preamble)
preamble = strip(string(Quiversty, "\n", preamble))
end
TikzCD(data; preamble=preamble, kw...)
end
end

5
test/runtests.jl

@ -1,6 +1,7 @@
# BASED ON TIKZPICTURES.JL TESTS
using TikzCDs
using TikzCDs: Styles
using Test
for file in ["testCD.pdf", "testCDDoc.pdf", "testCD.tex", "triangle.pdf", "triangle.svg"]
@ -70,5 +71,5 @@ triangle = L""" A &&& Q \\
\arrow["f", from=1-1, to=1-4]
\arrow["g"', from=1-1, to=3-4]
"""
tridiagram = QuiverCD(triangle)
testrender(tridiagram, "triangle")
tridiagram = TikzCD(triangle, preamble=Styles.Quiver)
testrender(tridiagram, "triangle")

Loading…
Cancel
Save