Debian Codegraph @

texmf-dist/doc/latex/jigsaw/jigsaw-doc.tex

raw
1 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2 %
3 % Documentation for the jigsaw package
4 % A package to draw jigsaw pieces with tikz
5 % Maintained by samcarter
6 %
7 % Project repository and bug tracker:
8 % https://github.com/samcarter/jigsaw
9 %
10 % Released under the LaTeX Project Public License v1.3c or later
11 % See http://www.latex-project.org/lppl.txt
12 %
13 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
14 % !TeX program = txs:///arara
15 % arara: latexmk: {
16 % arara: --> engine: pdflatex,
17 % arara: --> options: [
18 % arara: --> '-shell-escape',
19 % arara: --> '-synctex=1',
20 % arara: --> '-interaction=nonstopmode',
21 % arara: --> ]
22 % arara: --> }
23 \documentclass{scrartcl}
24
25 % meta %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
26 \title{The jigsaw package}
27 \subtitle{Drawing jigsaw pieces in \TikZ}
28 \author{%
29 \texorpdfstring{
30 \begin{tikzpicture}
31 \piece[lightgray!70!white]{1}{-1}{1}{-1}
32 \end{tikzpicture}\\[0.8em]
33 \texttt{samcarter}\\
34 \url{https://github.com/samcarter/jigsaw}\\
35 \url{https://www.ctan.org/pkg/jigsaw}
36 }{samcarter}}
37 \date{Version v0.5 \textendash{} 2024/04/25}
38
39 \usepackage[
40 themecolor=samlgreen
41 ]{\jobname-settings}
42
43 \colorlet{teal}{samlgreen}
44 \colorlet{violet}{samviolet}
45
46 \usepackage{jigsaw}
47 \usetikzlibrary{matrix}
48
49 \begin{document}
50 \maketitle
51
52 \section{Introduction}
53 \label{intro}
54
55 The jigsaw package allows to draw adjustable jigsaw pieces in \TikZ, to combine them and even to automatically create complete jigsaws. It is based on the TeX.Stackexchange answers \url{https://tex.stackexchange.com/a/446296/36296}.
56
57 The package is included in both \texlive and \miktex and available from \CTAN (\url{https://ctan.org/pkg/jigsaw}). The development version of this package is located at \url{github.com/samcarter/jigsaw}. If you have any problems, ideas or other feedback, please make constructive use of its bug tracker.
58
59 Copyright \raisebox{0.2em}{\tiny\fontfamily{cmr}\selectfont\textcopyright} \texttt{samcarter}. Permission is granted to copy, distribute and\slash or modify this software under the terms of the LaTeX project public licence, version 1.3c or later \url{http://www.latex-project.org/lppl.txt}.
60
61 \section{Usage}
62
63 An individual jigsaw piece can be drawn with
64
65 \begin{tcolorbox}[title={Jigsaw piece}]
66 \begin{samcode}
67 \piece{<bottom>}{<right>}{<top>}{<left>}
68 \end{samcode}
69 \tcblower
70 \begin{tikzpicture}
71 \piece{1}{-1}{1}{1}
72 \end{tikzpicture}
73 \end{tcolorbox}
74
75 wherein arguments specify for each side if it should be a tab (-1), a straight line (0) or a slot (1).
76
77 The following example will produce a jigsaw piece with one tab sticking out, one straight boarder and two slots:
78
79 \begin{tcblisting}{title={Jigsaw piece}}
80 \begin{tikzpicture}
81 \piece{1}{-1}{0}{1}
82 \end{tikzpicture}
83 \end{tcblisting}
84
85 With an optional argument, a fill colour can be passed to the piece:
86
87 \begin{tcblisting}{title={Filled piece}}
88 \begin{tikzpicture}
89 \piece[teal]{-1}{1}{-1}{1}
90 \end{tikzpicture}
91 \end{tcblisting}
92
93 Or to change the line colour:
94
95 \begin{tcblisting}{title={Coloured piece}}
96 \begin{tikzpicture}
97 \color{teal}\piece{-1}{-1}{1}{1}
98 \end{tikzpicture}
99 \end{tcblisting}
100
101 The piece shape is also available as \TikZ \saminline|pic|:
102
103 \begin{tcblisting}{title={\texttt{pic}}}
104 \begin{tikzpicture}
105 \path (2,-3) pic[
106 fill=lightgray, draw=teal, thick,
107 scale=2, pic text={Some Text},
108 pic text options={text=violet}
109 ]{piece={1}{-1}{1}{0}};
110 \end{tikzpicture}
111 \end{tcblisting}
112
113 Using the \TikZ \saminline|pic| allows to apply various \TikZ option like \saminline|scale| or add text in the centre of the piece via \saminline|pic text={...}|.
114
115 The shapes of the jigsaw pieces are designed to seamlessly fit into each other which allows to produce tile patters in various ways:
116
117 \begin{tcblisting}{title={Manual tile pattern}}
118 \begin{tikzpicture}
119 \begin{scope}
120 \piece[teal]{1}{1}{0}{0}
121 \end{scope}
122 \begin{scope}[xshift=1cm]
123 \piece[lightgray]{1}{0}{0}{-1}
124 \end{scope}
125 \begin{scope}[yshift=-1cm]
126 \piece[lightgray]{0}{-1}{-1}{0}
127 \end{scope}
128 \begin{scope}[xshift=1cm,yshift=-1cm]
129 \piece[teal]{0}{0}{-1}{1}
130 \end{scope}
131 \end{tikzpicture}
132 \end{tcblisting}
133
134 \begin{tcblisting}{title={Manual pattern using \texttt{\textbackslash pic}}}
135 \begin{tikzpicture}
136 \pic at (0,1) [fill=lightgray,draw]
137 {piece={1}{1}{0}{0}};
138 \pic at (1,1) [fill=teal,draw]
139 {piece={1}{0}{0}{-1}};
140 \pic at (0,0) [fill=teal,draw]
141 {piece={0}{-1}{-1}{0}};
142 \pic at (1,0) [fill=lightgray,draw]
143 {piece={0}{0}{-1}{1}};
144 \end{tikzpicture}
145 \end{tcblisting}
146
147 \begin{tcblisting}{title={Manual pattern using Ti\emph{k}Z matrix}}
148 % \usetikzlibrary{matrix}
149 \begin{tikzpicture}
150 \matrix [nodes=draw]{
151 \pic [fill=lightgray]
152 {piece={-1}{1}{0}{0}}; &
153 \pic [fill=teal]
154 {piece={1}{0}{0}{-1}}; \\
155 \pic [fill=teal]
156 {piece={0}{-1}{1}{0}}; &
157 \pic [fill=lightgray]
158 {piece={0}{0}{-1}{1}};\\
159 };
160 \end{tikzpicture}
161 \end{tcblisting}
162
163 Manually position each jigsaw piece at the correct position can be tedious, therefore the command \saminline|\tile[<colour>]{<bottom>}{<right>}{<top>}{<left>}| was added. It can be used outside of of the \saminline|tikzpicture| environment to place the pieces besides each other like normal letters in a text. Line breaks have to be added at the appropriate positions and one has to be careful not to introduce additional spaces between the jigsaw pieces from unprotected line endings.
164
165 \begin{tcblisting}{title={The tile command}}
166 \tile[violet]{1}{1}{0}{0}%
167 \tile[lightgray]{1}{-1}{0}{-1}%
168 \tile[teal]{1}{0}{0}{1}
169
170 \tile[teal]{1}{-1}{-1}{0}%
171 \tile[violet]{1}{-1}{-1}{1}%
172 \tile[lightgray]{-1}{0}{-1}{1}
173
174 \tile[lightgray]{0}{-1}{-1}{0}%
175 \tile[teal]{0}{-1}{-1}{1}%
176 \tile[violet]{0}{0}{1}{1}
177 \end{tcblisting}
178
179 Finally there is also the possibility to automatically generate complete jigsaw puzzles using the command \saminline|\jigsaw{<x>}{<y>}|, with \saminline|<x>| and \saminline|<y>| the number of rows and columns, respectively.
180
181 \begin{tcblisting}{title={Automatic jigsaw generation},righthand width=6.1cm}
182 \begin{tikzpicture}
183 \jigsaw{6}{4}
184 \end{tikzpicture}
185 \end{tcblisting}
186
187 This automatically generated jigsaw can also be overlaid on a picture:
188
189 \begin{tcblisting}{title={Overlaid image},righthand width=6.1cm}
190 \begin{tikzpicture}
191 \clip (0,0) rectangle (6,4);
192 \node at (3,2) {%
193 \includegraphics[
194 width=6cm,height=4cm
195 ]{example-image-duck}%
196 };
197 \jigsaw{6}{4}
198 \end{tikzpicture}
199 \end{tcblisting}
200
201 \end{document}