summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/source/latex/tikz-page/tikz-page.dtx
blob: 27ffe0b964ae989fd6a7b63e35dbf54128602798 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
% \iffalse meta-comment % -*- latex -*-
%
%<*ignore>
\begingroup
  \catcode123=1 %
  \catcode125=2 %
  \def\x{LaTeX2e}%
\expandafter\endgroup
\ifcase 0\ifx\install y1\fi\expandafter
         \ifx\csname processbatchFile\endcsname\relax\else1\fi
         \ifx\fmtname\x\else 1\fi\relax
\else\csname fi\endcsname
%</ignore>
%<*install>
\input docstrip.tex
\keepsilent

\usedir{tex/latex/tikz-page}

\let\MetaPrefix\relax
\preamble
This is a generated file.

Copyright © 2016 by Sébastien Gross <seb•ɑƬ•chezwam•ɖɵʈ•org>

This program is free software. It comes without any warranty, to the extent
permitted by applicable law. You can redistribute it and/or modify it under
the terms of the Do What The Fuck You Want To Public License, Version 2, as
published by Sam Hocevar. See http://sam.zoy.org/wtfpl/COPYING for more
details.

This file may be distributed and/or modified under the conditions of
the LaTeX Project Public License, either version 1.3c of this license
or (at your option) any later version. The latest version of this
license is in:

http://www.latex-project.org/lppl.txt

and version 1.3c or later is part of all distributions of LaTeX
version 2006/05/20 or later.

\endpreamble%
\let\MetaPrefix\DoubleperCent


\generate{\file{tikz-page.sty}{\from{tikz-page.dtx}{tikz-page}}}

\obeyspaces
\Msg{*************************************************************}
\Msg{*                                                           *}
\Msg{* To finish the installation you have to move the following *}
\Msg{* file into a directory searched by TeX:                    *}
\Msg{*                                                           *}
\Msg{* tikz-page.sty                                             *}
\Msg{*                                                           *}
\Msg{* To produce the documentation run the file mypackage.dtx   *}
\Msg{* through LaTeX.                                            *}
\Msg{*                                                           *}
\Msg{* Happy TeXing!                                             *}
\Msg{*                                                           *}
\Msg{*************************************************************}
\endbatchfile
%</install>
%<*ignore>
\fi
%</ignore>
%<*driver>
\ProvidesFile{tikz-page.drv}
\documentclass{ltxdoc}
\EnableCrossrefs
\CodelineIndex
\RecordChanges
\usepackage[english]{babel}
\usepackage[T1]{fontenc} 
\usepackage[utf8]{inputenc}
\usepackage{tcolorbox}
\tcbuselibrary{listings,documentation}
\tcbuselibrary{documentation,listings,minted}
\tcbuselibrary{breakable}
\tcbuselibrary{skins,raster}
\tcbset{listing engine=minted}
\usepackage{url}
\usepackage{minted}
\usepackage{calc}
\usepackage{makeidx}
\usepackage[textpos]{tikz-page}
\renewcommand{\headrulewidth}{0pt}
\makeindex
\definecolor{halfgray}{gray}{0.55}
\newcommand\anglei{-45}
\newcommand\angleii{45}
\newcommand\angleiii{225}
\newcommand\angleiv{135}
\newcommand{\pagedecoration}{
  \tpflip{
    \coordinate (aux1) at ([yshift=-15pt]page.northeast);
    \coordinate (aux2) at ([yshift=-410pt]page.northeast);
    \coordinate (aux3) at ([xshift=-4.5cm]page.northeast);
    \coordinate (aux4) at ([yshift=-150pt]page.northeast);
  }{
    \coordinate (aux1) at ([yshift=-15pt]page.northwest);
    \coordinate (aux2) at ([yshift=-410pt]page.northwest);
    \coordinate (aux3) at ([xshift=4.5cm]page.northwest);
    \coordinate (aux4) at ([yshift=-150pt]page.northwest);
    \renewcommand\anglei{-135}
    \renewcommand\angleii{135}
    \renewcommand\angleiii{-45}
    \renewcommand\angleiv{45}
  }
  \begin{scope}[halfgray!40,line width=12pt,rounded corners=12pt]
    \draw (aux1) -- coordinate (a) ++(\angleiii:5) -- ++(\anglei:5.1) coordinate (b);
    \draw[shorten <= -10pt] (aux3) -- (a) -- (aux1);
    \draw[opacity=0.6,halfgray,shorten <= -10pt] (b) -- ++(\angleiii:2.2) -- ++(\anglei:2.2);
  \end{scope}
  \draw[halfgray,line width=8pt,rounded corners=8pt,shorten <= -10pt]
  (aux4) -- ++(\angleiii:0.8) -- ++(\anglei:0.8);
  \begin{scope}[halfgray!70,line width=6pt,rounded corners=8pt]
    \draw[shorten <= -10pt] (aux2) -- ++(\angleiii:3) coordinate[pos=0.45] (c) -- ++(\anglei:3.1);
    \draw (aux2) -- (c) -- ++(\angleiv:2.5) -- ++(\angleii:2.5) -- ++(\anglei:2.5) coordinate[pos=0.3] (d);   
    \draw (d) -- +(\angleii:1);
  \end{scope}
}

