[texhax] minipage conditional

Uwe Lueck uwe.lueck at web.de
Tue Jun 21 10:53:59 CEST 2011


"Vafa Khalighi" <vafa018 at gmail.com> wrote 21.06.2011 09:49:42:
> The minipage environment accepts b, t, and few others as the position of the minipage.
> I want \test macro return "true" if it is used inside minipage with b position
> and otherwise return "false". I do not know if there is a better way but this is what I did:
>
>
> \documentclass{article}
> \makeatletter
> \newif\if at test
> \long\def\@iiiparbox#1#2[#3]#4#5{%
>   \leavevmode
>   \@pboxswfalse
>   \setlength\@tempdima{#4}%
>   \@begin at tempboxa\vbox{\hsize\@tempdima\@parboxrestore#5\@@par}%
>     \ifx\relax#2\else
>       \setlength\@tempdimb{#2}%
>       \edef\@parboxto{to\the\@tempdimb}%
>     \fi
>     \if#1b\@testtrue\vbox%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% this is where I made \if at test true
>     \else\if #1t\vtop
>     \else\ifmmode\vcenter
>     \else\@pboxswtrue $\vcenter
>     \fi\fi\fi
>     \@parboxto{\let\hss\vss\let\unhbox\unvbox
>        \csname bm@#3\endcsname}%
>     \if at pboxsw \m at th$\fi
>   \@end at tempboxa}
> \def\test{\if at test true\else false\fi}
> \makeatother
> \begin{document}
> \begin{minipage}[b]{0.5\textwidth}
> \test
> \end{minipage}
> \end{document}
>
> But it returns "false". Why is this?

Probably because you issue \@testtrue *after* the content of the box
-- #5 -- is evaluated.

> how can I fix it? Is it a better way for doing what I want to do?

I would remove your \@testtrue and add \if#1b\@testtrue\fi
right to the left of #5 (in the replacement text).

HTH -- Uwe.



More information about the texhax mailing list