0

minipage supports empty values for its optional arguments:

\begin{minipage}[c][][c]{1cm} test \end{minipage}

or

\begin{minipage}[c][\relax][c]{1cm} test \end{minipage}

but it doesn't if that empty values are passed by a macro:

\def\param{}
\begin{minipage}[c][\param][c]{1cm} test \end{minipage}

or

\def\param{\relax}
\begin{minipage}[c][\param][c]{1cm} test \end{minipage}

How can I properly define the macro, so that minipage takes an empty value?

4
  • With \let\param\relax rather than \def\param\relax (which is wrong: \def requires a braced definition, so you'd need \def\param{\relax}) Commented Jun 16, 2020 at 12:47
  • Are you sure? Try: \let\param\relax \fbox{\begin{minipage}[c][\param][c]{1cm} test \end{minipage}} \def\param{1cm} \fbox{\begin{minipage}[c][\param][c]{1cm} test \end{minipage}} (and with \def\param{\relax} you will get an error) Commented Jun 16, 2020 at 13:00
  • sorry @PhelypeOleinik, you're right. Yours may be the accepted answer.
    – e_moro
    Commented Jun 16, 2020 at 13:05
  • egreg's answer says pretty much the same, you can accept his. In short you need something that is \ifx-equal to \relax, and the way to get that is with \let\param\relax Commented Jun 16, 2020 at 13:10

1 Answer 1

1

The internal code for minipage uses the optional arguments when processing \endminipage. At a certain point, \@iiiparbox is called, which does \ifx\relax#2, where #2 is the second optional argument (or \relax if the optional argument is empty). Since no expansion is performed by \ifx, your code compares

\ifx\relax\param

which returns false, because \param is a macro expanding to \relax, not the same as \relax (assuming you gave \def\param{\relax}; or it expands to nothing, which again is not the same as being empty when the argument is absorbed if you give \def\param{}.

By the way, \def\param\relax is incorrect syntax; in the two lines in the second example you're defining \param with parameter text \relax\begin, expanding to minipage. But the intended \def\param{\relax} (that I assumed in the answer) will not work, as explained.

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .