| 1 |
% \CheckSum{220} |
| 2 |
% |
| 3 |
% \iffalse meta-comment |
| 4 |
% |
| 5 |
% Copyright (C) 2005 by Stephan Hennig <[email protected]> |
| 6 |
% ------------------------------------------------------------- |
| 7 |
% |
| 8 |
% This file may be distributed and/or modified under the |
| 9 |
% conditions of the LaTeX Project Public License, either version 1.2 |
| 10 |
% of this license or (at your option) any later version. |
| 11 |
% The latest version of this license is in: |
| 12 |
% |
| 13 |
% http://www.latex-project.org/lppl.txt |
| 14 |
% |
| 15 |
% and version 1.2 or later is part of all distributions of LaTeX |
| 16 |
% version 1999/12/01 or later. |
| 17 |
% |
| 18 |
% \fi |
| 19 |
% |
| 20 |
% \iffalse |
| 21 |
%<*dtx> |
| 22 |
\ProvidesFile{mcaption.dtx} |
| 23 |
%</dtx> |
| 24 |
%<package>\ProvidesPackage{mcaption} |
| 25 |
%<*dtx|package> |
| 26 |
[2009/03/13 v3.0 Put captions into the outer document margin (SH)] |
| 27 |
%</dtx|package> |
| 28 |
%<package>\NeedsTeXFormat{LaTeX2e}[1999/12/01] |
| 29 |
% |
| 30 |
%<*driver> |
| 31 |
\documentclass{ltxdoc} |
| 32 |
\EnableCrossrefs |
| 33 |
\CodelineIndex |
| 34 |
\RecordChanges |
| 35 |
\begin{document} |
| 36 |
\DocInput{mcaption.dtx} |
| 37 |
\PrintChanges |
| 38 |
\PrintIndex |
| 39 |
\end{document} |
| 40 |
%</driver> |
| 41 |
% |
| 42 |
%<*example> |
| 43 |
\listfiles |
| 44 |
\documentclass{book} |
| 45 |
\usepackage{wrapfig} |
| 46 |
\usepackage[top]{mcaption} |
| 47 |
\usepackage[ |
| 48 |
font={footnotesize,it}, |
| 49 |
labelfont=bf, |
| 50 |
justification=raggedright] |
| 51 |
{caption}[2005/06/28] |
| 52 |
\usepackage[english]{babel} |
| 53 |
\usepackage{blindtext} |
| 54 |
\begin{document} |
| 55 |
\setlength{\margincapsep}{3\columnsep} |
| 56 |
|
| 57 |
\author{Stephan Hennig} |
| 58 |
\title{mcaption test file} |
| 59 |
\maketitle |
| 60 |
\listoffigures |
| 61 |
\listoftables |
| 62 |
|
| 63 |
\chapter{Demonstration of the mcaption package} |
| 64 |
\section{This is one-column mode} |
| 65 |
\blindtext[1] |
| 66 |
|
| 67 |
\begin{wrapfigure}{o}{5cm} |
| 68 |
\begin{margincap} |
| 69 |
\rule{5cm}{2cm} |
| 70 |
\caption{A wrapfigure caption in the outer margin.} |
| 71 |
\label{fig:wrapOneCol} |
| 72 |
\end{margincap} |
| 73 |
\end{wrapfigure} |
| 74 |
\blindtext[1] |
| 75 |
\begin{table} |
| 76 |
\begin{margincap} |
| 77 |
\centering |
| 78 |
\begin{tabular}{@{}lr@{}} |
| 79 |
foo & 7\\ |
| 80 |
bar & 21 \\ |
| 81 |
baz & 23 \\ |
| 82 |
\end{tabular} |
| 83 |
\caption{A table caption in the outer margin.} |
| 84 |
\label{tab:shorttab} |
| 85 |
\end{margincap} |
| 86 |
\end{table} |
| 87 |
|
| 88 |
\twocolumn |
| 89 |
\section{This is two-column mode} |
| 90 |
\blindtext[1] |
| 91 |
|
| 92 |
\begin{wrapfigure}{o}{2cm} |
| 93 |
\begin{margincap} |
| 94 |
\rule{2cm}{1cm} |
| 95 |
\caption[A hanging wrapfigure caption.]{Another wrapfigure caption |
| 96 |
in the outer margin. Note, we are in the outer column. And we're |
| 97 |
hanging!} |
| 98 |
\label{fig:wrapTwoCol} |
| 99 |
\end{margincap} |
| 100 |
\end{wrapfigure} |
| 101 |
\blindtext[5] |
| 102 |
\begin{figure*} |
| 103 |
\begin{margincap} |
| 104 |
\centering |
| 105 |
\rule{10cm}{2cm} |
| 106 |
\caption{A figure caption in the outer margin.} |
| 107 |
\label{fig:figure*} |
| 108 |
\end{margincap} |
| 109 |
\end{figure*} |
| 110 |
|
| 111 |
Let's reference all figures and tables: |
| 112 |
|
| 113 |
\newcommand*{\pref}[1]{\ref{#1} & \pageref{#1}} |
| 114 |
\begin{tabular}{ll} |
| 115 |
float & page\\\hline |
| 116 |
figure~\pref{fig:wrapOneCol}\\ |
| 117 |
table~\pref{tab:shorttab}\\ |
| 118 |
figure~\pref{fig:wrapTwoCol}\\ |
| 119 |
figure~\pref{fig:figure*}\\ |
| 120 |
\end{tabular} |
| 121 |
\end{document} |
| 122 |
%</example> |
| 123 |
% \fi |
| 124 |
% |
| 125 |
% \CharacterTable |
| 126 |
% {Upper-case \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z |
| 127 |
% Lower-case \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z |
| 128 |
% Digits \0\1\2\3\4\5\6\7\8\9 |
| 129 |
% Exclamation \! Double quote \" Hash (number) \# |
| 130 |
% Dollar \$ Percent \% Ampersand \& |
| 131 |
% Acute accent \' Left paren \( Right paren \) |
| 132 |
% Asterisk \* Plus \+ Comma \, |
| 133 |
% Minus \- Point \. Solidus \/ |
| 134 |
% Colon \: Semicolon \; Less than \< |
| 135 |
% Equals \= Greater than \> Question mark \? |
| 136 |
% Commercial at \@ Left bracket \[ Backslash \\ |
| 137 |
% Right bracket \] Circumflex \^ Underscore \_ |
| 138 |
% Grave accent \` Left brace \{ Vertical bar \| |
| 139 |
% Right brace \} Tilde \~} |
| 140 |
% |
| 141 |
% |
| 142 |
% \GetFileInfo{mcaption.dtx} |
| 143 |
% |
| 144 |
% |
| 145 |
% \title{The \textsf{mcaption} package\thanks{This document corresponds |
| 146 |
% to \textsf{mcaption}~\fileversion, dated \filedate.}} |
| 147 |
% \author{Stephan Hennig\\ \texttt{[email protected]}} |
| 148 |
% |
| 149 |
% \maketitle |
| 150 |
% |
| 151 |
% \begin{abstract} |
| 152 |
% This package provides a |margincap| environment for putting captions |
| 153 |
% into the outer document margin with either a top or bottom |
| 154 |
% alignment. |
| 155 |
% \end{abstract} |
| 156 |
% |
| 157 |
% |
| 158 |
% \section{Package options}\label{sec:options} |
| 159 |
% |
| 160 |
% The \textsf{mcaption} package provides the following options: |
| 161 |
% |
| 162 |
% \smallskip |
| 163 |
% \begin{tabular}{lll} |
| 164 |
% option & brief description & page\\\hline |
| 165 |
% |bottom| & vertical caption alignment & \pageref{sec:alignv}\\ |
| 166 |
% |top| & vertical caption alignment & \pageref{sec:alignv}\\ |
| 167 |
% |v2.2| & compatibility option & \pageref{sec:usage}\\ |
| 168 |
% \end{tabular} |
| 169 |
% |
| 170 |
% |
| 171 |
% \section{Usage}\label{sec:usage} |
| 172 |
% |
| 173 |
% The |margincap|\DescribeEnv{margincap}\ environment places its |
| 174 |
% contents into a box whose width matches the current line witdh and |
| 175 |
% attaches a caption (with an optional label) next to the box in the |
| 176 |
% outer margin. Caption text and the label are taken from |\caption| |
| 177 |
% and |\label| commands within the environment. A typical use-case is |
| 178 |
% to put the |margincap| environment into a float, such as a |figure| or |
| 179 |
% |tabular| environment: |
| 180 |
% |
| 181 |
% \begin{verbatim} |
| 182 |
%\begin{figure} |
| 183 |
% \begin{margincap} |
| 184 |
% \centering |
| 185 |
% \includegraphics{picture} |
| 186 |
% \caption[short caption text]{long caption text} |
| 187 |
% \label{fig:pic} |
| 188 |
% \end{margincap} |
| 189 |
%\end{figure} |
| 190 |
% \end{verbatim} |
| 191 |
% |
| 192 |
% The |margincap| environment also works with the |
| 193 |
% |wrapfigure|\DescribeEnv{wrapfigure}\ environment provided by the |
| 194 |
% |wrapfig| package. Note, wrapped figures or tables have to appear in |
| 195 |
% the outer margin, \emph{i.\,e.}, parameters `o' or `O' have to be |
| 196 |
% applied to the |wrapfigure| environment. This even works in |
| 197 |
% two-column mode. See file |example.tex| for an example. |
| 198 |
% |
| 199 |
% Up to \textsf{mcaption}~v2.2\marginpar{\raggedleft\fbox{v2.2}} the |
| 200 |
% |margincap| environment had a different syntax. Macros |\caption| and |
| 201 |
% |\label| haven't been recognized inside the environment. Instead, |
| 202 |
% short and long caption texts had to be given as optional and mandatory |
| 203 |
% arguments to the |margincap| environment. To apply a label to a |
| 204 |
% |margincap| environment, the |\label| command had to passed as part of |
| 205 |
% the long caption text. The \textsf{mcaption} package provides a |
| 206 |
% compatibility option |v2.2|\marginpar{\raggedleft |v2.2|} that enables |
| 207 |
% the old behaviour. This option is disabled by default. |
| 208 |
% |
| 209 |
% |
| 210 |
% \section{Caption Format} |
| 211 |
% |
| 212 |
% \subsection{Vertical alignment}\label{sec:alignv} |
| 213 |
% Vertical alignment of margin captions can be controlled by package |
| 214 |
% options |top|\marginpar{\raggedleft |top|} or |
| 215 |
% |bottom|\marginpar{\raggedleft |bottom|}. |
| 216 |
% |
| 217 |
% Option |top| aligns the top-most line of the caption to the top of the |
| 218 |
% |margincap| environment's contents (an image, tabular, \emph{etc.}) |
| 219 |
% Similarly, option |bottom| aligns the bottom-most line of the caption |
| 220 |
% to the bottom of the |margincap| environment's contents. In case a |
| 221 |
% caption has a larger height or depth than a figure, it will hang or |
| 222 |
% grow beneath the running text. Option |bottom| is the default. |
| 223 |
% |
| 224 |
% Up to \textsf{mcaption}~v2.2\marginpar{\raggedleft\fbox{v2.2}}, the |
| 225 |
% vertical alignment of captions required some user-interaction. For |
| 226 |
% tabulars, the baseline alignment had to match that of the caption. |
| 227 |
% For that reason a macro |
| 228 |
% |\margincapalign|\DescribeMacro{\margincapalign}\ had been provided |
| 229 |
% that had to be passed as an alignment specifier to all tabular |
| 230 |
% declarations. Newer versions of \textsf{mcaption} don't need this |
| 231 |
% alignment specifier. For backwards compatibility macro |
| 232 |
% |\margincapalign| is still provided, but it's use is deprecated. |
| 233 |
% Legacy documents, that use |\margincapalign| in tabular declarations, |
| 234 |
% should still compile as soon as \textsf{mcaption} is loaded with |
| 235 |
% package option |v2.2| (see section~\ref{sec:usage}). |
| 236 |
% |
| 237 |
% \subsection{Horizontal alignment} |
| 238 |
% Horizontal spacing between a |margincap| environment's contents and |
| 239 |
% the caption can be adjusted by the length |
| 240 |
% |\margincapsep|\DescribeMacro{\margincapsep}{}. This has to be done |
| 241 |
% after |\begin{document}| or via |\AtBeginDocument| in the preamble. |
| 242 |
% Since changing |\margincapsep| will affect all further |margincap| |
| 243 |
% environments, the author suggests one document wide setting to get a |
| 244 |
% consistent look throughout the document. Default value is |
| 245 |
% |\marginparsep|. |
| 246 |
% |
| 247 |
% \subsection{Further tweaks} |
| 248 |
% To get visually pleasing results you should provide wide enough outer |
| 249 |
% margins. To further smoothen line breaking consider using a smaller |
| 250 |
% caption font and setting captions ragged. The author suggests using |
| 251 |
% the \textsf{caption} package to format captions. \emph{E.\,g.}, |
| 252 |
% issuing the following line in the document preamble |
| 253 |
% |
| 254 |
% \begin{verbatim} |
| 255 |
%\usepackage[font=footnotesize,justification=raggedright]{caption} |
| 256 |
% \end{verbatim} |
| 257 |
% will typeset all further captions at a smaller font size and flush |
| 258 |
% left. The |RaggedRight| option might be useful here, too, to allow |
| 259 |
% for hyphenation inside ragged text. |
| 260 |
% |
| 261 |
% |
| 262 |
% \section{Known Problems}\label{sec:problems} |
| 263 |
% |
| 264 |
% \begin{enumerate} |
| 265 |
% |
| 266 |
% \item Captions may appear in the wrong margin, sometimes. Running |
| 267 |
% \LaTeX\ twice should solve that problem. \emph{Background:} For |
| 268 |
% robustness, \textsf{mcaption} relies on the \textsf{changepage} |
| 269 |
% package with option |strict| to detect left- and right-hand pages. |
| 270 |
% This requires two \LaTeX-passes. The behaviour can be changed with |
| 271 |
% macro |\easypagecheck| (see package |changepage|). |
| 272 |
% |
| 273 |
% \item Captions are positioned slightly too high. This is because |
| 274 |
% |margincap| doesn't reliably know the contents' exact bottom-most |
| 275 |
% base line. Additional artificial zero height lines are used to |
| 276 |
% align environment contents and caption text. For that reason, the |
| 277 |
% true depth of both are not taken into account. \emph{Todo:} Provide |
| 278 |
% means for vertical fine-tuning of captions. |
| 279 |
% |
| 280 |
% \item When using the |wrapfig| package the auto sizing feature of the |
| 281 |
% |wrapfigure| environment won't work when putting a |margincap| |
| 282 |
% environment in. You'll have to specify the width of a |wrapfigure| |
| 283 |
% manually. |
| 284 |
% \end{enumerate} |
| 285 |
% |
| 286 |
% |
| 287 |
% \section{Bugs} |
| 288 |
% |
| 289 |
% If you find bugs, feel free to contact me at |
| 290 |
% \texttt{[email protected]}. |
| 291 |
% |
| 292 |
% |
| 293 |
% \DoNotIndex{\begin,\end,\def,\RequirePackage,\else,\fi,\equal,\relax} |
| 294 |
% |
| 295 |
% |
| 296 |
% \StopEventually{\PrintChanges} |
| 297 |
% |
| 298 |
% |
| 299 |
% \changes{v2.0}{2005/09/20}{Prepared .dtx package.} |
| 300 |
% |
| 301 |
% |
| 302 |
% \iffalse |
| 303 |
%<*package> |
| 304 |
% \fi |
| 305 |
% \section{Implementation} |
| 306 |
% |
| 307 |
% \changes{v3.0}{2009/03/07}{Complete revision of vertical alignment |
| 308 |
% mechanism.} |
| 309 |
% |
| 310 |
% Make sure the |changepage| package is loaded. |
| 311 |
% \changes{v3.0}{2009/03/12}{Replace package \textsf{chngpage} by |
| 312 |
% newer \textsf{changepage}.} |
| 313 |
% \begin{macrocode} |
| 314 |
\RequirePackage[strict]{changepage} |
| 315 |
% \end{macrocode} |
| 316 |
% |
| 317 |
% \begin{macro}{\mcaption@alignv} |
| 318 |
% This macro is used by options |bottom| and |top|. |
| 319 |
% \begin{macrocode} |
| 320 |
\newcommand*{\mcaption@alignv}{} |
| 321 |
% \end{macrocode} |
| 322 |
% \end{macro} |
| 323 |
% |
| 324 |
% Declare options |bottom| and |top| to determine vertical alignment of |
| 325 |
% a caption. Default package option is |bottom|. |
| 326 |
% \changes{v2.2}{2005/09/29}{New package options `bottom' and `top'.} |
| 327 |
% \begin{macrocode} |
| 328 |
\DeclareOption{top}{\renewcommand*{\mcaption@alignv}{t}} |
| 329 |
\DeclareOption{bottom}{\renewcommand*{\mcaption@alignv}{b}} |
| 330 |
\ExecuteOptions{bottom} |
| 331 |
% \end{macrocode} |
| 332 |
% |
| 333 |
% Declare compatibility option |v2.2|, that restores the behaviour of |
| 334 |
% \textsf{mcaption}~v2.2 for the |margincap| environment. |
| 335 |
% \changes{v3.0}{2009/03/10}{New package option `v2.2'.} |
| 336 |
% \begin{macrocode} |
| 337 |
\DeclareOption{v2.2}{% |
| 338 |
\AtEndOfPackage{% |
| 339 |
% \end{macrocode} |
| 340 |
% |
| 341 |
% Activate |margincap| with optional and mandatory caption argument. |
| 342 |
% \begin{macrocode} |
| 343 |
\let\margincap\mcaption@mcIIdotII% |
| 344 |
\let\endmargincap\endmcaption@mcIIdotII% |
| 345 |
% \end{macrocode} |
| 346 |
% |
| 347 |
% \begin{macro}{\margincapalign} |
| 348 |
% Macro |\margincapalign| is deprecated (cf. macro |
| 349 |
% |\mcaption@alignv|). It is only provided for backwards |
| 350 |
% compatibility. |
| 351 |
% \changes{v3.0}{2009/03/08}{Deprecated.} |
| 352 |
% \begin{macrocode} |
| 353 |
\newcommand*{\margincapalign}{\mcaption@alignv} |
| 354 |
% \end{macrocode} |
| 355 |
% \end{macro} |
| 356 |
% |
| 357 |
% \begin{macrocode} |
| 358 |
}% |
| 359 |
}% |
| 360 |
% \end{macrocode} |
| 361 |
% |
| 362 |
% Process the options. |
| 363 |
% \begin{macrocode} |
| 364 |
\ProcessOptions\relax |
| 365 |
% \end{macrocode} |
| 366 |
% |
| 367 |
% \begin{macro}{\margincapsep} |
| 368 |
% Length |\margincapsep| determines the horizontal distance between |
| 369 |
% contents and caption and can be adjusted by the user. This length |
| 370 |
% has to be set only after |\begin{document}| and equals |
| 371 |
% |\marginparsep| by default. |
| 372 |
% \begin{macrocode} |
| 373 |
\newlength{\margincapsep} |
| 374 |
\AtBeginDocument{% |
| 375 |
\setlength{\margincapsep}{\marginparsep}% |
| 376 |
} |
| 377 |
% \end{macrocode} |
| 378 |
% \end{macro} |
| 379 |
% |
| 380 |
% Declare macros for storing long and short caption text and a flag. |
| 381 |
% \begin{macrocode} |
| 382 |
\newcommand*{\mcaption@CaptionLong}{} |
| 383 |
\newcommand*{\mcaption@CaptionShort}{} |
| 384 |
\newcommand*{\mcaption@CaptionFlag}{} |
| 385 |
% \end{macrocode} |
| 386 |
% |
| 387 |
% Declare macros for storing a label and a flag. |
| 388 |
% \begin{macrocode} |
| 389 |
\newcommand*{\mcaption@Label}{} |
| 390 |
\newcommand*{\mcaption@LabelFlag}{} |
| 391 |
% \end{macrocode} |
| 392 |
% |
| 393 |
% Declare boxes to store the contents and caption of a |margincap| |
| 394 |
% environment. |
| 395 |
% \begin{macrocode} |
| 396 |
\newsavebox{\mcaption@ObjectBox} |
| 397 |
\newsavebox{\mcaption@CaptionBox} |
| 398 |
% \end{macrocode} |
| 399 |
% |
| 400 |
% |
| 401 |
% \begin{environment}{mcaption@mcIIdotII} |
| 402 |
% Declare a template for the traditional |margincap| environment as of |
| 403 |
% \textsf{mcaption}~v2.2, that takes an optional and a mandatory |
| 404 |
% caption text argument, \emph{cf.} environment |mcaption@mcIIIdot|. |
| 405 |
% \changes{v2.1}{2005/09/29}{Now works with standard classes.} |
| 406 |
% \begin{macrocode} |
| 407 |
\newenvironment{mcaption@mcIIdotII}[2][\mcaption@DefaultOpt]{% |
| 408 |
% \end{macrocode} |
| 409 |
% |
| 410 |
% Call |\caption| with or without optional argument. Trick taken from |
| 411 |
% UK-\TeX-FAQ, question 286: `Optional arguments like |\section|'. |
| 412 |
% \begin{macrocode} |
| 413 |
\def\mcaption@DefaultOpt{#2}% |
| 414 |
% \end{macrocode} |
| 415 |
% |
| 416 |
% Store optional and mandatory caption arguments for later processing. |
| 417 |
% Flag a caption without label. |
| 418 |
% \changes{v3.0}{2009/03/10}{Delay caption handling.} |
| 419 |
% \begin{macrocode} |
| 420 |
\def\mcaption@CaptionShort{#1}% |
| 421 |
\def\mcaption@CaptionLong{#2}% |
| 422 |
\gdef\mcaption@CaptionFlag{t}% |
| 423 |
\gdef\mcaption@LabelFlag{f}% |
| 424 |
% \end{macrocode} |
| 425 |
% |
| 426 |
% Collect environment contents in a box |\mcaption@ObjectBox| of width |
| 427 |
% |\linewidth|. |
| 428 |
% \begin{macrocode} |
| 429 |
\begin{lrbox}{\mcaption@ObjectBox}% |
| 430 |
\begin{minipage}{\linewidth}% |
| 431 |
}{% |
| 432 |
\end{minipage}% |
| 433 |
\end{lrbox}% |
| 434 |
% \end{macrocode} |
| 435 |
% |
| 436 |
% Call the working macros. |
| 437 |
% \begin{macrocode} |
| 438 |
\mcaption@align@boxes% |
| 439 |
\mcaption@output@boxes% |
| 440 |
% \end{macrocode} |
| 441 |
% |
| 442 |
% We're done. |
| 443 |
% \begin{macrocode} |
| 444 |
}% |
| 445 |
% \end{macrocode} |
| 446 |
% \end{environment} |
| 447 |
% |
| 448 |
% |
| 449 |
% \begin{environment}{mcaption@mcIIIdot} |
| 450 |
% Declare a template for the new |margincap| environment as of |
| 451 |
% \textsf{mcaption}~v3.0, that accepts |\caption| and |\label| |
| 452 |
% arguments inside the environment, \emph{cf.} environment |
| 453 |
% |mcaption@mcIIdotII|. |
| 454 |
% \changes{v3.0}{2009/03/10}{Recognize \texttt{\textbackslash caption} |
| 455 |
% and \texttt{\textbackslash label} commands.} |
| 456 |
% \begin{macrocode} |
| 457 |
\newenvironment{mcaption@mcIIIdot}{% |
| 458 |
% \end{macrocode} |
| 459 |
% |
| 460 |
% Replace |\caption| and |\label| commands by custom variants and unset |
| 461 |
% flags. |
| 462 |
% \begin{macrocode} |
| 463 |
\let\mcaption@origcaption\caption% |
| 464 |
\let\caption\mcaption@caption% |
| 465 |
\gdef\mcaption@CaptionFlag{f}% |
| 466 |
\let\mcaption@origlabel\label% |
| 467 |
\let\label\mcaption@label% |
| 468 |
\gdef\mcaption@LabelFlag{f}% |
| 469 |
% \end{macrocode} |
| 470 |
% |
| 471 |
% Collect environment contents in a box |\mcaption@ObjectBox| of width |
| 472 |
% |\linewidth|. |
| 473 |
% \begin{macrocode} |
| 474 |
\begin{lrbox}{\mcaption@ObjectBox}% |
| 475 |
\begin{minipage}{\linewidth}% |
| 476 |
}{% |
| 477 |
\end{minipage}% |
| 478 |
\end{lrbox}% |
| 479 |
% \end{macrocode} |
| 480 |
% |
| 481 |
% Restore original |\caption| and |\label| definitions. |
| 482 |
% \begin{macrocode} |
| 483 |
\let\caption\mcaption@origcaption% |
| 484 |
\let\label\mcaption@origlabel% |
| 485 |
% \end{macrocode} |
| 486 |
% |
| 487 |
% Call the working macros. |
| 488 |
% \begin{macrocode} |
| 489 |
\mcaption@align@boxes% |
| 490 |
\mcaption@output@boxes% |
| 491 |
% \end{macrocode} |
| 492 |
% |
| 493 |
% We're done. |
| 494 |
% \begin{macrocode} |
| 495 |
}% |
| 496 |
% \end{macrocode} |
| 497 |
% \end{environment} |
| 498 |
% |
| 499 |
% |
| 500 |
% \begin{environment}{margincap} |
| 501 |
% Provide the |margincap| environment. |
| 502 |
% \begin{macrocode} |
| 503 |
\newenvironment{margincap}{}{}% |
| 504 |
% \end{macrocode} |
| 505 |
% |
| 506 |
% Activate the new behaviour for the |margincap| environment. |
| 507 |
% \begin{macrocode} |
| 508 |
\let\margincap\mcaption@mcIIIdot% |
| 509 |
\let\endmargincap\endmcaption@mcIIIdot% |
| 510 |
% \end{macrocode} |
| 511 |
% \end{environment} |
| 512 |
% |
| 513 |
% |
| 514 |
% Define auxillary macros and environments. |
| 515 |
% |
| 516 |
% These macros are used for saving the original |\caption| and |\label| |
| 517 |
% definitions. |
| 518 |
% \begin{macrocode} |
| 519 |
\newcommand*{\mcaption@origcaption}{} |
| 520 |
\newcommand*{\mcaption@origlabel}{} |
| 521 |
% \end{macrocode} |
| 522 |
% |
| 523 |
% Declare an auxillary macro for storing the \emph{unexpanded} optional |
| 524 |
% |\caption| argument. |
| 525 |
% \begin{macrocode} |
| 526 |
\newcommand*{\mcaption@DefaultOpt}{} |
| 527 |
% \end{macrocode} |
| 528 |
% |
| 529 |
% \begin{macro}{\mcaption@caption} |
| 530 |
% This |\caption| replacement macro just stores its arguments in |
| 531 |
% |\mcaption@CaptionShort| and |\mcaption@CaptionLong| for later |
| 532 |
% reference and sets a flag. |
| 533 |
% \begin{macrocode} |
| 534 |
\newcommand*{\mcaption@caption}[2][\mcaption@DefaultOpt]{% |
| 535 |
\gdef\mcaption@DefaultOpt{#2}% |
| 536 |
\gdef\mcaption@CaptionShort{#1}% |
| 537 |
\gdef\mcaption@CaptionLong{#2}% |
| 538 |
\gdef\mcaption@CaptionFlag{t}% |
| 539 |
\ignorespaces |
| 540 |
}% |
| 541 |
% \end{macrocode} |
| 542 |
% \end{macro} |
| 543 |
% |
| 544 |
% \begin{macro}{\mcaption@label} |
| 545 |
% This |\label| replacement macro just stores its arguments in |
| 546 |
% |\mcaption@Label| for later reference and sets a flag. |
| 547 |
% \begin{macrocode} |
| 548 |
\newcommand*{\mcaption@label}[1]{% |
| 549 |
\gdef\mcaption@Label{#1}% |
| 550 |
\gdef\mcaption@LabelFlag{t}% |
| 551 |
\ignorespaces |
| 552 |
}% |
| 553 |
% \end{macrocode} |
| 554 |
% \end{macro} |
| 555 |
% |
| 556 |
% \begin{macro}{\mcaption@align@boxes} |
| 557 |
% This macro prepares and aligns contents and caption boxes. |
| 558 |
% \begin{macrocode} |
| 559 |
\newcommand*{\mcaption@align@boxes}{% |
| 560 |
% \end{macrocode} |
| 561 |
% |
| 562 |
% If the user issued a |\caption| command, put the caption text into box |
| 563 |
% |\mcaption@CaptionBox|. Else prepare an empty box. |
| 564 |
% \changes{v3.0}{2009/03/07}{Use temporary \LaTeX\ length.} |
| 565 |
% \begin{macrocode} |
| 566 |
\begin{lrbox}{\mcaption@CaptionBox}% |
| 567 |
\setlength{\@tempdima}{\marginparwidth}% |
| 568 |
\addtolength{\@tempdima}{\marginparsep}% |
| 569 |
\addtolength{\@tempdima}{-\margincapsep}% |
| 570 |
\begin{minipage}{\@tempdima}% |
| 571 |
\if\mcaption@CaptionFlag t% |
| 572 |
\setlength{\abovecaptionskip}{0pt}% |
| 573 |
\setlength{\belowcaptionskip}{0pt}% |
| 574 |
\caption[\mcaption@CaptionShort]{\strut\mcaption@CaptionLong\strut}% |
| 575 |
\fi% |
| 576 |
\if\mcaption@LabelFlag t% |
| 577 |
\label{\mcaption@Label}% |
| 578 |
\fi% |
| 579 |
\end{minipage}% |
| 580 |
\end{lrbox}% |
| 581 |
% \end{macrocode} |
| 582 |
% |
| 583 |
% Wrap contents into zero height top and bottom lines to get the desired |
| 584 |
% reference point. Then use |\vtop| or |\vbox| for aligning boxes. |
| 585 |
% \begin{macrocode} |
| 586 |
\sbox{\mcaption@ObjectBox}{% |
| 587 |
\if\mcaption@alignv t\vtop |
| 588 |
\else\vbox |
| 589 |
\fi |
| 590 |
{% |
| 591 |
\vskip0pt% |
| 592 |
\hbox{\usebox{\mcaption@ObjectBox}}% |
| 593 |
\vskip0pt% |
| 594 |
}% |
| 595 |
}% |
| 596 |
\sbox{\mcaption@CaptionBox}{% |
| 597 |
\if\mcaption@alignv t\vtop |
| 598 |
\else\vbox |
| 599 |
\fi |
| 600 |
{% |
| 601 |
\vskip0pt% |
| 602 |
\hbox{\usebox{\mcaption@CaptionBox}}% |
| 603 |
\vskip0pt% |
| 604 |
}% |
| 605 |
}% |
| 606 |
}% |
| 607 |
% \end{macrocode} |
| 608 |
% \end{macro} |
| 609 |
% |
| 610 |
% |
| 611 |
% \begin{macro}{\mcaption@output@oddpage} |
| 612 |
% This macro first outputs the contents and then the caption box. |
| 613 |
% \begin{macrocode} |
| 614 |
\newcommand*{\mcaption@output@oddpage}{% |
| 615 |
\makebox[\linewidth][l]{% |
| 616 |
\usebox{\mcaption@ObjectBox}% |
| 617 |
\hspace*{\margincapsep}% |
| 618 |
\smash{\usebox{\mcaption@CaptionBox}}% |
| 619 |
}% |
| 620 |
}% |
| 621 |
% \end{macrocode} |
| 622 |
% \end{macro} |
| 623 |
% |
| 624 |
% \begin{macro}{\mcaption@output@evenpage} |
| 625 |
% This macro first outputs the caption and then the contents box. |
| 626 |
% \begin{macrocode} |
| 627 |
\newcommand*{\mcaption@output@evenpage}{% |
| 628 |
\makebox[\linewidth][r]{% |
| 629 |
\smash{\usebox{\mcaption@CaptionBox}}% |
| 630 |
\hspace*{\margincapsep}% |
| 631 |
\usebox{\mcaption@ObjectBox}% |
| 632 |
}% |
| 633 |
}% |
| 634 |
% \end{macrocode} |
| 635 |
% \end{macro} |
| 636 |
% |
| 637 |
|
| 638 |
% \begin{macro}{\mcaption@output@boxes} |
| 639 |
% This macro outputs contents and caption boxes in the correct order. |
| 640 |
% \begin{macrocode} |
| 641 |
\newcommand*{\mcaption@output@boxes}{% |
| 642 |
% \end{macrocode} |
| 643 |
% |
| 644 |
% In two-sided documents check for odd and even pages. In one-sided |
| 645 |
% documents treat every page as an odd page. |
| 646 |
% \changes{v2.2}{2005/09/29}{Fixed: In one-sided documents captions were |
| 647 |
% put into the wrong margin.} |
| 648 |
% \changes{v3.0}{2009/03/12}{Fixed: In one-sided documents |
| 649 |
% \textsf{chngpage/changepage}'s even/odd page detection was subtly |
| 650 |
% broken by \textsf{mcaption}.} |
| 651 |
% \begin{macrocode} |
| 652 |
\if@twoside% |
| 653 |
\checkoddpage% |
| 654 |
\ifoddpage% |
| 655 |
\mcaption@output@oddpage% |
| 656 |
\else% |
| 657 |
\mcaption@output@evenpage% |
| 658 |
\fi% |
| 659 |
\else% |
| 660 |
\mcaption@output@oddpage% |
| 661 |
\fi% |
| 662 |
}% |
| 663 |
% \end{macrocode} |
| 664 |
% \end{macro} |
| 665 |
% |
| 666 |
% \iffalse |
| 667 |
%</package> |
| 668 |
% \fi |
| 669 |
% \Finale |