fmarotta/kaobook

Float(s) lost

cpazinatto opened this issue ยท 10 comments

Whenever I try to use a sidenote within one of the environments from mdftheorems I get a "Float(s) lost" error. If I try to use a marginnote it works fine. Is there any way to make it work?

Unfortunately it is a feature of LaTeX that floats cannot be nested, otherwise they 'get lost'. However, if \marginnote works for you, you can add a new macro which will use it to emulate a sidenote:

\makeatletter
\NewDocumentCommand\thmsidenote{ o O{0pt} +m }{%
    \IfNoValueOrEmptyTF{#1}{%
        \refstepcounter{sidenote}% This command has been moved here
    }{%
    }%
    \sidenotemark[#1]%
    \marginnote[#2]{\thesidenote: #3}%
    \@sidenotes@multimarker%
}
\makeatother

This definition should be placed either in the preamble of the main.tex or somewhere in styles/kao.sty.

PS
\marginnote does not work for me inside definitions or theorems: which environment are you using?

I ran into this today as well. Same error with \marginnote too, as @fmarotta mentioned.

@cpazinatto Did you get this fixed?

@fmarotta Any plans to implement a fix?

I will see what I can do in the next few days. As a possible temporary fix, and as a test that would help me to design a better solution, could you please tell me what happens if you add a vertical shift of 0pt to the marginnote? I.e. \marginnote[0pt]{...}

Oh, interesting. Yeah, adding any offset to \marginnote or \sidenote seems to make the error go away. I tested it with the assumption environment and with the margintable environment. Because the margintable is actually in the margin, the \sidenote or \marginnote gets put on top of the margintable. Manual offsetting fixes this. However, manual offsetting is not super fun when writing a book; floats that play well together is definitely preferable.

I totally agree. Thanks for doing that little test: when the offset is added, the \marginnote (or the \sidenote) becomes fixed, rather than floating. So in the latest commit, where, sadly, I forgot to reference this issue, I introduced the \ifInFloatingEnvir conditional: if the note is already inside a floating environment, like a theorem or a margintable, it is printed in non-floating mode.

This should fix the original issue, but I did not understand the problem with margintables: do you @bradyneal want to use \sidenote inside a margintable? If so, should the note refer to the caption or the table itself? And what is the expected behaviour? (Sorry for the many questions, they are really just to understand and see if I can do something about it.)

Nice, it works for me in the simple case, but it gives the same bug as before when the sidenote/sidecite is nested inside an enumerate environment that is inside of a floating environment.

Regarding the margintable, I don't think I was referencing the note inside the table/caption. Rather, I was just using sidenote somewhere near the margintable, and the sidenote was landing on top of the margintable. So the all the sidnotes, marginnotes, and sidecites seemed to float nicely and not land on top of each other, but the margintables and marginfigures did not. Is that more clear?

Yes, thanks. Is this the same problem as in #49? Anyways, does the sidenote overlap with the margintable, or is it just uncomfortably close to it?

Oh, yes; same problem as #49. I think I created that issue a bit after I commented about it in this thread. If I recall correctly, the sidenote and/or sidecite was appearing directly on top of a margintable. I think I ran into this with marginfigures as well. The second or third time I encountered it is when I made the issue.

Good, I added a comment on that issue trying to address this problem.

As regards the other problem, the one that occurs when the sidenote/sidecite is in an environment which itself is in a floating environment, I think it is because so far I just check the innermost environment, not the parent environments. I'll try to fix it asap.

I have now added a flag that is toggled at the beginning of the mdframed and minipage environments. If that flag is active, then the marginnote is printed in fixed, rather than floating, mode.