\newcommand{\tikzpagelayout}{
  \pagedecoration
  \node [,outer sep=0,inner sep=0,anchor=base] at (page.footer center) {\thepage};
  \node [,outer sep=0,inner sep=0,anchor=base, rotate=90, color=black!10] at (page.left south) {\footnotesize{tikz-page \pkgfileversion}};
}
\fancypagestyle{plain}{
  \fancyhf{}
  \chead{\tikzpage}
}
\fancypagestyle{titlepage}{
  \fancyhf{}
  \chead{\tikzpage}
}
\pagestyle{plain}
\begin{document}
\DocInput{tikz-page.dtx}
\printindex

\end{document}
%</driver>
%<*README>

%</README>

% \fi

% \iffalse
%% DeclareTCBListing{macrocode} leave a blank line after code.
% \fi

% \expandafter \let \csname macrocode\endcsname \relax \expandafter \let \csname endmacrocode\endcsname \relax
% \expandafter \let \csname macrocode*\endcsname \relax \expandafter \let \csname endmacrocode*\endcsname \relax
% \newminted[macrocode]{latex}{breaklines,breakafter=()/+-\\,baselinestretch=0.5,fontsize=\footnotesize,linenos,numbersep=3mm,firstnumber=last}
%
% \BeforeBeginEnvironment{macrocode}{%
% \begin{tcolorbox}[boxrule=0.1pt,colframe=red!75!black,left=8mm,width=\linewidth,breakable=true,colback=white,enhanced]}
% \AfterEndEnvironment{macrocode}{\end{tcolorbox}}%


% \newminted[example]{latex}{breaklines,breakafter=()/+-\\,baselinestretch=0.5,fontsize=\footnotesize}
% \BeforeBeginEnvironment{example}{%
% \begin{tcolorbox}[boxrule=0.1pt,colframe=red!75!black,left=8mm,width=\linewidth,breakable=true,colback=white,enhanced]}
% \AfterEndEnvironment{example}{\end{tcolorbox}}%

% \tcbset{
%   tpexample/.style = {%
%     enhanced jigsaw,
%     lower separated=false,
%     leftlower=0pt,
%     rightlower=0pt,
%     boxrule=0.1pt,
%     breakable=true,
%     colframe=red!75!black,
%     colback=white,
%     listing engine=minted,
%     minted options={breaklines,breakafter=()/+-\\,baselinestretch=0.5,fontsize=\footnotesize},
%     listing and comment,
%     pdf comment,
%     compilable listing,
%     run pdflatex}
% }


% \iffalse
%<*tikz-page>
% \fi
\def\pkgfileversion{1.0}
\def\pkgfiledate{2016/08/22}
% \iffalse
%</tikz-page>
% \fi

% \title{the \textsc{tikz-page} package }
% \author {Sébastien Gross <seb chezwam org>}
% \date{This file describes version \pkgfileversion\  (\pkgfiledate)}
% \maketitle
% \tableofcontents


% \section{Introduction}

% There are many ways to embelish a page with \LaTeX. One of the most
% easiest way is to use |fancyhdr| which allows to redefine both headers and
% footer. The |geometry| package is also useful to setup correct margins. If
% you need to put some background materials this might become painful,
% especially if you need your background to reach the page borders.

% There are some trick that help you in this task. |tikz-page| helps you in
% this way by the use of semeral mechanisms. Either you can use plain |tikz|
% picture on the background of your page, or use the \meta{textpos} option
% which enables absolute |textpos| positionning. Each method has its
% benefits and nuisances. With |tikz| you have to compile your document
% twice (which can be painful while you are designing your page layout) and
% with |textpos| you can get some incompatibility issues (please refer to
% |textpos| documentation).

% |tikz-page| is trying to give you best of both world by creating a new
% page object in a |tikzpicture| with many anchors. So you can easily place
% your page material at its correct position.


% \section{Usage}

% Basically you only need to add \mintinline{latex}{\usepackage{tikz-page}}
% at the begining of your document. Then you have to declare a
% \docAuxCommand{tikzpagelayout} command which is executed inside the
% background |tikzpicture|. Thus you can access the |page| shape and all its
% anchors. For example the following simple example add the page number to
% the footer center:

