The phrase "have in mind" refers to the number of expressions, and "in mind" there is always written separately (regardless of context). For example, "the head officer made the remark, having in mind incorrectly written agreement. Or another example: "there Was a time when I was engaged in minerals, not having in mindthat someday become a geologist."
The word "mind" is written together, if the importance is causal (or effect) relationship. For example, Inthe form of good weather, the whole family got together and went to the beach." Or: "In themind of a sudden outbreak of a storm, we were forced to approach the shore".
Not to be confused with the noun " mind" with the preposition "inmind", you can test yourself in the following way. If we are talking about events that already happened or is happening, and they can be replaced by a turnover "because", then you have an excuse "inmind (because of) good mood, grandma baked a delicious Apple cake." Or: "He has been sick in themind (because of) a weak immune system.
In another case, "have in mind" something (event) or someone (people) means to take something into account or to keep (at least mentally) in the field of view. It is already a combination of a noun with a preposition and it is written separately. For example, "boat floated on the smooth surface of a beautiful lake, in sight of the shore", "the fish swimming in the aquarium in the mind of plants".
The same algorithm applies when selecting "like" and "kind", "after" and "mark", "forward" and "meeting", "like" and "likeness" in the "middle" and "middle".