summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/source/latex/textpos/textpos.dtx
blob: b2faedc0d2ef95a036c849d70138a427b6f9db74 (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
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
% \iffalse
% This is textpos.dtx, which allows you to place text (and graphics)
% anywhere on the LaTeX page.  It's useful for posters.
%
%% This software is copyright, 1999, 2001--2003, 2005--7, 2009 Norman Gray. 
%% 
%% This program is free software; you can redistribute it and/or
%% modify it under the terms of the GNU General Public License
%% as published by the Free Software Foundation; either version 2
%% of the License, or (at your option) any later version.
%% 
%% This program is distributed in the hope that it will be useful,
%% but WITHOUT ANY WARRANTY; without even the implied warranty of
%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
%% GNU General Public License for more details.
%% 
%% You should have received a copy of the GNU General Public License
%% along with this program; if not, write to the Free Software
%% Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
%% 
%% Author: Norman Gray, norman@astro.gla.ac.uk.
%% Department of Physics and Astronomy, University of Glasgow, UK
%%
%% See the file LICENCE for a copy of the GPL.
%% You can also find an online copy at http://www.gnu.org/copyleft/gpl.html .
%%
%<+package|driver|example>%%% Source: @HGIDENT@
%%
%<*package|driver>
\def\filename{textpos}
\def\fileversion{1.7f}
\def\filedate{2009/05/28}
\def\docdate{2009 May 28}
%</package|driver>
%<+package>\NeedsTeXFormat{LaTeX2e}
%<+package>\ProvidesPackage{textpos}[\filedate\space v\fileversion]
%<+package>\typeout{Package: `textpos' \fileversion\space<\docdate>}
%
%<*driver>
\documentclass{ltxdoc}
\title{Textpos: absolute positioning of text on the page}
\author{Norman Gray\\(\texttt{http://nxg.me.uk})}
\date{Version \fileversion, \filedate}
\newcommand\Lopt[1]{\textsf {\small [#1]}}
\newcommand\file[1]{\texttt {#1}}
\newcommand\Lcount[1]{\textsl {\small#1}}
\newcommand\Lenv[1]{\texttt{\{#1\}}}
\newcommand\pstyle[1]{\textsl {#1}}
\makeatletter % make the ttfamily font less overbearingly large
\renewcommand\ttfamily{\not@math@alphabet\ttfamily\mathtt
    \fontfamily\ttdefault
    \fontsize{9}{\f@baselineskip}\selectfont}
\makeatother
% Make command strings easier to write
\def\activemeta#1>{\meta{#1}}
{\catcode`\<=\active
 \gdef\cmd{\begingroup
   \catcode`\\=12 \catcode`\{=12 \catcode`\}=12 
   \catcode`\<=\active \let<\activemeta
   \catcode`\|=12
   \docmd}}
\def\docmd|#1|{\texttt{#1}\endgroup}
%% \url macro (url.sty does this better)
\def\setpathdots{\discretionary{.}{}{.}}
\def\setpathslash{\discretionary{/}{}{/}}
{\catcode`\.=\active 
 \catcode`\/=\active 
  \gdef\pathcats{%
    \catcode`\%=12      \catcode`\~=12 
    \catcode`\.=\active  \let.\setpathdots
    \catcode`\/=\active \let/\setpathslash
    \catcode`\#=12      \catcode`\_=12}%
    }
\def\setpath#1{\ttfamily\small <\nobreak #1\nobreak>\endgroup}
\def\url{\begingroup\pathcats\setpath}
%\RecordChanges
\OnlyDescription
\begin{document}
\maketitle
\DocInput{textpos.dtx}
\end{document}
%</driver>
%
% \fi
%
%
%
%
% \changes{v1.0a}{1998/04/29}{Robin Fairbairns pointed out and adjusted errors in the documentation}
% \changes{v1.0b}{1998/04/30}{Reorganised documentation -- properly this time}
% \changes{v1.1b}{1999/03/05}{Added note to the effect that everyshi can be found at CTAN}
% \changes{v1.1c}{1999/03/09}{Corrected checksum (again!)}
% \changes{v1.1d}{1999/06/06}{Clarified copyright and licence status}
% \changes{v1.3?}{2003/06/??}{Finally removed bloody useless checksum and character table}
%
%
% This package facilitates placing boxes at absolute positions on the
% \LaTeX\ page.  There are several reasons why this might be useful, but
% the reaason which originally motivated this package is to help produce a
% large-format conference poster.  However the facility is also useful
% for filling in forms or other special purpose layout.
%
% This package provides a single environment, which contains the text
% (or graphics, or table, or whatever) which is to be placed on the
% page, and which specifies where it is to be placed.
%
% The package tries not to get in the way.  That is, you should be
% able to use most of the apparatus of \LaTeX\ in your poster, such as
% section headings, citations, graphics inclusion, and so on.  Please
% let me know if you experience problems in this respect.
%
% This package requires the services of Martin Schr\"oder's package
% \texttt{everyshi}.  If this is not already part of your \TeX{}
% installation, you will need to download this package from CTAN.  See
% \url{http://www.tex.ac.uk/tex-archive/macros/latex/contrib/supported/ms/} 
% or one of the other CTAN hosts.
%
% This software is copyright, 1999, 2001--03, 2005--7, 2009 Norman Gray.  It
% is released under
% the terms of the GNU General Public Licence.  See the copyright
% declaration at the top of file \texttt{textpos.dtx}, and the file
% \texttt{LICENCE} for the licence conditions.  You can find an
% online copy of the GPL at \url{http://www.gnu.org/copyleft/gpl.html}.
%
% An article describing Textpos appeared in TUGboat in 2004
% (Norman Gray, `Absolute Positioning with  
% Textpos', TUGboat \textbf{23} (3/4), pp341--4, 2002, available at
% \url{http://www.tug.org/TUGboat/Contents/contents23-3-4.html}). 
% Textpos has a home page at
% \url{http://purl.org/nxg/dist/textpos}.
%
% \section{Description}
%
% Load the package as usual, with
% \begin{quote}
% \cmd|\usepackage<package-options>{textpos}|
% \end{quote}
% The \meta{package-options} are as described in section~\ref{packopts}.
%
% The environment is used as follows
% \DescribeEnv{textblock}
% \begin{quote}\begin{raggedright}
% \cmd|\begin{textblock}{<hsize>}(<hpos>,<vpos>)|\\
% text...\\
% |\end{textblock}|
% \end{raggedright}
% \end{quote}
% The \meta{hsize} and \meta{hpos} arguments are given in units of a
% module |\TPHorizModule|, and \meta{vpos} is given in units of a
% module |\TPVertModule|.  You set these using
% the command 
% \cmd|\setlength{\TPHorizModule}{<dimen>}|,
% and similarly for |\TPVertModule|.
% The arguments may be any dimension, and you may use the modules as
% units elsewhere in your document if you wish to, for example in
% \texttt{\bslash makebox[2\bslash TPHorizModule]\{gnus\}}.  The text in the
% environment will be set in a 
% box \meta{hsize} modules wide, and placed on the page with its
% upper left corner at the position (\textit{hpos,vpos}).  As is
% natural in \TeX, the \meta{vpos} parameter indicates distance
% \emph{down} from the reference point.
%
% The \Lenv{textblock} parameters may be whole numbers or
% fractional.  If you want or need to give explicit sizes here, see
% the \Lenv{textblock*} environment below.
%
% Notice that the positioning arguments for the \Lenv{textblock}
% command -- the coordinates \cmd|...(<hpos>,<vpos>)| -- are in
% \emph{round} brackets, not 
% curly ones.  This is in imitation of the \texttt{picture}
% environment, and whether or not this is sensible, it's not going to
% change now.
%
% The textblocks are placed on the page in the order in which they
% appear in the file.  This means that later textblocks will be placed
% on top of earlier ones, which may matter if one or other contains,
% for example, a block of opaque colour (I believe this to be true in
% practice for all output mechanisms, though I doubt it's guaranteed
% in principle).  This order was unspecified before textpos 1.7e; it
% was changed, and specified, in that version.
%
% \DescribeMacro{\TPGrid}
% You will often wish to set up a grid on your page.  Rather than
% calculate and specify the two modules explicitly, you can set up the
% grid with a command
% \cmd|\TPGrid{<nhoriz>}{<nvert>}|, which sets
% |\TPHorizModule| to be \meta{paper
% width}/\meta{nhoriz}, and |\TPVertModule| to be
% \meta{paper height}/\meta{nvert}.  This takes an optional pair of
% dimension arguments, which specify a coordinate, as follows.
% \begin{quote}\begin{raggedright}
%   \cmd|\TPGrid[<x>,<y>]{<nhoriz>}{<nvert>}|
% \end{raggedright}\end{quote}
% If these are present, then the modules are set
% up to leave a border of the given size around the grid.  That is, 
% |\TPHorizModule| is set to be (\meta{paper
% width}${}-{}2$\meta{x})/\meta{nhoriz}, and similarly for
% |\TPVertModule|.  Further, if the package was given
% the \Lopt{absolute} option, then the text origin is set to be
% (\meta{x},\meta{y}) through a call to |\textblockorigin|
% (see below).  For example, the declaration
% \begin{quote}\begin{raggedright}
%   \cmd|\TPGrid[40mm,20mm]{10}{5}|
% \end{raggedright}\end{quote}
% would choose \cmd|\TPHorizModule| and \cmd|\TPVertModule| so as to
% give a grid of 10~intervals across and 5~intervals down, after
% leaving 40mm of a border on the right and left sides, and a 20mm
% border top and bottom.
%
% You may give a optional argument to the \Lenv{textblock}
% environment, specifying which point in the box
% is to be placed at the specified point:
% \begin{quote}
% \begin{raggedright}
% \cmd|\begin{textblock}{<hsize>}[<ho>,<vo>](<hpos>,<vpos>)|\\
% text...\\
% |\end{textblock}|
% \end{raggedright}
% \end{quote}
% The coordinates \meta{ho} and \meta{vo} are fractions of the
% width and height of the text box, respectively, and state that the
% box is to be placed so that the
% point (\meta{ho},\meta{vo}) within the box is to be placed at the point
% (\meta{hpos},\meta{vpos}) on the page.  The default specification is
% [0,0], the top left of the box: [0,1] would be the bottom left, and
% [0.5,0.5] the middle.
%
% \DescribeMacro{\TPMargin}
% By default, the box that is positioned by the
% \Lenv{textblock} environment is a tight fit to the block of text
% (or other material) inside it.  This looks rather odd when you also
% use the |\textblockcolour| macro described below, or specify a larger
% than default |\TPboxrulesize|, in order to get a noticeable border
% round a piece of text.  In those cases, you will want to request a
% non-zero margin around your text.  If you give the command
% \begin{quote}
% |\TPMargin{|\meta{size}|}|
% \end{quote}
% then the block of text inside the textblock will be decreased in
% width, enough to give the specified margin on each side.  That is,
% the \meta{hsize} of the textblock, and thus the coloured block (or
% the edge of the displayed border), remains the same, but the text
% width inside it decreases.  The parameter \meta{size} may be any
% non-negative dimension, and may as usual be in units of
% |\TPHorizModule| or |\TPVertModule|.  The default behaviour is
% recovered by giving a \meta{size} of \texttt{0pt}.
%
% There is a starred variant of this command,
% |\TPMargin*{|\meta{size}|}|, where the argument must again be
% non-negative.  In this case, the text block inside the box is set
% with the \meta{hsize} specified in the \Lenv{textblock}
% environment, but the coloured block is increased in size, such that
% there is again a margin of the specified size around the text block.
%
% The \Lenv{textblock} environment will most often be used in
% vertical mode.  If it is called in horizontal (ie, paragraph) mode,
% however, it will silently create a paragraph break by inserting a
% |\par| command before the environment; it remains in vertical mode
% after the environment is finished.  It should have no further
% effects on spacing, and if you find that it does, that's a bug.  If
% you try to use the environment when in maths mode, the package
% objects (as it should!).
%
% \DescribeEnv{textblock*}
% There is an alternative, starred, form of the \Lenv{textblock}
% environment.  In the argument to the \Lenv{textblock*} environment, the 
% block width, and the block position (but \emph{not} the
% specification of the block reference point) are given as absolute
% dimensions, rather than as numbers in units of the horizontal and
% vertical modules.  Thus
% \begin{quote}
% \begin{raggedright}
% \cmd|\begin{textblock*}{<hsize>}[<ho>,<vo>](<hpos>,<vpos>)|\\
% text...\\
% \cmd|\end{textblock*}|
% \end{raggedright}
% \end{quote}
% produces a textblock of the given size, where this time \meta{hsize},
% \meta{hpos} and \meta{vpos} are absolute dimensions, but \meta{ho}
% and \meta{vo} are pure-number offsets (that is, fractions of the
% width and height of the textblock), as above.
%
% Each \Lenv{textblock} environment takes up zero space on the page (which
% means, by the way, that it cannot detect that it's overprinting or
% being overprinted), so you can (and typically will) use several of
% the environments in a row to scatter text all over the page.
%
% This package works in two modes, relative and absolute.  In the
% first one, the default, the block-positioning parameters in the
% \Lenv{textblock} envirionment are taken to be relative to the
% current position on the page.  This will be appropriate if you are
% laying out text within a \texttt{figure} environment or the like.
% In this mode, you will typically give several \Lenv{textblock}
% environments one after the other, so that they are all relative to
% the same point.
%
% If, however, your entire 
% document is to be laid out piece by piece (which is the case in the
% canonical use of the package, to lay out a poster), then you might
% want to be more sure of where the origin is.  In this case, you make
% the package work in its absolute mode, by invoking it with
% the \Lopt{absolute} option: |\usepackage[absolute]{textpos}|.
% In this mode, all the block-positioning parameters are given
% relative to a single origin on the page.  By default, this is the
% top-left corner of the page, but you may change it with the 
% command \cmd|\textblockorigin{<hpos>}{<vpos>}|.
% Here \meta{hpos} and \meta{vpos} are dimensions such as `10mm',
% relative to the top-left corner of the paper.  You may use this
% command only if the package was invoked with the \Lopt{absolute}
% option.  See also section~\ref{absolute-newpage}.
%
% The package is compatible with the \pstyle{calc} package, so that
% you may use calc-style expressions when specifying lengths.  Thus
% \begin{quote}
% \begin{raggedright}
% |\usepackage{calc}|\\
% |\textblockorigin{56.9055pt-10mm}{0pt+1cm}|\\
% |\begin{textblock*}{10mm+14cm}(0.3cm*5,10\TPVertModule+5mm)|\\
% text\dots\\
% |\end{textblock*}|\\
% \end{raggedright}
% \end{quote}
% Note that you can only use calc-style expressions where you would
% specify a length with units, such as the width and location
% arguments of \Lenv{textblock*} or the arguments to |\textblockorigin|
% -- you can't use them when specifying a
% length in units of the horizontal and vertical modules, such as in
% the width and location arguments to the (unstarred) \Lenv{textblock}
% environment.
%
% \pstyle{Textpos} changes\marginpar{Figure and table environments}
% the behaviour of any \Lenv{figure} and \Lenv{table} environments
% \emph{within} instances of the \Lenv{textblock} environment, in such
% a way that the figure or table contents do not float away from the
% \Lenv{textblock} environment.  For the same reason, |\marginpar| is
% forbidden within a textblock.  It makes no change, however, outside
% the environment, where figures float as normal, and you are still
% able to use \pstyle{textblock} within figures, as described above.
% Within a \Lenv{textblock}, these environments do nothing
% beyond accepting the usual |\caption| command, which behaves
% correctly with respect to caption numbering and |\label| commands
% (it also respects |\@makecaption|, so you can tinker with that if
% you like that sort of thing).  There's no real need to use either
% the \Lenv{figure} or \Lenv{table} environments within a textblock --
% you don't require them to allow |\includegraphics| or \Lenv{tabular}
% to work, for example -- but many people automatically use them to
% surround graphics or tables, and also expect to use these
% environments to number figures and tables within \Lenv{textblock}
% environments; they are therefore here on a principle of least
% surprise.
%
% The support here is admittedly simple, and it is known to fail in
% the case where there are \Lenv{figure} (or \Lenv{table})
% environments both inside and outside \Lenv{textblock}s on the same
% page (the LoF is ordered incorrectly in this case, due to the
% different times that the various environments write to the
% \texttt{.lof} file).  I don't have immediate plans to fix this: the
% situation is surely sufficiently rare as not to justify the
% (potentially fragile) complication of the fix -- if you disagree,
% let me know.
%
% Since both \LaTeX's floats mechanism (that is, \Lenv{figure} and
% \Lenv{table}) and the \Lopt{absolute} mode are designed to move
% content around, we can't expect them to play together nicely.  With
% \Lopt{absolute} mode on, the contents of a \Lenv{textblock} inside a
% floating \Lenv{figure} probably isn't going to end up where you
% expect it to.  The only case I can think of where this would
% inconvenience you, is if you wanted some absolutely-positioned
% material to appear on the `next' page.  You might at first try to use
% a |\begin{figure}[p]| -- that won't work, but the following will, if
% you first load the \pstyle{afterpage} package:
% \begin{verbatim}
%  \afterpage{%
%    \newpage%
%    \begin{textblock*}{297mm}(0mm,0mm)%
%      \includegraphics{picture.png}% a full-page picture?
%    \end{textblock*}%
%    \null%
%    \newpage}
% \end{verbatim}
% This inserts a complete page, with some graphic on it, immediately
% after the end of the current page (thanks to Matthias Gloede for
% this technique).
%
% \DescribeMacro{\textblockcolour}
% The text blocks can be coloured in.  If you load the \pstyle{color}
% package, then the commands of that package, |\textcolor|,
% |\pagecolor| and the like, should work as usual.  The
% \pstyle{textpos} package adds a new command,
% |\textblockcolour|.  If you give the command
% \begin{quote}
% |\textblockcolour{|\meta{colour}|}|
% \end{quote}
% all text blocks following will have their background filled with the
% specified colour, which must be one of the standard colours or have
% been declared in a
% |\definecolor| declaration in the document preamble.  This colour
% may be overridden for individual text blocks by giving this command
% within the \Lenv{textblock} environment.  If you wish a block not to
% have any background colour, you can suppress it, again for one block
% at a time, with the command |\textblockcolour{}| inside the
% \Lenv{textblock} environment.
%
% \DescribeMacro{\textblockrulecolour}
% You can similarly change the colour of the borders around the text
% block.  If you give the command
% \begin{quote}
% |\textblockrulecolour{|\meta{colour}|}|
% \end{quote}
% then following text blocks will have their border in the given
% colour, which must again be either one of the standard ones of
% declared in the document preamble.
%
% \DescribeMacro{\textblockcolor}
% For the benefit of those who observe Webster's spelling
% reforms, |\textblockcolor| is defined as a synonym for
% |\textblockcolour|, but those who would condemn such anaemic half measures 
% \DescribeMacro{\tekstblokkulur}
% can use |\tekstblokkulur| instead.
% \DescribeMacro{\textblockrulecolor}
% \DescribeMacro{\tekstblokroolkulur}
% There are also the corresponding spelling-reform variants of
% |\textblockrulecolour|.
%
% \subsection{Package options}
% \label{packopts}
%
% There are several package options:
% \begin{description}
% \item[\Lopt{showboxes}]When you are laying things out, it can be
% useful to have the boxes drawn in for you.  This option draws a box
% fitting closely round the set text.  You can turn this on and off
% within the file using the |\TPshowboxestrue| and |\TPshowboxesfalse|
% commands.
% \item[\Lopt{noshowtext}]This suppresses the display of the text in
% each block (so it's not really usable without the \Lopt{showboxes}
% option).  The resulting box will be the correct size, but empty,
% unless the |\textblocklabel| command has been given.  This
% can be useful when you are previewing a document.
% \item[\Lopt{absolute}]If this is present, then the positions on the
% \Lenv{textblock} environment are taken to be absolute positions on
% the page.  See above for more detail, and see
% section~\ref{absolute-newpage} for the interaction with the
% |\newpage| command.
% \item[\Lopt{overlay}]When using the absolute-position mode, the
% textblocks are placed under any other text on the page.  This is
% normally what you want, but if you have page contents, and they have
% something 
% which \emph{obscures} the textblocks (for example, a block of opaque
% colour), then the positioned textboxes disappear.  In this case,
% specify the option \Lopt{overlay}, to request that the positioned
% blocks of text overlay any other page contents, rather
% than being overlaid.
% \item[\Lopt{verbose}, \Lopt{quiet}]The package writes a few messages
% to the output, describing its calculations.  These are potentially
% irritating, so you can turn them off with the \Lopt{quiet} option or
% on with the \Lopt{verbose} option.  The default is currently
% \Lopt{verbose}, but this might change in future.
% \end{description}
%
% \subsection{Package parameters}
% \begin{raggedright}
% \begin{description}
% \item[\texttt{\bslash TPHorizModule}]
% \DescribeMacro{\TPHorizModule}
% The length unit which is used for the horizontal positioning and
% size parameters of the \Lenv{textblock} environment.  Set it using
% the command \cmd|\setlength{\TPHorizModule}{<dimen>}| (or indeed
% |\addtolength|).
% The default is one sixteenth of the paper width.
% \item[\texttt{\bslash TPVertModule}]
% \DescribeMacro{\TPVertModule}
% The length unit which is used for the vertical positioning and
% size parameters of the \Lenv{textblock} environment.  Set it using
% the command \cmd|\setlength{\TPVertModule}{<dimen>}| (or |\addtolength|). 
% The default is one sixteenth of the paper height.
% \item[\texttt{\bslash TPshowboxestrue} and \texttt{\bslash TPshowboxesfalse}]
% You can control whether text blocks have the rule around them by
% using the |\TPshowboxestrue| and |\TPshowboxesfalse| commands.  The
% \Lopt{showboxes} option simply sets the initial value of this switch.
% \item[\texttt{\bslash TPboxrulesize}]
% \DescribeMacro{\TPboxrulesize}
% When you use the \Lopt{showboxes} option,
% the lines drawn are of this width.  If this too small to show up
% when you are previewing your document, or if you simply like bold
% frames and wish to make them a feature of your poster's design, you
% may adjust the size using |\setlength| or |\addtolength|.  The
% default is 0.4pt.  See also the |\textblockrulecolour| command.
% \item[\texttt{\bslash textblocklabel}]
% \DescribeMacro{\textblocklabel}
% This may be used within any \Lenv{textblock}
% environment.  It is ignored, unless the \Lopt{noshowtext} option has
% been specified, when it will be used to label the textblock it is
% inside.  Use: |\textblocklabel{Identifying text}|.
% \item[\texttt{\bslash showtextsize}]
% \DescribeMacro{\showtextsize}
% When |\textblocklabel| is being
% shown, the text appears in size |\showtextsize|, which is
% defined by default to be |\normalsize|.  If this is too
% small, you may adjust it using |\newcommand{\showtextsize}{\large}|, or
% whatever size you prefer.
% \item[\texttt{\bslash textblockorigin}]
% \DescribeMacro{\textblockorigin}
% Sets the position of the top-left of the
% printable area.  See above.
% \end{description}
% \end{raggedright}
%
% \section{Notes}
% \subsection{Suggestions: Producing large-format posters}
% 
% If you are producing a large-format poster, such as A0 size, you
% might want to use Gerlinde Kettl and Matthias Weiser's \cmd|a0poster|
% class, which painlessly deals with the miscellaneous hassles of
% printing to a large-format postscript printer.
%
% I have a collection of suggestions for producing such posters at
% \url{http://purl.org/nxg/note/posters}.
%
% The text on a large poster will typically use a very large font.  It
% can be a hassle to create (or have dvips create) these fonts, and
% they take up a good deal of space on your disk.  You might want to
% investigate the BlueSky/AMS fonts (available at CTAN), which are
% postscript versions of the Computer Modern fonts, and which can
% therefore be scaled arbitrarily.
%
% \subsection{Absolute mode and $\backslash$newpage}
% \label{absolute-newpage}
%
% You can sometimes get rather puzzling behaviour when you use
% |\newpage| in absolute mode.
%
% When using the \Lopt{absolute} option, you most typically
% have all of the text on your page inside \Lenv{textblock}
% environments.  In this case, \TeX\ does not believe that you have
% anything on the page at all, and so if you give a |\newpage| command
% to start a second sheet (perhaps you have a particularly generous
% poster space allocation at your conference, or you are filling out a
% form), \TeX\ thinks it is redundant, and ignores it, so that all
% your \Lenv{textblock} environments end up on just one page.  To work
% round this, use |\null\newpage| instead: this is enough to persuade
% \TeX\ to respect the page-break.
%
% This happens for the same reason that, also quite surprisingly, two
% |\newline| commands in a row do not produce a blank page.
%
% \subsection{Interactions}
%
% Textpos does not appear to get on terribly well with
% Prosper\marginpar{textpos \& prosper} (a 
% problem reported by Erik Van Eynde).  This is because
% Textpos in absolute mode places its text onto the page at the last
% moment before the page is shipped out, which will be \emph{after}
% Prosper has rotated the page from portrait to landscape format, so
% that the \Lenv{textblock} contents end up at the correct position on
% the portrait page, but the wrong position on the landscape page.
% This unfortunately means that Textpos in absolute mode is
% incompatible with Prosper.  But all is not lost: since Prosper
% slides start at a consistent point, you can fairly happily use Textpos in
% relative mode as long as the \Lenv{textblock} environment is the
% first thing on the slide.
%
% There's also an unfortunate interaction with the \texttt{color}
% package\marginpar{textpos \& color}.  Textpos in absolute mode, and
% the \texttt{pdftex} graphics driver, both squabble over who gets to
% redefine the |\shipout| command: using the |\pagecolor| command with
% \texttt{pdflatex} causes textpos absolute mode to behave
% strangely\footnote{See the \texttt{comp.text.tex} thread `Colour in
% a0 poster' starting 2007 April 3}.  A fix may appear here in time, but
% for the present, there are three workarounds.  The first is to place
% the |\pagecolor{...}| command before |\begin{document}|, which
% causes the redefinitions of |\shipout| to happen in a working
% order.  If this is impossible for some reason, then (as with the
% Prosper workaround above) you can use textpos not in absolute
% mode: if the textblocks are the first printable material on the
% page, then they're anchored at a fixed position, and you should be
% able to use textblocks and |\pagecolor| with \texttt{pdflatex}
% much as normal.  The final possibility is to use \texttt{latex},
% \texttt{dvips} and \texttt{ps2pdf} to produce PDF, since the
% dvips driver happens not to have this problem (thanks to Joris Vankerschaver
% for the initial report, and to Heiko Oberdiek for one of the workarounds).
%
% Gabriel Zachmann suggested having Textpos put a grid on the
% page\marginpar{page grid}, so
% that it is easier to work out \Lenv{textblock} coordinates.  I may
% yet do this, but it may not be necessary, since Rolf Niepraschk's
% \texttt{eso-pic} package can help you create this grid yourself.
% There is a vivid example of using Textpos along with Rolf's
% \texttt{eso-pic} package and the \texttt{calc} package on the
% Textpos web pages, at
% \url{http://purl.org/nxg/dist/textpos}.
%
% Finally, Robert Wenner reported a problem when using Textpos along
% with the \texttt{texdraw} package\marginpar{textpos \& texdraw}, with
% |\move(0,0)| apparently 
% making a difference when it should be a no-op.  I haven't worked out
% what's going on here.
%
% \section{Credits}
%
% Olaf Maibaum, \texttt{Olaf.Maibaum@informatik.uni-oldenburg.de},
% made an elegant improvement to an earlier version of this package,
% by producing the code which I've incorporated here as the `absolute
% mode' (I'd had something like this before, but it was \emph{very}
% kludgy).
%
% Bjoern Pedersen, \texttt{bjoern@poseidon.org.chemie.tu-muenchen.de},
% made the excellent suggestion that the horizontal and vertical
% modules should be independent, and provided code to implement this.
%
% Rolf Niepraschk, \texttt{niepraschk@ptb.de}, provided the code changes
% which made textpos compatible with the \pstyle{calc} package.
%
% Wybo Dekker, \texttt{wybo@servalys.nl}, reported a problem when
% box~255 was (erroneously) not a vbox, and passed on a fix from Hans
% Hagen.
%
% Jenny Maresh and Matthias Jerg independently suggested that it would
% be useful to specify a margin around the block of text in a
% \Lenv{textblock} environment.  That resulted in the |\TPMargin|
% command (after an unconscionably long gestation period).  Rusen Lu
% suggested that one should be able to specify the colours of the box
% borders, and that it would be useful to turn the bordering feature
% on and off within the file.
%
% Axel Sommerfeldt provided elegant code to fix incorrect
% behaviour of |\caption| within the \Lenv{figure} environment.
%
% Thanks also for bugreports and other suggestions to Jozef Bednarcik,
% Daniel Richard G, Wolfgang Fleischer, Giovanni Radilla and Robert Whittaker.
%
% If you've reported a bug or made a suggestion and I haven't credited
% you here, please do accept my apologies, and please let me know.
%
% \section{Example}
%
% Here is a short example file.
%    \begin{macrocode}
%<*example>
\documentclass{article}

\usepackage[absolute]{textpos}

\setlength{\TPHorizModule}{30mm}
\setlength{\TPVertModule}{\TPHorizModule}
\textblockorigin{10mm}{10mm} % start everything near the top-left corner
\setlength{\parindent}{0pt}

\begin{document}

\begin{textblock}{3}(0,0)
This block is 3 modules wide, and is placed with its top left corner
at the `origin' on the page.  Note that the length of the block is not
specified in the arguments -- the box will be as long as necessary to
accomodate the text inside it.  You need to examine the output of the
text to adjust the positioning of the blocks on the page.
\end{textblock}

\begin{textblock}{2}(2,1)
\textblocklabel{block two}
Here is another, slightly narrower, block, at position (2,1) on the page.
\end{textblock}

\begin{textblock}{3}[0.5,0.5](2,3)
This block is at position (2,3), but because the optional argument
[0.5,0.5] has been given, it is the centre of the block which is
located at that point, rather than the top-left corner.
\end{textblock}

\end{document}
%</example>
%    \end{macrocode}
%
% \StopEventually{}
%
% \section{Implementation}
%
%
% \subsection{Options}
%
% Allow the user to switch on display of boxes round the text.
%    \begin{macrocode}
%<*package>
\newif\ifTPshowboxes
\TPshowboxesfalse
\DeclareOption{showboxes}{\TPshowboxestrue}
%    \end{macrocode}
% \dots and switch off printing of text.
%    \begin{macrocode}
\newif\ifTP@showtext
\TP@showtexttrue
\DeclareOption{noshowtext}{\TP@showtextfalse}
%    \end{macrocode}
%
% User may declare that the positions given to the |\textblock|
% environment are to be absolute on the page, rather than relative to
% the current position.
%    \begin{macrocode}
\newif\ifTP@abspos
\TP@absposfalse
\DeclareOption{absolute}{\TP@abspostrue}
%    \end{macrocode}
%
% When using the absolute-position mode, the holdbox is placed into
% box~255 in front of the previous contents of box~255.  This is
% normally what you want, but if the page contents have something
% which \emph{obscures} the hold box (for example, a block of opaque
% colour), then the positioned textboxes disappear.  In this case,
% allow the user to specify that the holdbox is to be placed
% \emph{after} the contents of box~255, so that it overlays it rather
% than being overlayed.
% \changes{v1.1c}{1999/03/22}{Added overlay option}
%    \begin{macrocode}
\newif\ifTP@overlay
\TP@overlayfalse
\DeclareOption{overlay}{\TP@overlaytrue}
%    \end{macrocode}
%
% The package can produce some messages reporting on its progress.
% Allow these to be turned off and on explicitly.  The default is
% (currently) on.
% \changes{v1.2}{2002/04/21}{Added verbose and quiet options}
%    \begin{macrocode}
\newif\ifTP@chatter
\TP@chattertrue
\DeclareOption{quiet}{\TP@chatterfalse}
\DeclareOption{verbose}{\TP@chattertrue}
%    \end{macrocode}
%
% That's it.  Now process the options and get on with it.
%    \begin{macrocode}
\ProcessOptions
%    \end{macrocode}
%
% \subsection{Required Packages}
%
% To manipulate |\box255|, this package needs the package
% \texttt{everyshi}, which provides the command |\EveryShipout|.
%    \begin{macrocode}
\ifTP@abspos
  \RequirePackage{everyshi}
\fi
%    \end{macrocode}
%
% \subsection{Other initialisation}
%
% Handle floats.  The following definition of |\TP@xfloat| will be
% used to redefine |\@xfloat| within textblocks.  It has the same
% `interface' as |\@xfloat| -- and in particular, it sets |\@captype|,
% so that |\caption| will still work -- except that it ignores any
% placement specifiers, and doesn't put anything into the |\@currbox|.
% Thus nothing will actually float from here, and thus float out of the
% textblock.
%
% We have to open a box, and set |\@floatpenalty|, because
% |\end@float| expects to close a box; and we don't want to redefine
% |\end@float| because that would required us to redefine
% |\end@dblfloat| as well.  Redefine |\@xympar| to throw an error:
% this means that |\marginpar| is forbidden inside textblocks.  Hmm,
% it also means that it's forbidden even within a minipage -- is that
% a bad thing?
% \changes{1.6a}{2005/10/13}{remove superfluous definitions of thefigure}
% \changes{1.7c}{2007/03/29}{fix caption handling -- code from Axel Sommerfeldt}
% \changes{1.7d}{2007/03/30}{further figure fixes, building on more Axel suggestions}
%    \begin{macrocode}
\def\TP@xfloat#1[#2]{
  \par\def\@captype{#1}%
  \@floatpenalty\z@
  \color@vbox
    \normalcolor
    \vbox\bgroup
}
\def\TP@xympar{
  \PackageError{textpos}
    {You can't use \protect\marginpar\space within a textblock}
    {You're using textpos because you _don't_ want things to float
      around, yes?}}
%    \end{macrocode}
%
% \subsection{The box handling starts here}
% The text we set will be put into the box |\TP@textbox|.
%    \begin{macrocode}
\newbox\TP@textbox
%    \end{macrocode}
% When the package is invoked in `absolute' mode, the contents of
% |\TP@textbox| are not shipped out immediately, but instead put into the box
% |\TP@holdbox|, which holds the boxes until the page as a whole is
% shipped out (these additions contributed by Olaf Maibaum).
% \changes{v1.1}{1999/02/22}{Introduce holdbox, and absolute/relative modes}
%
% \TeX\ does not call the output routine if there is nothing on the
% page.  To deal with this situation, add code to the end-document
% hook to add a zero-size hbox on the page if |\TP@holdbox| is
% non-empty; the page is no longer empty, so the output routine must
% be called at some point.  The alternative is to add such an hbox at
% the end of every textblock, when in absolute mode.  That solves
% this problem, but introduces others by interfering with vertical spacing.
% (thanks to Bjoern Pedersen for diagnosing this in an old version
% of textpos).
%   \begin{macrocode}
\ifTP@abspos
  \newbox\TP@holdbox            % starts off void
  \AtEndDocument{\ifvoid\TP@holdbox \else \hbox{}\fi}
\fi
%    \end{macrocode}
% All the dimensions (except the optional argument of the textblock
% environment) are in terms of the modules |\TPHorizModule| and
% |\TPVertModule|.
% \changes{v1.1}{1999/02/22}{Distinguish horizontal and vertical modules}
%    \begin{macrocode}
\newdimen\TPHorizModule
\newdimen\TPVertModule
%    \end{macrocode}
%
% \begin{macro}{\TPMargin}
% Macro |\TPMargin| specifies the amount of space left between the
% box, as positioned by the \texttt{textblock}, and the enclosed
% text.  The argument is a dimension, which may as usual be given in
% units of |\TP*Module|.  We signal this to the rest of this package
% by making |\TP@margin| positive (we demand that the argument is
% positive).  The companion dimension |\TP@absmargin| is just the
% absolute value of |\TP@margin|, for convenience.
%    \begin{macrocode}
\newdimen\TP@margin
\TP@margin=0pt
\newdimen\TP@absmargin
\TP@absmargin=0pt
\newcommand{\TPMargin}{%
  \@ifstar\TPMargin@outer\TPMargin@inner
}
\newcommand{\TPMargin@inner}[1]{%
  \TP@margin=#1\relax
  \ifdim\TP@margin < 0pt
    \PackageError{textpos}
      {\protect\TPMargin\space must have a positive argument}
      {\protect\TPMargin\space must have a positive argument}
  \fi
  \TP@absmargin=\TP@margin
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\TPMargin*}
% Partnered to this, the |\TPMargin*| command also specifies a margin
% between the text and its enclosing box, but this time the
% \emph{text} is at the position specified by the \texttt{textblock},
% and the box, delimited either by a line or by a panel of colour,
% extends outside this position by an amount specified in the argument
% to this macro.  We signal this to the rest of this package by making
% the margin negative.
%    \begin{macrocode}
\newcommand\TPMargin@outer[1]{%
  \TP@margin=-#1\relax
  \ifdim\TP@margin > 0pt
    \PackageError{textpos}
      {\protect\TPMargin*\space must have a positive argument}
      {\protect\TPMargin*\space must have a positive argument}
  \fi
  \TP@absmargin=-\TP@margin
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\TPGrid}
% Rather than declare the modules to be specific sizes, they can be
% declared to be proportions of the paper size.  The command
% |\TPGrid{16}{10}| would declare the horizontal module to be a
% sixteenth of the paper size, and the vertical one to be a tenth of
% the paper height.  Set the textblockorigin if the optional arguments
% were provided.
% \changes{v1.1c}{1999/03/09}{Add optional argument to TPGrid}
%    \begin{macrocode}
\def\TPGrid{%
  \@ifnextchar[{\@tempswatrue\TP@Grid}{\@tempswafalse\TP@Grid[0pt,0pt]}}
\def\TP@Grid[#1,#2]#3#4{
  \setlength{\@tempdima}{#1}
  \multiply\@tempdima by 2
  \TPHorizModule=\paperwidth
  \advance\TPHorizModule by -\@tempdima
  \divide\TPHorizModule by #3
  \setlength{\@tempdima}{#2}
  \multiply\@tempdima by 2
  \TPVertModule=\paperheight
  \advance\TPVertModule by -\@tempdima
  \divide\TPVertModule by #4
  \ifTP@chatter
    \typeout{Grid set #3 x #4 = \the\TPHorizModule\space x \the\TPVertModule}%
  \fi
  \ifTP@abspos\if@tempswa \textblockorigin{#1}{#2}\fi\fi
}
%    \end{macrocode}
% \end{macro}
% And use this to initialise initialise the modules to a suitable
% default -- one sixteenth of the paper width and height.
%    \begin{macrocode}
\TPGrid{16}{16}
%    \end{macrocode}
%
% The rules round the boxes are of width |\TPboxrulesize|, and the
% label text within them is |\normalsize|.  For the colour, see
% |\textblockrulecolour|.
%    \begin{macrocode}
\newdimen\TPboxrulesize
\setlength{\TPboxrulesize}{0.4pt}
\def\showtextsize{\normalsize}
%    \end{macrocode}
%
% \begin{macro}{\textblockorigin}
% If we're producing a single page of text, it can be convenient to
% set an origin.  This command may only be used in absolute mode.
%
% First, we need two dimensions, to hold the position of the origin.
% These are relative to the top-left corner of the page, so we need to
% shift them by (1in,1in) to make them relative to the \TeX\ origin.
%    \begin{macrocode}
\ifTP@abspos
  \newdimen\TP@ox
  \newdimen\TP@oy
\fi
%    \end{macrocode}
% The |\textblockorigin| command sets the origin of the page.  It may
% only be called if the package was loaded with the \Lopt{absolute}
% option, so output an error message if that's not the case.
%    \begin{macrocode}
\def\textblockorigin#1#2{%
  \ifTP@abspos
    \TP@ox=-1in    \addtolength\TP@ox{#1}
    \TP@oy=-1in    \addtolength\TP@oy{#2}
    \ifTP@chatter\typeout{TextBlockOrigin set to #1 x #2}\fi
  \else
    \PackageError{textpos}
      {The \protect\textblockorigin\space command\MessageBreak
       may only be used if the package was given\MessageBreak
       the`absolute' option when it was invoked}
      {If you want to use the \protect\textblockorigin\space command, then
         \MessageBreak
       invoke the package with the syntax\MessageBreak
       \protect\usepackage[absolute]{textpos}}
  \fi
  }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\textblocklabel}
% When we're only displaying rules boxes, instead of the text contents
% of the blocks, it's useful to be able to identify which block is
% which.  The contents of |\textblocklabel| are ignored except when
% the \Lopt{noshowtext} option has been used.
%    \begin{macrocode}
\def\textblocklabel#1{\gdef\TP@textblocklabel{#1}}
% (should I use \@bsphack...\@esphack for this?)
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\textblockcolour}
% \changes{v1.3}{2003/06/25}{Add textblockcolour}
% \changes{v1.3a}{2003/06/25}{Fix textblockcolour so it works when {color} not loaded}
%    \begin{macrocode}
\def\textblockcolour#1{%
  \@ifundefined{color}%
    {%
      \gdef\TP@blockcolour{}% ignore argument, switch off colour blocking below
      \PackageWarning{textpos}{command textblockcolour used, but
        {color} package not loaded.\MessageBreak Colour changes ignored.}%
    }
    {%
      \def\@tempa{#1}
      \gdef\TP@blockcolour{#1}
      \ifx\TP@defaultblockcolour\@undefined
        \gdef\TP@defaultblockcolour{#1}
      \fi
    }}
\def\TP@blockcolour{}           % safe initial default
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\textblockcolor}
% Add a synonym for those who follow Webster's half-hearted spelling reforms.
%    \begin{macrocode}
\let\textblockcolor\textblockcolour
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\tekstblokkulur}
% \dots and one for the hard-core reformers, too.
%    \begin{macrocode}
\let\tekstblokkulur\textblockcolour
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\textblockrulecolour}
% We select the colour of the box rules using |\color| (since v1.7).
% However we don't want to depend on the `color' package, so if we're
% showing box rules, and so would be selecting box colours, then give
% a warning but do not fail.  Note the faking of that package's
% commands below.
% \changes{v1.7}{2006/08/24}{Add textblockrulecolour}
%    \begin{macrocode}
\def\textblockrulecolour#1{%
  \@ifundefined{color}%
    {%
      \gdef\TP@rulecolour{}% ignore argument, switch off colour blocking below
      \PackageWarning{textpos}{command textblockrulecolour used, but
        {color} package not loaded.\MessageBreak Colour changes ignored.}}%
    {%
      \def\@tempa{#1}
      \gdef\TP@rulecolour{#1}%
    }}
\def\TP@rulecolour{black}
%    \end{macrocode}
% Plus spelling-reform variants:
%    \begin{macrocode}
\let\textblockrulecolor\textblockrulecolour
\let\tekstblokroolkulur\textblockrulecolour
%    \end{macrocode}
%
% We don't want to create a dependency on the \pstyle{color} package,
% so we shouldn't fail if that package isn't loaded.  Check that here,
% and if not, create dummy no-op definitions for the package commands
% we use.
%    \begin{macrocode}
\@ifundefined{color}%
  {\gdef\color#1{}%
   \gdef\color@block#1#2#3{}%
  }{}
%
% \begin{macro}{\textblock}
% Now define the start of the textblock environment.  Read the first
% argument, and save it for the moment as |\@tempdima|.  If we are
% not in vertical mode, then issue a |\par| to make us so.  The
% environment is documented to create this paragraph break in this
% case, so we don't neet to warn the user about this.
% Then call |\TP@textblock| to read the remaining arguments and start
% off the |\vbox| the body text will be set in.
% \changes{v1.1}{1999/02/22}{Add par here, to put us back into vertical mode}
% \changes{v1.4}{2003/09/05}{Remove warning about par}
%    \begin{macrocode}
\def\textblock#1{%
  \@tempdima=#1\TPHorizModule
  \ifvmode\else
    \ifmmode
      \PackageError{textpos}
        {You cannot use textblock in maths mode}
        {You may use the textblock environment only in \MessageBreak
         vertical mode or horizontal mode (when it triggers a\MessageBreak
         new paragraph).  You cannot use it in maths mode.}    
    \else % in horizontal mode
      \par % force us back into vertical mode
    \fi
  \fi
  \@ifnextchar[{\TP@textblock}{\TP@textblock[0,0]}%] bracematch
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\textblock*}
% |\begin{textblock*}| is a variant of |\begin{textblock}| which takes 
% absolute values for its arguments.  It uses |\setlength| throughout, 
% and is therefore compatible with the \pstyle{calc} package.
% \changes{1.2a}{2002/04/28}{Added textblock* env}
%    \begin{macrocode}
\def\TP@textblockstar#1{%
  \setlength{\@tempdima}{#1}
  \ifvmode\else    
    \PackageWarning{textpos}{environment textblock* not in vertical mode.
      \MessageBreak
      Environment textblock* should not have any text\MessageBreak
      or printable material appearing before it.\MessageBreak 
      Alignment may work out wrongly.}%
    \par % force us back into vertical mode
  \fi
  \@ifnextchar[{\TP@textblock}{\TP@textblock[0,0]}%] bracematch
}
\expandafter\let\csname textblock*\endcsname\TP@textblockstar
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\TP@textblock}
% Command |\TP@textblock| saves all its arguments in a token list, for
% use in |\TP@endtextblock| later, then it starts a vbox.  Arguments~1
% and~2 are the coordinates of the reference point, as proportions of
% the box's horizontal and vertical size, and arguments~3 and~4 are
% the position of the box in units of the horizontal and vertical modules.
%    \begin{macrocode}
\newtoks\TP@tbargs
\def\TP@textblock[#1,#2](#3,#4){%
  \TP@tbargs={{#1}{#2}{#3}{#4}}%
%    \end{macrocode}
%
% Now (re)define |\@xfloat| and |\@xympar| to be the stub ones defined
% above.  Do this in all cases, even those where the |\figure|
% environment is not defined: if there's no figure environment, this
% will end up otiose rather than wrong, plus this will cope with the
% rather peculiar case where there are some floats defined
% \emph{other} than |\figure|.
%    \begin{macrocode}
  \let\@xfloat\TP@xfloat
  \let\@xympar\TP@xympar
%    \end{macrocode}
%
% Start the |\TP@textbox|, which contains the contents of the textblock.
%    \begin{macrocode}
  \setbox\TP@textbox=\vbox\bgroup
%    \end{macrocode}
% If we're showing boxes, then draw a rule here
%    \begin{macrocode}
    \ifTPshowboxes
      {\color{\TP@rulecolour}\hrule height0pt depth \TPboxrulesize }%
      \vskip-\TPboxrulesize
    \fi
%    \end{macrocode}
% Set the |\hsize| to the temporary dimension set in |\textblock|
% above, and set the other \LaTeX{} parameters to match.  If
% |\TP@margin| is positive, then the the value in |\@tempdima| is to
% be the width of the box including its left and right margins; if
% |\TP@margin| is negative, then the box should be bigger by twice the
% absolute value of this margin.  In both the cases where |\TP@margin|
% is non-zero, then (a) increase the left- and rightskip by the absolute value
% of the margin, to set the text in a block which is that much smaller
% than the enclosing box, and (b) include the same amount of vertical
% skip before and after the text block.
% \changes{v1.7b}{2007/03/21}{Fixed lists inside boxes with non-zero margins}
%    \begin{macrocode}
    \ifdim\TP@margin = 0pt
      \hsize=\@tempdima
      \textwidth\hsize \columnwidth\hsize \linewidth\hsize
    \else
      \vskip\TP@absmargin
      \@tempdimb=\@tempdima % \@tempdimb is outer box width
      \hsize=\@tempdima     % \hsize is inner box width
      \ifdim\TP@margin < 0pt
        \advance\@tempdimb by 2\TP@absmargin % bigger box
      \else
        \advance\hsize by -2\TP@absmargin    % narrower content
      \fi
      \hbox to \@tempdimb\bgroup
        \hskip\TP@absmargin\vbox\bgroup
          \textwidth\hsize \columnwidth\hsize \linewidth\hsize
    \fi
  }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\endtextblock}
% \begin{macro}{\endtextblock*} 
% We have two slight variants of the end-block code, depending on
% whether we're in a |{textblock}| or a |{textblock*}| environment.
% The |\if@tempswa| set here is tested below, in |\TP@endtextblock|.
% \changes{1.2a}{2002/04/28}{Added commonendtextblock, and starred variant}
%    \begin{macrocode}
\def\endtextblock{\global\@tempswatrue\TP@commonendtextblock}
\@namedef{endtextblock*}{\global\@tempswafalse\TP@commonendtextblock}
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\TP@commonendtextblock}
% At the end of the environment, draw the matching horizontal rule
% (if we're showing boxes),
% and finish off the vbox begun in |\TP@textblock|.  Then call
% |\TP@endtextblock| with the arguments we saved in the token register
% in |\TP@tbargs|.
%
% To manipulate the spacing around textblocks, we want to save the
% |\prevdepth| quantity in |\TP@prevdepth|.
%    \begin{macrocode}
\newdimen\TP@prevdepth
%    \end{macrocode}
%
% Now we can handle the end of the textblock.  When |\TP@margin| is
% non-zero, include a final skip which is the size of the absolute
% value of this margin.
%    \begin{macrocode}
\def\TP@commonendtextblock{%
    \ifdim\TP@margin = 0pt
      \relax
    \else
      \egroup % end of inner vbox
      \hskip\TP@absmargin
      \egroup % end of inner hbox
      \vskip \TP@absmargin
    \fi
    \ifTPshowboxes 
        \vskip-\TPboxrulesize
        {\color{\TP@rulecolour}\hrule depth 0pt height \TPboxrulesize}%
    \fi
    \egroup % end of \TP@textbox
%    \end{macrocode}
%
% Control vertical spacing: we need to avoid causing the
% insertion of more space in the case where this \texttt{textblock} is
% between paragraphs of text.  Save the |\prevdepth|, then set it to
% $-1000pt$, suppressing interline glue; then add the zero-size vbox;
% then restore |\prevdepth| to what it was before.  See the discussion
% of interline glue (ie, |\baselineskip| and |\prevdepth|) in
% Chapter~12 (p.~80) of the \TeX book (thanks to Peter M\"unster
% \texttt{<peter@univ-rennes1.fr>} for spotting that I'd got this
% wrong in the previous version).
% \changes{v1.1e}{2001/04/29}{Replace randomly-placed nointerline skip with prevdepth acrobatics, to avoid spacing misfeatures}
% \changes{v1.4}{2003/09/05}{Improve prevdepth calculations, adding TP@prevdepth}
%    \begin{macrocode}
  \TP@prevdepth=\prevdepth
  \prevdepth=-1000pt  % = \nointerlineskip
%    \end{macrocode}
% Finally, call |\TP@endtextblock| to do the work of putting the text
% on the page, directly or indirectly.
%    \begin{macrocode}
  \expandafter\TP@endtextblock\the\TP@tbargs
  }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\TP@endtextblock}
% This is where most of the calculations are. Set temporary dimensions
% a and b to be the coordinates (again, in units of the modules), and
% then adjust them by subtracting the position of the `reference point'
% given by parameters~1 and~2.  These dimensions are pure numbers,
% fractions of the width and height, respectively, of the text block.
% Parameters~3 and~4 indicate where the reference point will be
% positioned.  In the unstarred case (|\if@tempswa| true), these are
% pure numbers, indicating dimensions in units of the |\TPHorizModule| 
% and |\TPVertModule| respectively; in the starred case (|\if@tempswa| 
% false), they're dimensions.
%
% Position the box |\TP@textbox|, which was build up between
% |\TP@textblock| and |\endtextblock|, at (x,y)=|(#3,#4)|.  
% The point that is so positioned is at |(#1\wd,#2\ht)| of
% |\TP@textbox|, so that |(#1,#2)| =(0,0) means top left.
%
% If we're in the absolute-position mode, then we need to make further
% adjustments to these dimensions.
%
% Below, |\@tempdima| and |\@tempdimb| are the $x$- and
% $y$-coordinates of the framebox.
% \changes{v1.5b}{2005/06/13}{Fixed control of reference point, broken in 1.5}
%    \begin{macrocode}
\def\TP@endtextblock#1#2#3#4{%
  \if@tempswa % modular/unstarred endtextblock
    \@tempdima=#3\TPHorizModule
    \@tempdimb=#4\TPVertModule  
  \else % absolute/starred endtextblock
    \setlength{\@tempdima}{#3}
    \setlength{\@tempdimb}{#4}
  \fi
  \ifdim\TP@margin < 0pt
    \advance\@tempdima \TP@margin
    \advance\@tempdimb \TP@margin
    % #1,#2 are proportions of \TP@textbox size
    \@tempdimc=-#1\wd\TP@textbox
    \advance\@tempdima\@tempdimc
    \@tempdimc=-#2\ht\TP@textbox
    \advance\@tempdimb\@tempdimc
  \else
    % \TP@margin is positive
    % #1,#2 are proportions of \TP@framebox size = \TP@textbox+2\TP@margin
    \@tempdimc=\wd\TP@textbox
    \advance\@tempdimc 2\TP@margin
    \@tempdimc=#1\@tempdimc
    \advance\@tempdima -\@tempdimc
    \@tempdimc=\ht\TP@textbox
    \advance\@tempdimc 2\TP@margin
    \@tempdimc=#2\@tempdimc
    \advance\@tempdimb -\@tempdimc
  \fi
  \ifTP@abspos
    \advance\@tempdima by \TP@ox
    \advance\@tempdimb by \TP@oy
  \fi
%    \end{macrocode}
% Then create an hbox inside a vbox, both of size 0pt, in each case
% with the contents prefixed by a skip of the appropriate size, and
% suffixed by |\hss| or |\vss| respectively.  Put the result into the
% temporary box~0
% \changes{v1.3}{2003/06/25}{Add colouring of textblocks}
%    \begin{macrocode}
  \setbox0=\vbox to 0pt{\vskip\@tempdimb
    \hbox to 0pt{\hskip\@tempdima
    \ifx\TP@blockcolour\@empty \else
      {% defaults for TP@blockcolour mean we should never get here if
       % the {color} package is not loaded 
        \color{\TP@blockcolour}%
        \color@block{\wd\TP@textbox}{\ht\TP@textbox}{\dp\TP@textbox}%
      }%
    \fi
    \ifx\TP@defaultblockcolour\@undefined \else
      \global\let\TP@blockcolour\TP@defaultblockcolour
    \fi
    \ifTPshowboxes
      {\color{\TP@rulecolour}\vrule width \TPboxrulesize}%
      \hskip -\TPboxrulesize
    \fi
    \ifTP@showtext
      \box\TP@textbox
    \else
      \vbox to\ht\TP@textbox{%
        \ifTPshowboxes 
          {\color{\TP@rulecolour}\hrule depth 0pt height \TPboxrulesize \vskip-\TPboxrulesize}%
        \fi
        \vskip\smallskipamount
        \hbox to\wd\TP@textbox{%
          \ifx\TP@textblocklabel\undefined
            \hbox{}%
          \else
            \hskip\smallskipamount
            \fbox{\showtextsize \TP@textblocklabel}%
            \global\let\TP@textblocklabel\undefined
          \fi
          \hss
        }%
        \vss
        \ifTPshowboxes 
          \vskip -\TPboxrulesize
          {\color{\TP@rulecolour}\hrule depth 0pt height \TPboxrulesize}%
        \fi
      }%
    \fi
    \ifTPshowboxes
      \hskip -\TPboxrulesize
      {\color{\TP@rulecolour}\vrule width \TPboxrulesize}%
    \fi
    \hss}%
  \vss
  }%  end of box0
%    \end{macrocode}
% Now switch behaviour depending on whether or not we're in the
% absolute-position mode.  If we are, then add the newly-constructed
% box 0 to (the end of) the holdbox.  The order matters in some
% (many?, all?) circumstances, since this way means that later
% textblock environments go `on top of' earlier ones, which is
% generally more intuitive.  I \emph{think} this would be true for all
% drivers.  Does this have some interaction with the \Lopt{overlay}
% option, and if so, should it be coupled to that.  I haven't
% documented this one way or the other, and I think that ambiguity is
% probably useful.
%    \begin{macrocode}
  \ifTP@abspos
    \global\setbox\TP@holdbox\vbox{%
      \unvbox\TP@holdbox
      \box0
    }%
%    \end{macrocode}
% Else, place the box on the page immediately, and restore the value
% of the quantity |\prevdepth| to what it was before we started
% accumulating material for the textblock.  This will mean (a) that
% we can list several textblock environments one after another, and have them
% all offset from the same point, and (b) that we are invisible with
% respect to any |\parskip| or |\baselineskip| calculations that were
% relevant at the time we started the textblock.
%    \begin{macrocode}
  \else
    \box0
    \prevdepth=\TP@prevdepth
  \fi
  }%
