Is there a way to check if a minipage ends with display math? Or more generally, if the line above was a displaymath?

Background: I defined a command for a minipage-environment that fixes alot of spacings and adjusts to the current position (adapts identation in theorems, if its the first minipage in the theorem etc). Everything works fine except when a Minipage ends with \[ ... \]
Then it adds the wrong spacing compared to when the same would not be in a minipage. I wrote a command to fix the spacing, however i would like to have it automatically put when the minipage ends with one of the mathenvironments (displaymath and align* is what im using mostly).

So, I would like my minipagedefinition to execute something at the end like

  % Do various Dimension calculations
  % Adjust spacing only if the last thing in the minipage was
  %   \[ ... \]
    \spacecommand %this is just \vspace*{-1em}

Is there a way to define such a \if@aftermathenv such that

\Mp{Text text text}

does not execute \spacecommand while

\Mp{Here is an equation
    \[ x = 3 \]

does execute the \spacecommand and adjust the spacing.

  • 1
    What happens if you add \par \nointerlineskip \null just before \end{minipage} in the definiton of your command?
    – GuM
    Commented Sep 1, 2018 at 15:28
  • It does not do the trick. My problem also is that i collected quite a few things manipulating with minipages and spacing in general. From beginning and ending minipages with \strut to various other changes. Thats why I think it would be easiest to get a conditional, that checks if the page was ended by displaymath.
    – Shakaja
    Commented Sep 1, 2018 at 15:36
  • I think that, in order to get meaningful answers, you should explain better the background for your question. For example, what “counts” as “something that follows the displayed equation”? Another paragraph? An explicit vertical space inserted by means of a \vspace command?
    – GuM
    Commented Sep 1, 2018 at 15:44
  • I updated the codesample and added some explanation, i hope it becomes clear now.
    – Shakaja
    Commented Sep 1, 2018 at 15:58
  • Mmh… I’m afraid there’s something fundamentally wrong with the design of your \Mp command. If you are placing a \strut (both at the beginning and) at the end of its argument, you are implicitly assuming that the command will be used only in horizontal mode, and that what is passed in the argument won’t cause TeX to exit that mode; in particular, the argument shuld not contain displayed equations by your design itself. May I suggest that you describe what you are trying to achieve with the \Mp command? Perhaps someone will suggest an approach that will prove better then yours.
    – GuM
    Commented Sep 1, 2018 at 17:28


You must log in to answer this question.

Browse other questions tagged .