Remove empty caption line

I am compiling a PDF, using Scrivener 3, Mac OS, to generate LaTex from Multimarkdown text.

I have some figures that have captions [caption] and some without.

Figures without captions are nevertheless generating an empty line in the Tex output: \caption{} .

Is there a way to remove the empty caption (line) in the automatically generated Tex output? It is not practical to edit the Tex afterwards, because I generate it fresh hundreds of times a day / week.

This looks like an issue with MultiMarkdown rather than Scrivener (and thus it’s outside of its control, unless you break out the Processing pane and use sed to clean up MMD’s output, or something). You’ll get the same result if you type in a quick test into the command-line:

[code]$ mmd2tex

And this one has a caption[/code]



\caption{And this one has a caption}

So that’s happening after the compiler has done everything it does, save for executing MMD against its output and piping the the result to a file/folder as you request.

I suppose one way you could get around it is to force MMD to consider the figure “inline”, by putting a space in front of the image. Not terribly clean, and inline images are simply \includegraphics{…} all by itself, not the minipage and alignment stuff, which might work against you.

I have to say though, I’ve never run into problems with how this works—though now that you bring it up, I wonder how often I use images on their own lines without having a caption. :slight_smile: It might be kind of rare—maybe only in listing environments.

Thanks for these thoughts.

I’ve implemented some tex in the preamble that corrects the issue, but had hoped to discover an MMD / Scrivener solution. … ption-line

Well like I say, you can use the Processing pane for stuff like this. It can be as simple as using sed to wipe out these lines, which is what I would do for something very simple like this, or more complex. The user manual project has a post-processing script that does some stuff to the MultiMarkdown file Scrivener creates, then runs MMD to create the .tex file, and then processes that further. In one case I have table formatting stored in a custom metadata field for each table in Scrivener. The compile settings print the custom tabulary line as a LaTeX comment directly above the table itself, and the script comes along looking for those and swaps out the generic tabulary MMD generates. For a while I experimented with moving the caption line above the image (before I figured out how to make it so cross-references would scroll to the top of the image rather than the caption in PDF viewers).

It’s programming at that point, so there really is no limit to how you can instruct Scrivener to manipulate the output, and that all can be stored directly into the compile settings, making it something you can then save as a global Format for use as a starter in all your projects.

Check out §24.22 in the user manual, if you’ve never looked into this before.

I will. I started out using a comprehensive set of preamble tex files supplied by MMD itself. Gradually, I’ve been discovering how powerfully Scrivener can accommodate tex. I’ve not got as far as replacing my convoluted preamble, but perhaps that’s next…