Markdown to LaTeX compile issue images missing tags & captions

When I add images to scrivener some are not correctly compiled to MMD, then to LaTeX.

I have the same issue as @phrk here: Using Images with MMD to Latex
Although his solution does not work all the time.

After adding a picture and compiling it to markdown they appear as so:

![Ice-cream machine fully assembled][Draft_Full_Isometric]## Hardware ##

Then they are compiled to LaTeX and become:

\begin{figure}[htbp]
\centering
\includegraphics[width=241pt,height=400pt]{Draft_Full_Isometric.png}
\caption{Ice-cream machine fully assembled}
\label{draft_full_isometric}
\end{figure}

BUT SOMETIMES:

They generate to this markdown:

Also note that the ice forming on the wall of the cylinder heat exchanger, creates a heat-insulating layerben_lakhdar_heat_2005, therefore constant scraping is necessary, and heat transfer in this way is a pulsating exchange.
![Breakout of the freezing assembly][Draft_FreezingAssembly_PerspectWithBladesUncut]

Translates to LaTeX without the tags:

\includegraphics[width=350pt,height=269pt]{Draft_FreezingAssembly_PerspectWithBladesUncut.png}

The difference as @phrk noted is the trailing empty line before the image. But it has to be in Markdown!
Sometimes Scrivener removes this empty line.
And the empty line in front of the image in Scrivener would not fix it.

Sometimes an empty line with a whitespace fixes it, but sometimes even that would not help.
All my images are at the end of scrivenings, and have text before them

I could replace /r/n![ to /r/n/r/n![ in the Markdown file but I cannot access it during the MMD to LaTeX process, and replacements are only done before compile.

Is there an elegant solution for this?

To confirm the issue, these errors stem from spacing issues, maybe from how it is being entered into the editor, or from separator settings in the compiler. In this case:

![Ice-cream machine fully assembled][Draft_Full_Isometric]## Hardware ##

We would probably want to see this:

![Ice-cream machine fully assembled][Draft_Full_Isometric]

## Hardware ##

And this one…

Also note that the ice forming on the wall of the cylinder heat exchanger, creates a heat-insulating layerben_lakhdar_heat_2005, therefore constant scraping is necessary, and heat transfer in this way is a pulsating exchange.
![Breakout of the freezing assembly][Draft_FreezingAssembly_PerspectWithBladesUncut]

…also needs a full space between the image and the preceding paragraph. The way it is formatted here would make the image inline with the paragraph, and inline images wouldn’t have the full caption and float treatment.

So that’s what is happening, as to how to fix it, I’m not sure—Scrivener shouldn’t be changing your line spacing with default settings. One thing to check for is to turn on invisible characters, and look for symbols. You should only ever be seeing symbols at the ends of lines. The former works like a <br/> in a word processing context, but does nothing special in a Markdown file.

Another factor might be if you’re using the full RTF to MMD conversion switch in your compile settings. It doesn’t sound like you should be, if you’re writing Markdown into your documents, but maybe you have a reason to be trying it out. That is the one thing that will mess with line spacing, as most RTF users won’t be fully double-spacing their paragraphs. I would say though that it should be erring toward adding redundant newlines, rather than subtracting any.

Is there an elegant solution for this?

Finding the source of the problem will be the best approach. This isn’t something that should be happening ordinarily. I’ve never had images end up adjacent to paragraphs, or combined with heading lines, and I’ve used thousands of them in Scrivener over the years.

Thank you for the fast reply! I really appreciate it.

I am not entirely sure what you meant. I feel I might have misexplained my situation.
I am not writing in Markdown to Scrivener, just simply examined how the output looks if I switch the Markdown > LaTeX to simly MultiMarkdown compile. So I write in Plain text only, and output to LaTeX

How the part in question looks is in the image below.

Also, I’m unsure what is the difference between the solid paragraph sign(in the empty line) an the empty one (after the text) when i turn on the invisibles.

Yes, this is exactly what I was thinking when I found no one mentioning this before.

Also I don’T have Rich text to Markdown, I have tables and lists to Markdown. Also replaced the paragraph signes to be full solid by Copy pasting them, but to no avail .

It might help to share a couple of snippets in an example project that reproduce these problems. I don’t see anything in the screenshot that would cause this image to end up adjacent to the previous paragraph. When I test those same conditions (paragraph + line + image + line + table), I get a valid Markdown file, just using the stock “Basic MultiMarkdown” compile format:

Thung ik la flim urfa su ewayf thung. Berot wynlarce---gen nix srung athran er vusp gen, sernag jince. Ma er ma jince ma rintax ma wex ux wynlarce. Xu, zeuhl lydran ux erk. Sernag epp anu er cree ik korsa groum rintax velar ozlint velar thung vo korsa berot menardis er arul.

![This is the caption of the image][Clipboard-Image]

| one | two | three |
| :------------- | :------------- | :------------- |
| four | five | six |