textpos.sty 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369
  1. %%
  2. %% This is file `textpos.sty',
  3. %% generated with the docstrip utility.
  4. %%
  5. %% The original source files were:
  6. %%
  7. %% textpos.dtx (with options: `package')
  8. %% Textpos: absolute positioning of text on the page
  9. %% This software is copyright, 1999, 2001--2003, 2005--7 Norman Gray.
  10. %%
  11. %% This program is free software; you can redistribute it and/or
  12. %% modify it under the terms of the GNU General Public License
  13. %% as published by the Free Software Foundation; either version 2
  14. %% of the License, or (at your option) any later version.
  15. %%
  16. %% This program is distributed in the hope that it will be useful,
  17. %% but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. %% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. %% GNU General Public License for more details.
  20. %%
  21. %% You should have received a copy of the GNU General Public License
  22. %% along with this program; if not, write to the Free Software
  23. %% Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  24. %%
  25. %% Author: Norman Gray, norman@astro.gla.ac.uk.
  26. %% Department of Physics and Astronomy, University of Glasgow, UK
  27. %%
  28. %% See the file LICENCE for a copy of the GPL.
  29. %% You can also find an online copy at http://www.gnu.org/copyleft/gpl.html .
  30. %%
  31. %%% Source: $Id: textpos.dtx.in,v 1.18 2007/04/04 13:22:51 norman Exp $
  32. %%
  33. %%\def\ParseRCSDate$#1: #2 #3 ${\def\TP@Date{#2}}
  34. %%\ParseRCSDate$Date: 2007/04/04 13:22:51 $
  35. \def\filename{textpos}
  36. \def\fileversion{1.7d}
  37. \def\filedate{2007/03/30}
  38. \def\docdate{2007 March 30}
  39. \NeedsTeXFormat{LaTeX2e}
  40. \ProvidesPackage{textpos}[\filedate\space v\fileversion]
  41. \typeout{Package: `textpos' \fileversion\space<\docdate>}
  42. \newif\ifTPshowboxes
  43. \TPshowboxesfalse
  44. \DeclareOption{showboxes}{\TPshowboxestrue}
  45. \newif\ifTP@showtext
  46. \TP@showtexttrue
  47. \DeclareOption{noshowtext}{\TP@showtextfalse}
  48. \newif\ifTP@abspos
  49. \TP@absposfalse
  50. \DeclareOption{absolute}{\TP@abspostrue}
  51. \newif\ifTP@overlay
  52. \TP@overlayfalse
  53. \DeclareOption{overlay}{\TP@overlaytrue}
  54. \newif\ifTP@chatter
  55. \TP@chattertrue
  56. \DeclareOption{quiet}{\TP@chatterfalse}
  57. \DeclareOption{verbose}{\TP@chattertrue}
  58. \ProcessOptions
  59. \ifTP@abspos
  60. \RequirePackage{everyshi}
  61. \fi
  62. \def\TP@xfloat#1[#2]{
  63. \par\def\@captype{#1}%
  64. \@floatpenalty\z@
  65. \color@vbox
  66. \normalcolor
  67. \vbox\bgroup
  68. }
  69. \def\TP@xympar{
  70. \PackageError{textpos}
  71. {You can't use \protect\marginpar\space within a textblock}
  72. {You're using textpos because you _don't_ want things to float
  73. around, yes?}}
  74. \newbox\TP@textbox
  75. \ifTP@abspos
  76. \newbox\TP@holdbox % starts off void
  77. \AtEndDocument{\ifvoid\TP@holdbox \else \hbox{}\fi}
  78. \fi
  79. \newdimen\TPHorizModule
  80. \newdimen\TPVertModule
  81. \newdimen\TP@margin
  82. \TP@margin=0pt
  83. \newdimen\TP@absmargin
  84. \TP@absmargin=0pt
  85. \newcommand{\TPMargin}{%
  86. \@ifstar\TPMargin@outer\TPMargin@inner
  87. }
  88. \newcommand{\TPMargin@inner}[1]{%
  89. \TP@margin=#1\relax
  90. \ifdim\TP@margin < 0pt
  91. \PackageError{textpos}
  92. {\protect\TPMargin\space must have a positive argument}
  93. {\protect\TPMargin\space must have a positive argument}
  94. \fi
  95. \TP@absmargin=\TP@margin
  96. }
  97. \newcommand\TPMargin@outer[1]{%
  98. \TP@margin=-#1\relax
  99. \ifdim\TP@margin > 0pt
  100. \PackageError{textpos}
  101. {\protect\TPMargin*\space must have a positive argument}
  102. {\protect\TPMargin*\space must have a positive argument}
  103. \fi
  104. \TP@absmargin=-\TP@margin
  105. }
  106. \def\TPGrid{%
  107. \@ifnextchar[{\@tempswatrue\TP@Grid}{\@tempswafalse\TP@Grid[0pt,0pt]}}
  108. \def\TP@Grid[#1,#2]#3#4{
  109. \setlength{\@tempdima}{#1}
  110. \multiply\@tempdima by 2
  111. \TPHorizModule=\paperwidth
  112. \advance\TPHorizModule by -\@tempdima
  113. \divide\TPHorizModule by #3
  114. \setlength{\@tempdima}{#2}
  115. \multiply\@tempdima by 2
  116. \TPVertModule=\paperheight
  117. \advance\TPVertModule by -\@tempdima
  118. \divide\TPVertModule by #4
  119. \ifTP@chatter
  120. \typeout{Grid set #3 x #4 = \the\TPHorizModule\space x \the\TPVertModule}%
  121. \fi
  122. \ifTP@abspos\if@tempswa \textblockorigin{#1}{#2}\fi\fi
  123. }
  124. \TPGrid{16}{16}
  125. \newdimen\TPboxrulesize
  126. \setlength{\TPboxrulesize}{0.4pt}
  127. \def\showtextsize{\normalsize}
  128. \ifTP@abspos
  129. \newdimen\TP@ox
  130. \newdimen\TP@oy
  131. \fi
  132. \def\textblockorigin#1#2{%
  133. \ifTP@abspos
  134. \TP@ox=-1in \addtolength\TP@ox{#1}
  135. \TP@oy=-1in \addtolength\TP@oy{#2}
  136. \ifTP@chatter\typeout{TextBlockOrigin set to #1 x #2}\fi
  137. \else
  138. \PackageError{textpos}
  139. {The \protect\textblockorigin\space command\MessageBreak
  140. may only be used if the package was given\MessageBreak
  141. the`absolute' option when it was invoked}
  142. {If you want to use the \protect\textblockorigin\space command, then
  143. \MessageBreak
  144. invoke the package with the syntax\MessageBreak
  145. \protect\usepackage[absolute]{textpos}}
  146. \fi
  147. }
  148. \def\textblocklabel#1{\gdef\TP@textblocklabel{#1}}
  149. \def\textblockcolour#1{%
  150. \@ifundefined{color}%
  151. {%
  152. \gdef\TP@blockcolour{}% ignore argument, switch off colour blocking below
  153. \PackageWarning{textpos}{command textblockcolour used, but
  154. {color} package not loaded.\MessageBreak Colour changes ignored.}%
  155. }
  156. {%
  157. \def\@tempa{#1}
  158. \gdef\TP@blockcolour{#1}
  159. \ifx\TP@defaultblockcolour\@undefined
  160. \gdef\TP@defaultblockcolour{#1}
  161. \fi
  162. }}
  163. \def\TP@blockcolour{} % safe initial default
  164. \let\textblockcolor\textblockcolour
  165. \let\tekstblokkulur\textblockcolour
  166. \def\textblockrulecolour#1{%
  167. \@ifundefined{color}%
  168. {%
  169. \gdef\TP@rulecolour{}% ignore argument, switch off colour blocking below
  170. \PackageWarning{textpos}{command textblockrulecolour used, but
  171. {color} package not loaded.\MessageBreak Colour changes ignored.}}%
  172. {%
  173. \def\@tempa{#1}
  174. \gdef\TP@rulecolour{#1}%
  175. }}
  176. \def\TP@rulecolour{black}
  177. \let\textblockrulecolor\textblockrulecolour
  178. \let\tekstblokroolkulur\textblockrulecolour
  179. \@ifundefined{color}%
  180. {\gdef\color#1{}%
  181. \gdef\color@block#1#2#3{}%
  182. }{}
  183. \def\textblock#1{%
  184. \@tempdima=#1\TPHorizModule
  185. \ifvmode\else
  186. \ifmmode
  187. \PackageError{textpos}
  188. {You cannot use textblock in maths mode}
  189. {You may use the textblock environment only in \MessageBreak
  190. vertical mode or horizontal mode (when it triggers a\MessageBreak
  191. new paragraph). You cannot use it in maths mode.}
  192. \else % in horizontal mode
  193. \par % force us back into vertical mode
  194. \fi
  195. \fi
  196. \@ifnextchar[{\TP@textblock}{\TP@textblock[0,0]}%] bracematch
  197. }
  198. \def\TP@textblockstar#1{%
  199. \setlength{\@tempdima}{#1}
  200. \ifvmode\else
  201. \PackageWarning{textpos}{environment textblock* not in vertical mode.
  202. \MessageBreak
  203. Environment textblock* should not have any text\MessageBreak
  204. or printable material appearing before it.\MessageBreak
  205. Alignment may work out wrongly.}%
  206. \par % force us back into vertical mode
  207. \fi
  208. \@ifnextchar[{\TP@textblock}{\TP@textblock[0,0]}%] bracematch
  209. }
  210. \expandafter\let\csname textblock*\endcsname\TP@textblockstar
  211. \newtoks\TP@tbargs
  212. \def\TP@textblock[#1,#2](#3,#4){%
  213. \TP@tbargs={{#1}{#2}{#3}{#4}}%
  214. \let\@xfloat\TP@xfloat
  215. \let\@xympar\TP@xympar
  216. \setbox\TP@textbox=\vbox\bgroup
  217. \ifTPshowboxes
  218. {\color{\TP@rulecolour}\hrule height0pt depth \TPboxrulesize }%
  219. \vskip-\TPboxrulesize
  220. \fi
  221. \ifdim\TP@margin = 0pt
  222. \hsize=\@tempdima
  223. \textwidth\hsize \columnwidth\hsize \linewidth\hsize
  224. \else
  225. \vskip\TP@absmargin
  226. \@tempdimb=\@tempdima % \@tempdimb is outer box width
  227. \hsize=\@tempdima % \hsize is inner box width
  228. \ifdim\TP@margin < 0pt
  229. \advance\@tempdimb by 2\TP@absmargin % bigger box
  230. \else
  231. \advance\hsize by -2\TP@absmargin % narrower content
  232. \fi
  233. \hbox to \@tempdimb\bgroup
  234. \hskip\TP@absmargin\vbox\bgroup
  235. \textwidth\hsize \columnwidth\hsize \linewidth\hsize
  236. \fi
  237. }
  238. \def\endtextblock{\global\@tempswatrue\TP@commonendtextblock}
  239. \@namedef{endtextblock*}{\global\@tempswafalse\TP@commonendtextblock}
  240. \newdimen\TP@prevdepth
  241. \def\TP@commonendtextblock{%
  242. \ifdim\TP@margin = 0pt
  243. \relax
  244. \else
  245. \egroup % end of inner vbox
  246. \hskip\TP@absmargin
  247. \egroup % end of inner hbox
  248. \vskip \TP@absmargin
  249. \fi
  250. \ifTPshowboxes
  251. \vskip-\TPboxrulesize
  252. {\color{\TP@rulecolour}\hrule depth 0pt height \TPboxrulesize}%
  253. \fi
  254. \egroup % end of \TP@textbox
  255. \TP@prevdepth=\prevdepth
  256. \prevdepth=-1000pt % = \nointerlineskip
  257. \expandafter\TP@endtextblock\the\TP@tbargs
  258. }
  259. \def\TP@endtextblock#1#2#3#4{%
  260. \if@tempswa % modular/unstarred endtextblock
  261. \@tempdima=#3\TPHorizModule
  262. \@tempdimb=#4\TPVertModule
  263. \else % absolute/starred endtextblock
  264. \setlength{\@tempdima}{#3}
  265. \setlength{\@tempdimb}{#4}
  266. \fi
  267. \ifdim\TP@margin < 0pt
  268. \advance\@tempdima \TP@margin
  269. \advance\@tempdimb \TP@margin
  270. % #1,#2 are proportions of \TP@textbox size
  271. \@tempdimc=-#1\wd\TP@textbox
  272. \advance\@tempdima\@tempdimc
  273. \@tempdimc=-#2\ht\TP@textbox
  274. \advance\@tempdimb\@tempdimc
  275. \else
  276. % \TP@margin is positive
  277. % #1,#2 are proportions of \TP@framebox size = \TP@textbox+2\TP@margin
  278. \@tempdimc=\wd\TP@textbox
  279. \advance\@tempdimc 2\TP@margin
  280. \@tempdimc=#1\@tempdimc
  281. \advance\@tempdima -\@tempdimc
  282. \@tempdimc=\ht\TP@textbox
  283. \advance\@tempdimc 2\TP@margin
  284. \@tempdimc=#2\@tempdimc
  285. \advance\@tempdimb -\@tempdimc
  286. \fi
  287. \ifTP@abspos
  288. \advance\@tempdima by \TP@ox
  289. \advance\@tempdimb by \TP@oy
  290. \fi
  291. \setbox0=\vbox to 0pt{\vskip\@tempdimb
  292. \hbox to 0pt{\hskip\@tempdima
  293. \ifx\TP@blockcolour\@empty \else
  294. {% defaults for TP@blockcolour mean we should never get here if
  295. % the {color} package is not loaded
  296. \color{\TP@blockcolour}%
  297. \color@block{\wd\TP@textbox}{\ht\TP@textbox}{\dp\TP@textbox}%
  298. }%
  299. \fi
  300. \ifx\TP@defaultblockcolour\@undefined \else
  301. \global\let\TP@blockcolour\TP@defaultblockcolour
  302. \fi
  303. \ifTPshowboxes
  304. {\color{\TP@rulecolour}\vrule width \TPboxrulesize}%
  305. \hskip -\TPboxrulesize
  306. \fi
  307. \ifTP@showtext
  308. \box\TP@textbox
  309. \else
  310. \vbox to\ht\TP@textbox{%
  311. \ifTPshowboxes
  312. {\color{\TP@rulecolour}\hrule depth 0pt height \TPboxrulesize \vskip-\TPboxrulesize}%
  313. \fi
  314. \vskip\smallskipamount
  315. \hbox to\wd\TP@textbox{%
  316. \ifx\TP@textblocklabel\undefined
  317. \hbox{}%
  318. \else
  319. \hskip\smallskipamount
  320. \fbox{\showtextsize \TP@textblocklabel}%
  321. \global\let\TP@textblocklabel\undefined
  322. \fi
  323. \hss
  324. }%
  325. \vss
  326. \ifTPshowboxes
  327. \vskip -\TPboxrulesize
  328. {\color{\TP@rulecolour}\hrule depth 0pt height \TPboxrulesize}%
  329. \fi
  330. }%
  331. \fi
  332. \ifTPshowboxes
  333. \hskip -\TPboxrulesize
  334. {\color{\TP@rulecolour}\vrule width \TPboxrulesize}%
  335. \fi
  336. \hss}%
  337. \vss
  338. }% end of box0
  339. \ifTP@abspos
  340. \global\setbox\TP@holdbox\vbox{%
  341. \box0
  342. \unvbox\TP@holdbox
  343. }%
  344. \else
  345. \box0
  346. \prevdepth=\TP@prevdepth
  347. \fi
  348. }%
  349. \ifTP@abspos
  350. \ifTP@overlay
  351. \EveryShipout{%
  352. \global\setbox\@cclv\vbox{%
  353. \vbox to 0pt{\ifvbox\@cclv \unvbox\@cclv \else \box\@cclv \fi \vss}%
  354. \unvbox\TP@holdbox % TP@holdbox is now void
  355. }
  356. }%
  357. \else
  358. \EveryShipout{%
  359. \global\setbox\@cclv\vbox{%
  360. \unvbox\TP@holdbox
  361. \ifvbox\@cclv \unvbox\@cclv \else \box\@cclv \fi
  362. }%
  363. }%
  364. \fi
  365. \textblockorigin{0pt}{0pt}%
  366. \fi
  367. \endinput
  368. %%
  369. %% End of file `textpos.sty'.