%    \end{macrocode}
% \end{macro}
%
% Finally, and only if we are in the absolute-position mode, set up
% the output routine with |\EveryShipout|, and set the textblockorigin
% to the (default) upper-left corner of the paper.  Respect the
% \Lopt{overlay} option by putting the |\TP@holdbox| contents
% \emph{after} the |\@cclv| contents, putting the latter into a size-0
% box (could this cause a problem with spacing?  I don't think so, at
% this stage).
%
% Box 255 should be either a vbox or void (see \TeX Book pp.~125
% or~253), but if it is an hbox, because some package has misbehaved,
% then we ought to try not to simply collapse.  Work round this by
% testing explicitly whether box~255 is a vbox or not.
% \changes{v1.2b}{2002/07/01}{Defend against box 255 not being a vbox}
%    \begin{macrocode}
\ifTP@abspos
  \ifTP@overlay
    \EveryShipout{%
      \global\setbox\@cclv\vbox{%
        \vbox to 0pt{\ifvbox\@cclv \unvbox\@cclv \else \box\@cclv \fi \vss}%
        \unvbox\TP@holdbox      % TP@holdbox is now void
      }
    }%
  \else
    \EveryShipout{%
      \global\setbox\@cclv\vbox{%
        \unvbox\TP@holdbox
        \ifvbox\@cclv \unvbox\@cclv \else \box\@cclv \fi
      }%
    }%
  \fi
  \textblockorigin{0pt}{0pt}%
\fi
%    \end{macrocode}
% Done!
%    \begin{macrocode}
%</package>
%    \end{macrocode}
%
% \Finale
%
\endinput