Debian Codegraph @

texmf-dist/tex/latex/tikz-page/tikz-page.sty

raw
1 %%
2 %% This is file `tikz-page.sty',
3 %% generated with the docstrip utility.
4 %%
5 %% The original source files were:
6 %%
7 %% tikz-page.dtx (with options: `tikz-page')
8 %% This is a generated file.
9 %%
10 %% Copyright © 2016 by Sébastien Gross <seb•ɑƬ•chezwam•ɖɵʈ•org>
11 %%
12 %% This program is free software. It comes without any warranty, to the extent
13 %% permitted by applicable law. You can redistribute it and/or modify it under
14 %% the terms of the Do What The Fuck You Want To Public License, Version 2, as
15 %% published by Sam Hocevar. See http://sam.zoy.org/wtfpl/COPYING for more
16 %% details.
17 %%
18 %% This file may be distributed and/or modified under the conditions of
19 %% the LaTeX Project Public License, either version 1.3c of this license
20 %% or (at your option) any later version. The latest version of this
21 %% license is in:
22 %%
23 %% http://www.latex-project.org/lppl.txt
24 %%
25 %% and version 1.3c or later is part of all distributions of LaTeX
26 %% version 2006/05/20 or later.
27 %%
28
29
30 %% DeclareTCBListing{macrocode} leave a blank line after code.
31
32
33
34
35 \def\pkgfileversion{1.0}
36 \def\pkgfiledate{2016/08/22}
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51 %% Reset the FancyVerbLine counter to have the correct lines number in front
52 %% of implementation.
53
54
55 \NeedsTeXFormat{LaTeX2e}
56 \ProvidesPackage{tikz-page}[\pkgfiledate\space (v\pkgfileversion)]
57
58
59 \newif\if@tp@use@textpos\@tp@use@textposfalse
60 \DeclareOption{textpos}{\@tp@use@textpostrue}
61 \ProcessOptions
62
63 \if@tp@use@textpos
64 \RequirePackage[absolute]{textpos}
65 \fi
66
67 \RequirePackage{fancyhdr}
68 \RequirePackage{tikz}
69 \usetikzlibrary{plotmarks,calc,shapes,positioning,decorations.text}
70 \RequirePackage{graphicx}
71 \RequirePackage{calc}
72
73 \makeatletter
74
75
76 \newlength{\@tp@left@margin}
77 \newlength{\@tp@right@margin}
78 \newlength{\@tp@top@margin}
79 \newlength{\@tp@bottom@margin}
80
81
82
83 \newcommand\@tp@create@length[2]{%
84 \expandafter\newskip\csname tp@#1@#2\endcsname%
85 }%
86
87
88 \foreach\@@tp@element in {page,body,marginpar,header,footer,top,right,bottom,left}{%
89 \foreach\@@tp@len in {xmin,xmax,xmid,ymin,ymax,ymid}{%
90 \@tp@create@length{\@@tp@element}{\@@tp@len}%
91 }}%
92
93 \newcommand{\tpflip}[2]{\ifodd\thepage#1\else#2\fi}
94
95
96 \def\tp@compute@margins{%
97 \setlength{\tp@page@xmin}{0pt}%
98 \setlength{\tp@page@ymin}{0pt}%
99 \setlength{\tp@page@xmax}{\paperwidth}%
100 \setlength{\tp@page@ymax}{\paperheight}%
101 \setlength{\tp@page@xmid}{\dimexpr(\tp@page@xmin+\tp@page@xmax)/2\relax}%
102 \setlength{\tp@page@ymid}{\dimexpr(\tp@page@ymin+\tp@page@ymax)/2\relax}%
103 %
104 \setlength\@tp@left@margin{\dimexpr(1in+\hoffset+\tpflip{\oddsidemargin}{\evensidemargin})\relax}%
105 \setlength\@tp@right@margin{\dimexpr(\paperwidth-\@tp@left@margin-\textwidth)\relax}%
106 \setlength\@tp@top@margin{\dimexpr(1in+\voffset+\topmargin+\headheight+\headsep)\relax}%
107 \setlength\@tp@bottom@margin{\dimexpr(\paperheight-(\textheight+\@tp@top@margin))\relax}%
108 %% Body computation
109 \setlength\tp@body@xmin{\dimexpr\tp@page@xmin+\@tp@left@margin\relax}%
110 \setlength\tp@body@xmax{\dimexpr\tp@page@xmax-\@tp@right@margin\relax}%
111 \setlength\tp@body@xmid{\dimexpr((\tp@body@xmax+\tp@body@xmin)/2)\relax}%
112 \setlength\tp@body@ymax{\dimexpr(\tp@page@ymax-\@tp@top@margin)\relax}%
113 \setlength\tp@body@ymin{\dimexpr\tp@body@ymin+\@tp@bottom@margin\relax}%
114 \setlength\tp@body@ymid{\dimexpr(\tp@body@ymin+(\tp@body@ymax-\tp@body@ymin)/2)\relax}%
115 %
116 %% Margin computation
117 %
118 \tpflip{%
119 \setlength\tp@marginpar@xmin{\dimexpr\tp@body@xmax+\marginparsep\relax}
120 \setlength\tp@marginpar@xmax{\dimexpr\tp@marginpar@xmin+\marginparwidth\relax}%
121 }{%
122 \setlength\tp@marginpar@xmax{\dimexpr\tp@body@xmin-\marginparsep\relax}%
123 \setlength\tp@marginpar@xmin{\dimexpr\tp@marginpar@xmax-\marginparwidth\relax}%
124 }%
125 \setlength\tp@marginpar@xmid{\dimexpr((\tp@marginpar@xmax+\tp@marginpar@xmin)/2)\relax}%
126 \setlength\tp@marginpar@ymax{\tp@body@ymax}%
127 \setlength\tp@marginpar@ymin{\tp@body@ymin}%
128 \setlength\tp@marginpar@ymid{\tp@body@ymid}%
129 %
130 %% header
131 %
132 \setlength\tp@header@xmax{\tp@body@xmax}%
133 \setlength\tp@header@xmin{\tp@body@xmin}%
134 \setlength\tp@header@xmid{\tp@body@xmid}%
135 \setlength\tp@header@ymin{\dimexpr\tp@body@ymax+\headsep\relax}%
136 \setlength\tp@header@ymax{\dimexpr\tp@header@ymin+\headheight\relax}%
137 \setlength\tp@header@ymid{\dimexpr((\tp@header@ymax+\tp@header@ymin)/2)\relax}%
138 %
139 %% footer
140 %
141 \setlength\tp@footer@xmax{\tp@body@xmax}%
142 \setlength\tp@footer@xmin{\tp@body@xmin}%
143 \setlength\tp@footer@xmid{\tp@body@xmid}%
144 \setlength\tp@footer@ymin{\dimexpr\tp@body@ymin-\footskip\relax}%
145 \setlength\tp@footer@ymax{\tp@footer@ymin}%
146 \setlength\tp@footer@ymid{\dimexpr((\tp@footer@ymax+\tp@footer@ymin)/2)\relax}%
147 %%
148 %% blocks%
149 %%
150 \setlength\tp@top@xmin{\tp@page@xmin}%
151 \setlength\tp@top@xmax{\tp@page@xmax}%
152 \setlength\tp@top@xmid{\dimexpr((\tp@top@xmax+\tp@top@xmin)/2)\relax}%
153 \setlength\tp@top@ymin{\tp@body@ymax}%
154 \setlength\tp@top@ymax{\tp@page@ymax}%
155 \setlength\tp@top@ymid{\dimexpr((\tp@top@ymax+\tp@top@ymin)/2)\relax}%
156 %%
157 \setlength\tp@bottom@xmin{\tp@page@xmin}%
158 \setlength\tp@bottom@xmax{\tp@page@xmax}%
159 \setlength\tp@bottom@xmid{\dimexpr((\tp@bottom@xmax+\tp@bottom@xmin)/2)\relax}%
160 \setlength\tp@bottom@ymin{\tp@page@ymin}%
161 \setlength\tp@bottom@ymax{\tp@body@ymin}%
162 \setlength\tp@bottom@ymid{\dimexpr((\tp@bottom@ymax+\tp@bottom@ymin)/2)\relax}%
163 %%
164 \setlength\tp@left@xmin{\tp@page@xmin}%
165 \setlength\tp@left@xmax{\tp@body@xmin}%
166 \setlength\tp@left@xmid{\dimexpr((\tp@left@xmax+\tp@left@xmin)/2)\relax}%
167 \setlength\tp@left@ymin{\tp@body@ymin}%
168 \setlength\tp@left@ymax{\tp@body@ymax}%
169 \setlength\tp@left@ymid{\dimexpr((\tp@left@ymax+\tp@left@ymin)/2)\relax}%
170 %%
171 \setlength\tp@right@xmin{\tp@body@xmax}%
172 \setlength\tp@right@xmax{\tp@page@xmax}%
173 \setlength\tp@right@xmid{\dimexpr((\tp@right@xmax+\tp@right@xmin)/2)\relax}%
174 \setlength\tp@right@ymin{\tp@body@ymin}%
175 \setlength\tp@right@ymax{\tp@body@ymax}%
176 \setlength\tp@right@ymid{\dimexpr((\tp@right@ymax+\tp@right@ymin)/2)\relax}%
177 }%% \end{macrocode}
178
179
180 \def\@tp@genanchors#1{%
181 \anchor{#1 north}{\pgf@x=\csname tp@#1@xmid\endcsname \pgf@y=\csname tp@#1@ymax\endcsname}%
182 \anchor{#1 south}{\pgf@x=\csname tp@#1@xmid\endcsname \pgf@y=\csname tp@#1@ymin\endcsname}%
183 \anchor{#1 west}{\pgf@x=\csname tp@#1@xmin\endcsname \pgf@y=\csname tp@#1@ymid\endcsname}%
184 \anchor{#1 northwest}{\pgf@x=\csname tp@#1@xmin\endcsname \pgf@y=\csname tp@#1@ymax\endcsname}%
185 \anchor{#1 southwest}{\pgf@x=\csname tp@#1@xmin\endcsname \pgf@y=\csname tp@#1@ymin\endcsname}%
186 \anchor{#1 east}{\pgf@x=\csname tp@#1@xmax\endcsname \pgf@y=\csname tp@#1@ymid\endcsname}%
187 \anchor{#1 northeast}{\pgf@x=\csname tp@#1@xmax\endcsname \pgf@y=\csname tp@#1@ymax\endcsname}%
188 \anchor{#1 southeast}{\pgf@x=\csname tp@#1@xmax\endcsname \pgf@y=\csname tp@#1@ymin\endcsname}%
189 \anchor{#1 center}{\pgf@x=\csname tp@#1@xmid\endcsname \pgf@y=\csname tp@#1@ymid\endcsname}%
190 }%
191
192 \newcommand\tp@pgfdeclareanchoralias[3]{%
193 \expandafter\def\csname pgf@anchor@#1@#3\expandafter\endcsname
194 \expandafter{\csname pgf@anchor@#1@#2\endcsname}}
195
196 \pgfdeclareshape{page}{
197 \backgroundpath{
198 \pgfpathmoveto{\pgfpoint{\tp@page@xmin}{\tp@page@ymin}}
199 \pgfpathlineto{\pgfpoint{\tp@page@xmin}{\tp@page@ymax}}
200 \pgfpathlineto{\pgfpoint{\tp@page@xmax}{\tp@page@ymax}}
201 \pgfpathlineto{\pgfpoint{\tp@page@xmax}{\tp@page@xmin}}
202 \pgfpathclose
203 }
204 %% basic anchors
205 \anchor{north}{\pgf@x=\tp@page@xmid \pgf@y=\tp@page@ymax}%
206 \anchor{south}{\pgf@x=\tp@page@xmid \pgf@y=\tp@page@ymin}%
207 \anchor{west}{\pgf@x=\tp@page@xmin \pgf@y=\tp@page@ymid}%
208 \anchor{northwest}{\pgf@x=\tp@page@xmin \pgf@y=\tp@page@ymax}%
209 \anchor{southwest}{\pgf@x=\tp@page@xmin \pgf@y=\tp@page@ymin}%
210 \anchor{east}{\pgf@x=\tp@page@xmax \pgf@y=\tp@page@ymid}%
211 \anchor{northeast}{\pgf@x=\tp@page@xmax \pgf@y=\tp@page@ymax}%
212 \anchor{southeast}{\pgf@x=\tp@page@xmax \pgf@y=\tp@page@ymin}%
213 %\anchor{center}{\pgfpointorigin}
214 \anchor{center}{\pgf@x=\tp@page@xmid \pgf@y=\tp@page@ymid}
215 \anchor{origin}{\pgfpointorigin}%\pgf@x=0pt \pgf@y=0pt}
216 \@tp@genanchors{page}
217 %% Body anchors
218 \@tp@genanchors{body}
219 \@tp@genanchors{marginpar}
220 \@tp@genanchors{header}
221 \@tp@genanchors{footer}
222 \@tp@genanchors{top}
223 \@tp@genanchors{bottom}
224 \@tp@genanchors{left}
225 \@tp@genanchors{right}
226 }
227
228 \newdimen\tp@linewidth
229 \newdimen\tp@marksize
230 \setlength\tp@marksize{3pt}
231 \pgfdeclareplotmark{tpx}{
232 \setlength{\tp@linewidth}{\pgflinewidth}
233 \pgfsetlinewidth{0.1pt}
234 \pgfpathmoveto{\pgfpoint{-\tp@marksize}{-\tp@marksize}}
235 \pgfpathlineto{\pgfpoint{\tp@marksize}{\tp@marksize}}
236 \pgfpathmoveto{\pgfpoint{-\tp@marksize}{\tp@marksize}}
237 \pgfpathlineto{\pgfpoint{\tp@marksize}{-\tp@marksize}}
238 \pgfusepathqstroke
239 \setlength{\pgflinewidth}{\tp@linewidth}
240 }
241
242
243 \def\tikzpageputanchorsdefaults{
244 \foreach \anchor/\placement in {%
245 northwest/below right%
246 ,north/below%
247 ,northeast/below left%
248 ,west/right%
249 ,center/below%
250 ,east/left%
251 ,southwest/above right%
252 ,south/above%
253 ,southeast/above left%
254 } \draw[red,shift=(page.\anchor)] plot[mark=tpx%% my plot mark
255 ] coordinates{(0,0)}
256 node[blue,\placement] {\scriptsize\texttt{(page.\anchor)}};
257 }
258
259 \def\tikzpageputanchorsbody{
260 \foreach \anchor/\placement in {%
261 body northwest/below right%
262 ,body north/below%
263 ,body northeast/below left%
264 ,body west/right%
265 ,body center/below%
266 ,body east/left%
267 ,body southwest/above right%
268 ,body south/above%
269 ,body southeast/above left%
270 } \draw[red,shift=(page.\anchor)] plot[mark=tpx%% my plot mark
271 ] coordinates{(0,0)}
272 node[blue,\placement] {\scriptsize\texttt{(page.\anchor)}};
273 }
274
275 \def\tikzpageputanchorsmarginpar{
276 \foreach \anchor/\placement in {%
277 marginpar northwest/below left%
278 ,marginpar north/left%
279 ,marginpar northeast/above left%
280 ,marginpar west/below%
281 ,marginpar center/below%
282 ,marginpar east/above%
283 ,marginpar southwest/below right%
284 ,marginpar south/right%
285 ,marginpar southeast/above right%
286 } \draw[red,shift=(page.\anchor)] plot[mark=tpx%% my plot mark
287 ] coordinates{(0,0)}
288 node[blue,\placement, rotate=90] {\scriptsize\texttt{(page.\anchor)}};
289 }
290
291 \def\tikzpageputanchorsheader{
292 \foreach \anchor/\placement in {%
293 header northwest/above right%
294 ,header north/above%
295 ,header northeast/above left%
296 ,header west/right%
297 ,header center/right%
298 ,header east/left%
299 ,header southwest/below right%
300 ,header south/below%
301 ,header southeast/below left%
302 } \draw[red,shift=(page.\anchor)] plot[mark=tpx%% my plot mark
303 ] coordinates{(0,0)}
304 node[blue,\placement] {\scriptsize\texttt{(page.\anchor)}};
305 }
306
307 \def\tikzpageputanchorsfooter{
308 \foreach \anchor/\placement in {%
309 footer northwest/above right%
310 ,footer north/above%
311 ,footer northeast/above left%
312 ,footer west/right%
313 ,footer center/right%
314 ,footer east/left%
315 ,footer southwest/below right%
316 ,footer south/below%
317 ,footer southeast/below left%
318 } \draw[red,shift=(page.\anchor)] plot[mark=tpx%% my plot mark
319 ] coordinates{(0,0)}
320 node[blue,\placement] {\scriptsize\texttt{(page.\anchor)}};
321 }
322
323 \def\tikzpageputanchorstop{
324 \foreach \anchor/\placement in {%
325 top northwest/below right%
326 ,top north/below%
327 ,top northeast/below left%
328 ,top west/right%
329 ,top center/below%
330 ,top east/left%
331 ,top southwest/above right%
332 ,top south/above%
333 ,top southeast/above left%
334 } \draw[red,shift=(page.\anchor)] plot[mark=tpx%% my plot mark
335 ] coordinates{(0,0)}
336 node[blue,\placement] {\scriptsize\texttt{(page.\anchor)}};
337 }
338
339 \def\tikzpageputanchorsbottom{
340 \foreach \anchor/\placement in {%
341 bottom northwest/below right%
342 ,bottom north/below%
343 ,bottom northeast/below left%
344 ,bottom west/right%
345 ,bottom center/below%
346 ,bottom east/left%
347 ,bottom southwest/above right%
348 ,bottom south/above%
349 ,bottom southeast/above left%
350 } \draw[red,shift=(page.\anchor)] plot[mark=tpx%% my plot mark
351 ] coordinates{(0,0)}
352 node[blue,\placement] {\scriptsize\texttt{(page.\anchor)}};
353 }
354
355 \def\tikzpageputanchorsleft{
356 \foreach \anchor/\placement in {%
357 left northwest/below left%
358 ,left north/left%
359 ,left northeast/above left%
360 ,left west/below%
361 ,left center/below%
362 ,left east/above%
363 ,left southwest/below right%
364 ,left south/right%
365 ,left southeast/above right%
366 } \draw[red,shift=(page.\anchor)] plot[mark=tpx%% my plot mark
367 ] coordinates{(0,0)}
368 node[blue,\placement, rotate=90] {\scriptsize\texttt{(page.\anchor)}};
369 }
370
371 \def\tikzpageputanchorsright{
372 \foreach \anchor/\placement in {%
373 right northwest/below left%
374 ,right north/left%
375 ,right northeast/above left%
376 ,right west/below%
377 ,right center/below%
378 ,right east/above%
379 ,right southwest/below right%
380 ,right south/right%
381 ,right southeast/above right%
382 } \draw[red,shift=(page.\anchor)] plot[mark=tpx%% my plot mark
383 ] coordinates{(0,0)}
384 node[blue,\placement, rotate=90] {\scriptsize\texttt{(page.\anchor)}};
385 }
386
387 \def\tikzpageputanchors{
388 \tikzpageputanchorsdefaults
389 \tikzpageputanchorsbody
390 \tikzpageputanchorsmarginpar
391 \tikzpageputanchorsheader
392 \tikzpageputanchorsfooter
393 \tikzpageputanchorstop
394 \tikzpageputanchorsbottom
395 \tikzpageputanchorsleft
396 \tikzpageputanchorsright
397 }
398
399 \def\tpshowframes{
400 \draw[fill=blue!50, opacity=.3, draw] (page.bottom northwest) rectangle (page.bottom southeast);
401 \draw[fill=yellow!50, opacity=.3, draw] (page.top northwest) rectangle (page.top southeast);
402 \draw[fill=red!50, opacity=.3, draw] (page.left northwest) rectangle (page.left southeast);
403 \draw[fill=green!50, opacity=.3, draw] (page.right northwest) rectangle (page.right southeast);
404 }
405
406 \def\tpfancyhdrdefault{
407 \node [outer sep=0,inner sep=0, anchor=mid] at (page.header center) {};
408 \node [outer sep=0,inner sep=0, anchor=mid east] at (page.header east) {\tpflip{\sl\leftmark}{\sl\rightmark}};
409 \node [outer sep=0,inner sep=0, anchor=mid west] at (page.header west) {\tpflip{\sl\rightmark}{\sl\leftmark}};
410 \node [outer sep=0,inner sep=0, anchor=base east] at (page.footer east) {};
411 \node [,outer sep=0,inner sep=0,anchor=base] at (page.footer center) {\thepage};
412 \node [outer sep=0,inner sep=0, anchor=base west] at (page.footer west) {};
413 }
414
415 \newcommand{\tikzpage}{
416 \if@tp@use@textpos
417 \begin{textblock*}{\textwidth}[0,0](0pt,0pt)%
418 \fi
419 \tp@compute@margins%
420 \if@tp@use@textpos
421 \begin{tikzpicture}[]%
422 \clip (0,0) rectangle (\paperwidth, \paperheight);
423 \else
424 \begin{tikzpicture}[remember picture, overlay]%
425 \fi
426 \if@tp@use@textpos
427 \node[anchor=origin,shape=page] (page) {};
428 \else
429 \node[anchor=origin,shape=page] (page) at (current page.south west) {};
430 \fi
431 \@ifundefined{tikzpagelayout}{}{\tikzpagelayout}
432 \end{tikzpicture}%
433 \if@tp@use@textpos
434 \end{textblock*}%
435 \fi
436 }
437
438 \fancypagestyle{plain}{
439 \fancyhf{}
440 \chead{\tikzpage}
441 }
442 \fancypagestyle{empty}{
443 \fancyhf{}
444 \chead{\tikzpage}
445 }
446
447 \makeatother
448
449
450 \endinput
451 %%
452 %% End of file `tikz-page.sty'.