% \iffalse
%<*example>
% \fi
% \begin{example}
\newcommand{tikzpagelayout}{%
  \node [outer sep=0,inner sep=0,anchor=base] at (page.footer center) {\thepage};
}
% \end{example}
% \iffalse
%</example>
% \fi


% If you want to simulate the default |fancyhdr| behaviour you can define the
% \docAuxCommand{tikzpagelayout} as following:


% \iffalse
%<*example>
% \fi
% \begin{example}
\newcommand{tikzpagelayout}{%
  \node [outer sep=0,inner sep=0, anchor=mid east] at (page.header east) {\tpflip{\sl\leftmark}{\sl\rightmark}};
  \node [outer sep=0,inner sep=0, anchor=mid west] at (page.header west) {\tpflip{\sl\rightmark}{\sl\leftmark}};
  \node [,outer sep=0,inner sep=0,anchor=base] at (page.footer center) {\thepage};
% \end{example}
% \iffalse
%</example>
% \fi

% A minimum working example:
% \iffalse
%<*example>
% \fi
%\begin{tcblisting}{tpexample}
\documentclass{article}
\usepackage{tikz-page}
\usepackage{lipsum}
\newcommand{\tikzpagelayout}{
  \tpshowframes
  \tikzpageputanchors
}
\pagestyle{plain}
\begin{document}
\lipsum
\end{document}
% \end{tcblisting}
% \iffalse
%</example>
% \fi


% A more complex example\cite{Graphical Decoration}:
% \iffalse
%<*example>
% \fi
%\begin{tcblisting}{tpexample}
\documentclass{article}
\usepackage{tikz-page}
\usepackage{lipsum}
\definecolor{halfgray}{gray}{0.55}
\newcommand\anglei{-45}
\newcommand\angleii{45}
\newcommand\angleiii{225}
\newcommand\angleiv{135}
\newcommand{\tikzpagelayout}{
  \tpflip{
    \coordinate (aux1) at ([yshift=-15pt]page.northeast);
    \coordinate (aux2) at ([yshift=-410pt]page.northeast);
    \coordinate (aux3) at ([xshift=-4.5cm]page.northeast);
    \coordinate (aux4) at ([yshift=-150pt]page.northeast);
  }{
    \coordinate (aux1) at ([yshift=-15pt]page.northwest);
    \coordinate (aux2) at ([yshift=-410pt]page.northwest);
    \coordinate (aux3) at ([xshift=4.5cm]page.northwest);
    \coordinate (aux4) at ([yshift=-150pt]page.northwest);
    \renewcommand\anglei{-135}
    \renewcommand\angleii{135}
    \renewcommand\angleiii{-45}
    \renewcommand\angleiv{45}
  }
  \begin{scope}[halfgray!40,line width=12pt,rounded corners=12pt]
    \draw (aux1) -- coordinate (a) ++(\angleiii:5) -- ++(\anglei:5.1) coordinate (b);
    \draw[shorten <= -10pt] (aux3) -- (a) -- (aux1);
    \draw[opacity=0.6,halfgray,shorten <= -10pt] (b) -- ++(\angleiii:2.2) -- ++(\anglei:2.2);
  \end{scope}
  \draw[halfgray,line width=8pt,rounded corners=8pt,shorten <= -10pt]
  (aux4) -- ++(\angleiii:0.8) -- ++(\anglei:0.8);
  \begin{scope}[halfgray!70,line width=6pt,rounded corners=8pt]
    \draw[shorten <= -10pt] (aux2) -- ++(\angleiii:3) coordinate[pos=0.45] (c) -- ++(\anglei:3.1);
    \draw (aux2) -- (c) -- ++(\angleiv:2.5) -- ++(\angleii:2.5) -- ++(\anglei:2.5) coordinate[pos=0.3] (d);   
    \draw (d) -- +(\angleii:1);
  \end{scope}
}
\pagestyle{plain}
\begin{document}
\lipsum
\end{document}
% \end{tcblisting}
% \iffalse
%</example>
% \fi



% \iffalse
%<*tikz-page>
% \fi

% \iffalse
%% Reset the FancyVerbLine counter to have the correct lines number in front
%% of implementation.
% \fi
% \setcounter{FancyVerbLine}{0}

% \section{Implementation}

%    \begin{macrocode}
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{tikz-page}[\pkgfiledate\space (v\pkgfileversion)]
%    \end{macrocode}

% The \meta{textpos} option can be used if you want to use |textpos|
% \meta{overlay} option instead of |current page| to position the page
% layout. Beware that |textpos| with \meta{overlay} option maybe incompatible
% with some other packages. On the other hand |tikz| |current page| requires
% at least 2 compilation to work correctly. Thus you might want to use
% \meta{textpos} at conception time and remove this option for your final
% build or if you have incompatibility issues.

%    \begin{macrocode}
\newif\if@tp@use@textpos\@tp@use@textposfalse
\DeclareOption{textpos}{\@tp@use@textpostrue}
\ProcessOptions

\if@tp@use@textpos
\RequirePackage[absolute]{textpos}
\fi
%    \end{macrocode}

%    \begin{macrocode}
\RequirePackage{fancyhdr}
\RequirePackage{tikz}
\usetikzlibrary{plotmarks,calc,shapes,positioning,decorations.text}
\RequirePackage{graphicx}
\RequirePackage{calc}
%    \end{macrocode}


\makeatletter

% All margin sizes are defined in\docLength{@tp@left@margin},
% \docLength{@tp@right@margin}, \docLength{@tp@top@margin},
% \docLength{@tp@bottom@margin} their values are computed by the
% \refCom{tp@compute@margins}.

%    \begin{macrocode}
\newlength{\@tp@left@margin}
\newlength{\@tp@right@margin}
\newlength{\@tp@top@margin}
\newlength{\@tp@bottom@margin}
%    \end{macrocode}


% \begin{docCommand}{@tp@create@length}{\marg{block name}\marg{length name}}

% Generate a \cs{tp@\meta{block name}@\meta{length name}} length. This
% command is intended to be only used to create block length defined below.

%    \begin{macrocode}
\newcommand\@tp@create@length[2]{%
  \expandafter\newskip\csname tp@#1@#2\endcsname%
}%
%    \end{macrocode}
% \end{docCommand}
% 

% For each standard blocks in the page (|page|, |body|, |marginpar|,
% |header|, |footer|) and additionnal blocks (|top|, |right|, |bottom|,
% |left|), 6 lenths are computed in order to define their anchors. Each
% length is defined using the \refCom{@tp@create@length} macro.

%    \begin{macrocode}
\foreach\@@tp@element in {page,body,marginpar,header,footer,top,right,bottom,left}{%
  \foreach\@@tp@len in {xmin,xmax,xmid,ymin,ymax,ymid}{%
    \@tp@create@length{\@@tp@element}{\@@tp@len}%
}}%
%    \end{macrocode}

% \begin{docCommand}{tcflip}{\marg{odd page code}\marg{even page code}}
% Execute \meta{odd page even code} on odd pages and \meta{even page code}
% on even ones.
% \end{docCommand}
%    \begin{macrocode}
\newcommand{\tpflip}[2]{\ifodd\thepage#1\else#2\fi}
%    \end{macrocode}

% \begin{docCommand}{tp@compute@margins}{}
%
% This is where the magic happens. This command sets all \cs{tp@\meta{block
% name}@\meta{length name}} lengths.
%
% \end{docCommand}

%    \begin{macrocode}
\def\tp@compute@margins{%
  \setlength{\tp@page@xmin}{0pt}%
  \setlength{\tp@page@ymin}{0pt}%
  \setlength{\tp@page@xmax}{\paperwidth}%
  \setlength{\tp@page@ymax}{\paperheight}%
  \setlength{\tp@page@xmid}{\dimexpr(\tp@page@xmin+\tp@page@xmax)/2\relax}%
  \setlength{\tp@page@ymid}{\dimexpr(\tp@page@ymin+\tp@page@ymax)/2\relax}%
  %
  \setlength\@tp@left@margin{\dimexpr(1in+\hoffset+\tpflip{\oddsidemargin}{\evensidemargin})\relax}%
  \setlength\@tp@right@margin{\dimexpr(\paperwidth-\@tp@left@margin-\textwidth)\relax}%
  \setlength\@tp@top@margin{\dimexpr(1in+\voffset+\topmargin+\headheight+\headsep)\relax}%
  \setlength\@tp@bottom@margin{\dimexpr(\paperheight-(\textheight+\@tp@top@margin))\relax}%
  %% Body computation
  \setlength\tp@body@xmin{\dimexpr\tp@page@xmin+\@tp@left@margin\relax}%
  \setlength\tp@body@xmax{\dimexpr\tp@page@xmax-\@tp@right@margin\relax}%
  \setlength\tp@body@xmid{\dimexpr((\tp@body@xmax+\tp@body@xmin)/2)\relax}%
  \setlength\tp@body@ymax{\dimexpr(\tp@page@ymax-\@tp@top@margin)\relax}%
  \setlength\tp@body@ymin{\dimexpr\tp@body@ymin+\@tp@bottom@margin\relax}%
  \setlength\tp@body@ymid{\dimexpr(\tp@body@ymin+(\tp@body@ymax-\tp@body@ymin)/2)\relax}%
  %
  %% Margin computation
  %
  \tpflip{%
    \setlength\tp@marginpar@xmin{\dimexpr\tp@body@xmax+\marginparsep\relax}
    \setlength\tp@marginpar@xmax{\dimexpr\tp@marginpar@xmin+\marginparwidth\relax}%
  }{%
    \setlength\tp@marginpar@xmax{\dimexpr\tp@body@xmin-\marginparsep\relax}%
    \setlength\tp@marginpar@xmin{\dimexpr\tp@marginpar@xmax-\marginparwidth\relax}%
  }%
  \setlength\tp@marginpar@xmid{\dimexpr((\tp@marginpar@xmax+\tp@marginpar@xmin)/2)\relax}%
  \setlength\tp@marginpar@ymax{\tp@body@ymax}%
  \setlength\tp@marginpar@ymin{\tp@body@ymin}%
  \setlength\tp@marginpar@ymid{\tp@body@ymid}%
  %
  %% header
  %
  \setlength\tp@header@xmax{\tp@body@xmax}%
  \setlength\tp@header@xmin{\tp@body@xmin}%
  \setlength\tp@header@xmid{\tp@body@xmid}%
  \setlength\tp@header@ymin{\dimexpr\tp@body@ymax+\headsep\relax}%
  \setlength\tp@header@ymax{\dimexpr\tp@header@ymin+\headheight\relax}%
  \setlength\tp@header@ymid{\dimexpr((\tp@header@ymax+\tp@header@ymin)/2)\relax}%
  %
  %% footer
  %
  \setlength\tp@footer@xmax{\tp@body@xmax}%
  \setlength\tp@footer@xmin{\tp@body@xmin}%
  \setlength\tp@footer@xmid{\tp@body@xmid}%
  \setlength\tp@footer@ymin{\dimexpr\tp@body@ymin-\footskip\relax}%
  \setlength\tp@footer@ymax{\tp@footer@ymin}%
  \setlength\tp@footer@ymid{\dimexpr((\tp@footer@ymax+\tp@footer@ymin)/2)\relax}%
  %%
  %% blocks%
  %%
  \setlength\tp@top@xmin{\tp@page@xmin}%
  \setlength\tp@top@xmax{\tp@page@xmax}%
  \setlength\tp@top@xmid{\dimexpr((\tp@top@xmax+\tp@top@xmin)/2)\relax}%
  \setlength\tp@top@ymin{\tp@body@ymax}%
  \setlength\tp@top@ymax{\tp@page@ymax}%
  \setlength\tp@top@ymid{\dimexpr((\tp@top@ymax+\tp@top@ymin)/2)\relax}%
  %%
  \setlength\tp@bottom@xmin{\tp@page@xmin}%
  \setlength\tp@bottom@xmax{\tp@page@xmax}%
  \setlength\tp@bottom@xmid{\dimexpr((\tp@bottom@xmax+\tp@bottom@xmin)/2)\relax}%
  \setlength\tp@bottom@ymin{\tp@page@ymin}%
  \setlength\tp@bottom@ymax{\tp@body@ymin}%
  \setlength\tp@bottom@ymid{\dimexpr((\tp@bottom@ymax+\tp@bottom@ymin)/2)\relax}%
  %%
  \setlength\tp@left@xmin{\tp@page@xmin}%
  \setlength\tp@left@xmax{\tp@body@xmin}%
  \setlength\tp@left@xmid{\dimexpr((\tp@left@xmax+\tp@left@xmin)/2)\relax}%
  \setlength\tp@left@ymin{\tp@body@ymin}%
  \setlength\tp@left@ymax{\tp@body@ymax}%
  \setlength\tp@left@ymid{\dimexpr((\tp@left@ymax+\tp@left@ymin)/2)\relax}%
  %%
  \setlength\tp@right@xmin{\tp@body@xmax}%
  \setlength\tp@right@xmax{\tp@page@xmax}%
  \setlength\tp@right@xmid{\dimexpr((\tp@right@xmax+\tp@right@xmin)/2)\relax}%
  \setlength\tp@right@ymin{\tp@body@ymin}%
  \setlength\tp@right@ymax{\tp@body@ymax}%
  \setlength\tp@right@ymid{\dimexpr((\tp@right@ymax+\tp@right@ymin)/2)\relax}%
}%%    \end{macrocode}

% \begin{docCommand}{@tp@genanchors}{\marg{block name}}
% Generate all 9 anchors (|northwest|, |north|, |northest|, |west|,
% |center|, |east|, |southwest|, |south|, |southest|) for \meta{block name}.
% \end{docCommand}

%    \begin{macrocode}
\def\@tp@genanchors#1{%
  \anchor{#1 north}{\pgf@x=\csname tp@#1@xmid\endcsname \pgf@y=\csname tp@#1@ymax\endcsname}%
  \anchor{#1 south}{\pgf@x=\csname tp@#1@xmid\endcsname \pgf@y=\csname tp@#1@ymin\endcsname}%
  \anchor{#1 west}{\pgf@x=\csname tp@#1@xmin\endcsname \pgf@y=\csname tp@#1@ymid\endcsname}%
  \anchor{#1 northwest}{\pgf@x=\csname tp@#1@xmin\endcsname \pgf@y=\csname tp@#1@ymax\endcsname}%
  \anchor{#1 southwest}{\pgf@x=\csname tp@#1@xmin\endcsname \pgf@y=\csname tp@#1@ymin\endcsname}%
  \anchor{#1 east}{\pgf@x=\csname tp@#1@xmax\endcsname \pgf@y=\csname tp@#1@ymid\endcsname}%
  \anchor{#1 northeast}{\pgf@x=\csname tp@#1@xmax\endcsname \pgf@y=\csname tp@#1@ymax\endcsname}%
  \anchor{#1 southeast}{\pgf@x=\csname tp@#1@xmax\endcsname \pgf@y=\csname tp@#1@ymin\endcsname}%
  \anchor{#1 center}{\pgf@x=\csname tp@#1@xmid\endcsname \pgf@y=\csname tp@#1@ymid\endcsname}%
}% 
%    \end{macrocode}

%    \begin{macrocode}
\newcommand\tp@pgfdeclareanchoralias[3]{%
  \expandafter\def\csname pgf@anchor@#1@#3\expandafter\endcsname
    \expandafter{\csname pgf@anchor@#1@#2\endcsname}}
%    \end{macrocode}

%    \begin{macrocode}
\pgfdeclareshape{page}{
  \backgroundpath{
    \pgfpathmoveto{\pgfpoint{\tp@page@xmin}{\tp@page@ymin}}
    \pgfpathlineto{\pgfpoint{\tp@page@xmin}{\tp@page@ymax}}
    \pgfpathlineto{\pgfpoint{\tp@page@xmax}{\tp@page@ymax}}
    \pgfpathlineto{\pgfpoint{\tp@page@xmax}{\tp@page@xmin}}
    \pgfpathclose
  }
  %% basic anchors
  \anchor{north}{\pgf@x=\tp@page@xmid \pgf@y=\tp@page@ymax}%
  \anchor{south}{\pgf@x=\tp@page@xmid \pgf@y=\tp@page@ymin}%
  \anchor{west}{\pgf@x=\tp@page@xmin \pgf@y=\tp@page@ymid}%
  \anchor{northwest}{\pgf@x=\tp@page@xmin \pgf@y=\tp@page@ymax}%
  \anchor{southwest}{\pgf@x=\tp@page@xmin \pgf@y=\tp@page@ymin}%
  \anchor{east}{\pgf@x=\tp@page@xmax \pgf@y=\tp@page@ymid}%
  \anchor{northeast}{\pgf@x=\tp@page@xmax \pgf@y=\tp@page@ymax}%
  \anchor{southeast}{\pgf@x=\tp@page@xmax \pgf@y=\tp@page@ymin}%
  %\anchor{center}{\pgfpointorigin}
  \anchor{center}{\pgf@x=\tp@page@xmid \pgf@y=\tp@page@ymid}
  \anchor{origin}{\pgfpointorigin}%\pgf@x=0pt \pgf@y=0pt}
  \@tp@genanchors{page}
  %% Body anchors
  \@tp@genanchors{body}
  \@tp@genanchors{marginpar}
  \@tp@genanchors{header}
  \@tp@genanchors{footer}
  \@tp@genanchors{top}
  \@tp@genanchors{bottom}
  \@tp@genanchors{left}
  \@tp@genanchors{right}
}
%    \end{macrocode}


%Create a new |tpx| mark to show anchor location when using
%\refCom{tikzpageputanchors} to display anchors on the page.
%
%    \begin{macrocode}
\newdimen\tp@linewidth
\newdimen\tp@marksize
\setlength\tp@marksize{3pt}
\pgfdeclareplotmark{tpx}{
  \setlength{\tp@linewidth}{\pgflinewidth}
  \pgfsetlinewidth{0.1pt}
  \pgfpathmoveto{\pgfpoint{-\tp@marksize}{-\tp@marksize}}
  \pgfpathlineto{\pgfpoint{\tp@marksize}{\tp@marksize}}
  \pgfpathmoveto{\pgfpoint{-\tp@marksize}{\tp@marksize}}
  \pgfpathlineto{\pgfpoint{\tp@marksize}{-\tp@marksize}}
  \pgfusepathqstroke
  \setlength{\pgflinewidth}{\tp@linewidth}
}
%    \end{macrocode}


% Anchors can be displayed block by block (using
% \cs{tikzpageputanchorsdefaults}, \cs{tikzpageputanchors}
% \cs{tikzpageputanchorsmarginpar}, \cs{tikzpageputanchorsheader},
% \cs{tikzpageputanchorsfooter}, \cs{tikzpageputanchorstop},
% \cs{tikzpageputanchorsright}, \cs{tikzpageputanchorsbottom},
% \cs{tikzpageputanchorsleft}) or globally (using \refCom{tikzpageputanchors}).

%    \begin{macrocode}
\def\tikzpageputanchorsdefaults{
  \foreach \anchor/\placement in {%
    northwest/below right%
    ,north/below%
    ,northeast/below left%
    ,west/right%
    ,center/below%
    ,east/left%
    ,southwest/above right%
    ,south/above%
    ,southeast/above left%
  } \draw[red,shift=(page.\anchor)] plot[mark=tpx%% my plot mark
  ] coordinates{(0,0)}
  node[blue,\placement] {\scriptsize\texttt{(page.\anchor)}};
}

\def\tikzpageputanchorsbody{
  \foreach \anchor/\placement in {%
    body northwest/below right%
    ,body north/below%
    ,body northeast/below left%
    ,body west/right%
    ,body center/below%
    ,body east/left%
    ,body southwest/above right%
    ,body south/above%
    ,body southeast/above left%
  } \draw[red,shift=(page.\anchor)] plot[mark=tpx%% my plot mark
  ] coordinates{(0,0)}
  node[blue,\placement] {\scriptsize\texttt{(page.\anchor)}};
}


\def\tikzpageputanchorsmarginpar{
  \foreach \anchor/\placement in {%
    marginpar northwest/below left%
    ,marginpar north/left%
    ,marginpar northeast/above left%
    ,marginpar west/below%
    ,marginpar center/below%
    ,marginpar east/above%
    ,marginpar southwest/below right%
    ,marginpar south/right%
    ,marginpar southeast/above right%
  } \draw[red,shift=(page.\anchor)] plot[mark=tpx%% my plot mark
  ] coordinates{(0,0)}
  node[blue,\placement, rotate=90] {\scriptsize\texttt{(page.\anchor)}};
}


\def\tikzpageputanchorsheader{
  \foreach \anchor/\placement in {%
    header northwest/above right%
    ,header north/above%
    ,header northeast/above left%
    ,header west/right%
    ,header center/right%
    ,header east/left%
    ,header southwest/below right%
    ,header south/below%
    ,header southeast/below left%
  } \draw[red,shift=(page.\anchor)] plot[mark=tpx%% my plot mark
  ] coordinates{(0,0)}
  node[blue,\placement] {\scriptsize\texttt{(page.\anchor)}};
}


\def\tikzpageputanchorsfooter{
  \foreach \anchor/\placement in {%
    footer northwest/above right%
    ,footer north/above%
    ,footer northeast/above left%
    ,footer west/right%
    ,footer center/right%
    ,footer east/left%
    ,footer southwest/below right%
    ,footer south/below%
    ,footer southeast/below left%
  } \draw[red,shift=(page.\anchor)] plot[mark=tpx%% my plot mark
  ] coordinates{(0,0)}
  node[blue,\placement] {\scriptsize\texttt{(page.\anchor)}};
}

\def\tikzpageputanchorstop{
  \foreach \anchor/\placement in {%
    top northwest/below right%
    ,top north/below%
    ,top northeast/below left%
    ,top west/right%
    ,top center/below%
    ,top east/left%
    ,top southwest/above right%
    ,top south/above%
    ,top southeast/above left%
  } \draw[red,shift=(page.\anchor)] plot[mark=tpx%% my plot mark
  ] coordinates{(0,0)}
  node[blue,\placement] {\scriptsize\texttt{(page.\anchor)}};
}


\def\tikzpageputanchorsbottom{
  \foreach \anchor/\placement in {%
    bottom northwest/below right%
    ,bottom north/below%
    ,bottom northeast/below left%
    ,bottom west/right%
    ,bottom center/below%
    ,bottom east/left%
    ,bottom southwest/above right%
    ,bottom south/above%
    ,bottom southeast/above left%
  } \draw[red,shift=(page.\anchor)] plot[mark=tpx%% my plot mark
  ] coordinates{(0,0)}
  node[blue,\placement] {\scriptsize\texttt{(page.\anchor)}};
}


\def\tikzpageputanchorsleft{
  \foreach \anchor/\placement in {%
    left northwest/below left%
    ,left north/left%
    ,left northeast/above left%
    ,left west/below%
    ,left center/below%
    ,left east/above%
    ,left southwest/below right%
    ,left south/right%
    ,left southeast/above right%
  } \draw[red,shift=(page.\anchor)] plot[mark=tpx%% my plot mark
  ] coordinates{(0,0)}
  node[blue,\placement, rotate=90] {\scriptsize\texttt{(page.\anchor)}};
}

\def\tikzpageputanchorsright{
  \foreach \anchor/\placement in {%
    right northwest/below left%
    ,right north/left%
    ,right northeast/above left%
    ,right west/below%
    ,right center/below%
    ,right east/above%
    ,right southwest/below right%
    ,right south/right%
    ,right southeast/above right%
  } \draw[red,shift=(page.\anchor)] plot[mark=tpx%% my plot mark
  ] coordinates{(0,0)}
  node[blue,\placement, rotate=90] {\scriptsize\texttt{(page.\anchor)}};
}
%    \end{macrocode}

% \begin{docCommand}{tikzpageputanchors}{}
% A simple short hand to display all anchors at once.
% \end{docCommand}
%    \begin{macrocode}
\def\tikzpageputanchors{
  \tikzpageputanchorsdefaults
  \tikzpageputanchorsbody
  \tikzpageputanchorsmarginpar
  \tikzpageputanchorsheader
  \tikzpageputanchorsfooter
  \tikzpageputanchorstop
  \tikzpageputanchorsbottom
  \tikzpageputanchorsleft
  \tikzpageputanchorsright
}
%    \end{macrocode}



% \begin{docCommand}{tpshowframes}{}
% 
% Display |top|, |right|, |bottom| and |left| block using a specific
% background. This can be used in conjunction with \refCom{tikzpageputanchors} for
% debuging purposes.
% 
% \end{docCommand}
%    \begin{macrocode}
\def\tpshowframes{
  \draw[fill=blue!50, opacity=.3, draw] (page.bottom northwest) rectangle (page.bottom southeast);
  \draw[fill=yellow!50, opacity=.3, draw] (page.top northwest) rectangle (page.top southeast);
  \draw[fill=red!50, opacity=.3, draw] (page.left northwest) rectangle (page.left southeast);
  \draw[fill=green!50, opacity=.3, draw] (page.right northwest) rectangle (page.right southeast);
}
%    \end{macrocode}


% \begin{docCommand}{tpfancyhdrdefault}{}
% An example to display headers and footer as |fancyhdr| does.
% \end{docCommand}
%    \begin{macrocode}
\def\tpfancyhdrdefault{
  \node [outer sep=0,inner sep=0, anchor=mid] at (page.header center) {};
  \node [outer sep=0,inner sep=0, anchor=mid east] at (page.header east) {\tpflip{\sl\leftmark}{\sl\rightmark}};
  \node [outer sep=0,inner sep=0, anchor=mid west] at (page.header west) {\tpflip{\sl\rightmark}{\sl\leftmark}};
  \node [outer sep=0,inner sep=0, anchor=base east] at (page.footer east) {};
  \node [,outer sep=0,inner sep=0,anchor=base] at (page.footer center) {\thepage};
  \node [outer sep=0,inner sep=0, anchor=base west] at (page.footer west) {};
}
%    \end{macrocode}

% \begin{docCommand}{tikzpage}{}
% Generate a |tikzpicture| for the whole page. if a \cs{tikzpagelayout}
% command exists, it will be executed.
% \end{docCommand}
%    \begin{macrocode}
\newcommand{\tikzpage}{
  \if@tp@use@textpos
  \begin{textblock*}{\textwidth}[0,0](0pt,0pt)%
    \fi
    \tp@compute@margins%
    \if@tp@use@textpos
    \begin{tikzpicture}[]%
      \clip (0,0) rectangle (\paperwidth, \paperheight);
      \else
      \begin{tikzpicture}[remember picture, overlay]%
      \fi
      \if@tp@use@textpos
      \node[anchor=origin,shape=page] (page) {};
      \else
      \node[anchor=origin,shape=page] (page) at (current page.south west) {};
      \fi
      \@ifundefined{tikzpagelayout}{}{\tikzpagelayout}
    \end{tikzpicture}%
  \if@tp@use@textpos
  \end{textblock*}%
  \fi
}
%    \end{macrocode}


\fancypagestyle{plain}{
  \fancyhf{}
  \chead{\tikzpage}
}
\fancypagestyle{empty}{
  \fancyhf{}
  \chead{\tikzpage}
}


%
\makeatother
% \iffalse
%</tikz-page>
% \fi
%
% \Finale
%
% 
% \iffalse
% <*example>
% \fi
% \begin{thebibliography}{9}

% \bibitem{Graphical Decoration} Trying to do graphical decorations in
% “ClassicThesis style” \url{http://tex.stackexchange.com/questions/86294}
% \end{thebibliography}
% \iffalse
% </example>
% \fi

\endinput