0

Related to Can I detect whether LaTeX is in vertical mode?

\documentclass{article}

\newcommand{\wm}{% \ifinner INNER \else OUTER\fi MODE }

\newcommand{\mm}{% (trying margin par)\ifinner(no margin par)\else\marginpar{yes marginpar}\fi }

\begin{document}

\begin{table} \caption{Table} \wm ... \mm


\end{table}

\bigskip

Text: \wm

MPAR: \mm

\end{document}

This informs me that my float is lost. the output is

output

so how do I write a macro that sets a marginpar only when it is allowed to do so, and does not have the little side effects here (i.e., should have said "(no margin par)" and not give a lost float error)?

PS: When it works, \marginpar trick: not considered as float is pretty neat.

ivo Welch
  • 3,766

1 Answers1

2

Inside your table \wm is executed in vertical mode at the start of the float box, but as that's a box not the main vertical list that is inner v mode but you then typeset INNER MODE ... (trying margin par) which starts a paragraph, so you are in outer h mode so the test in \mn is false so it attempts a marginpar which fails.

You want to test for being in outer h mode in a paragraph that was started from outer v mode for which there isn't a direct test. You would probably need to keep track of paragraph starts "by hand" throughout the document.

David Carlisle
  • 757,742
  • way over my head...is there an idiot-proof (idiot=me) way to put marginpars into floats like tables and figures? Redefining \gdef\@parmoderr{\@latex@error{Not in outer par mode}\@ehb} seems a bit drastic, too... – ivo Welch Nov 15 '21 at 17:18
  • @ivoWelch you can't use marginpars in a box, just as you can't use figures in a box, you could do \hspace*{\fill}\rlap{\smash{\hspace{\marginparsep}\parbox[t]{\marginparwidth}{some text}}} – David Carlisle Nov 15 '21 at 19:16
  • is there a way at least to detect whether a marginpar is not allowed and would result in an error? – ivo Welch Nov 17 '21 at 18:48
  • 2
    @ivoWelch you can test for a few places it will definitely fail, but basically no. – David Carlisle Nov 17 '21 at 19:00