I have a class file that I am writing (it's my first one and I am new to LaTeX). I have a situation where I'd like to know if I am inside a float so that I can prevent attempting to create a nested one. I found How can I detect if I'm inside or outside of a float environment? but this didn't work. I tried this (from the answer to that question):
\makeatletter
\def\InFloat{\ifnum\@floatpenalty<0\relax in float \else outside float \fi}
\makeatother
But it always displays "in float" wherever I place "\InFloat" in my document. I have also found How to detect if in an exercise environment? and tried this:
\newcommand{\InFloat}{\ifinner inside-float\else outside-float\fi}
but that doesn't work either. I've been trying to find an answer but have been unsuccessful so far...
Updates
Thanks for the replies, I have tried this:
\makeatletter
\def\InFloat{\@ifundefined{\@captype}{OUTSITE}{INSIDE}}
\makeatother
but I got this in the output "Undefined control sequence. \@captype".
I should add a bit of background about what I am trying to do, and why. I have a number of documents that are text based but marked up using some proprietary markings. I want to convert these so I can use LaTex going forwards. The mark-up is such that it is easily translated into LaTeX with a sed script (I am writing commands and environments in a class file make those marked up sections render as needed - the sed script substitutes the mark-up for the commands/environment begin/end that I have created).
Two of the mark-ups are relevant to this question. One defines a box and I have implemented an environment using boxedminipage for that. The other defines an image (or actually potentially multiple images, a caption and some text). I have implemented an environment using figure for that one. They both work fine, except for the possibility that the image mark-up can fall inside the box mark-up. It is this case I want to detect and simply not create the inner figure in the case when the image mark-up appears inside a box mark-up. Hopefully that makes sense.
\makeatletter\def\InFloat{\@ifundefined{\@captype}{OUTSITE}{INSIDE}}\makeatotherwork? (It is untested.) – yo' Feb 25 '13 at 09:36\captionoffor example, but they are acting like floats so you probably want the in-float behaviour in that case. But you should think hard if you really want to do this. It is best for class files not to change LaTeX conventions to much, and in standard latex markup it is always explicit whether or not an environment is floating. – David Carlisle Feb 25 '13 at 09:46[H]should be classed as float or not, the penalty test just tests for real floats. – David Carlisle Feb 25 '13 at 10:12\makeatletter\def\InFloat{\@ifundefined{@captype}{OUTSITE}{INSIDE}}\makeatother. I will add it as an answer to the other question, and I will possibly explain the answer that is already there. The fact that that answer is not explanatory somehow doesn't influence the fact that they ask the same thing. – yo' Feb 25 '13 at 14:29