Cross referencing figures (LaTex)

(I’ve been trying to figure this out for the whole afternoon / day!)

I am using Scrivener to MMD to LaTex
I have an imported image (now in Resources) inserted into my scrivening, showing as an image, not a Scrivener link.
I have given it a caption.
When compiled to (LaTex) Pdf, it generates “Figure 2.1 : (My caption)” below the image.

All good.

Now: I want to refer to “Figure 2.1” within another part of the scrivening, using auto-generated cross-reference (i.e. not text).

I’ve tried to use the MMD syntax as follows:

[Caption](#nameoffile.png)

But this generates :

Caption (??)

I’ve been round and round with this, generating previews all day, to try and get it to work, and searched through forums and MMD / Scrivener manuals, so V. grateful for assistance!!

Gonna go and have tea now and calm nerves!

You need to add a label beneath the image, alongside the caption.

The syntax for the image label is:

![Caption][Label]

Then, for the cross reference:

[](#label)

Note the label text has to be lower case, without spaces (and the funny shape is a set of square brackets).

So you’d have:

![A beautiful picture][beautpic]

and the cross reference would be:

to understand the wonders of nature see [](#beautpic)

That should do it.

Thanks, McGruff

I’m using MMD 3.n, b/t/way and MMD->(LaTex) PDF production in-built after downloading Fletcher Penney’s MMD Support files

I’ve tested the syntax you suggest. I even downloaded the Scrivener Manual project and played around with that.

I also referred to this post [url]https://forum.literatureandlatte.com/t/using-images-with-mmd-to-latex/21852/1], which suggests a slightly different syntax to your suggestions—perhaps because of differences between MMD 2 and 3?

Anyway, I compiled first to MMD alone and it outputs something like this:

[code] please refer to.

![This is a nice image][thisniceimage.png][/code]

Which seems to work ok, in MMD direct (using Marked to preview, it sets up the # reference as a link to the file.

When I compile to MMD->(LaTex) PDF, I get the following:

[code] please refer to (??)

{the nice image}
Figure 1.1: This is a nice image[/code]

Any clues anyone to what’s going wrong here?b :unamused:

Have you done two typesetting runs in Latex?

You need one run to do the initial layout (which builds the section numbers and pagination) and a second one to put in all the cross references.

If you’re using the MMD->PDF compile format from Scrivener you shouldn’t have to worry about how many times the file is typeset. That option already does a triple pdflatex output. That said the result you have does look a lot like what you get if you only typeset a document with cross-references once.

It’s always a good idea to reduce the amount of automation you are using, when troubleshooting a problem with MMD. The first layer of automation you are using is all of the pdflatex stuff. You can do that yourself, and in doing so, examine the source files that are creating this result. So step back to using .tex, check the syntax in the TeX file and make sure the label matches the autoref. Typeset it two times to get a proper link printed (three times for final metrics, but you can skip that if you are just testing).

If the syntax is wrong, then go back another step of automation and just have Scrivener output a plain MultiMarkdown file, and check that in a plain-text editor for any problems (one that shows unprintable characters as diamonds or something else would be good, maybe a gremlin snuck in).

Ok. Several days later…

I’ve followed the suggestions you’ve offered AmberV, but I’m still getting null results…

If I use this text / syntax (i.e. [text][imagename.png])

> *Facilitator: unless everyone has a textbook, draw [the model][tri-foldnumbered.png] for the group, making sure each circle overlaps the others.*

I get this LaTex output:

\emph{Facilitator: unless everyone has a textbook, draw \href{tri-foldnumbered.png}{the model}\footnote{\href{tri-foldnumbered.png}{tri-foldnumbered.png}} for the group, making sure each circle overlaps the others.} \end{quote}

I.e. it treats the link as a footnote.

If I use this text / syntax (i.e. text:

> *Facilitator: unless everyone has a textbook, draw [the model](#tri-foldnumbered.png) for the group, making sure each circle overlaps the others.*

I get this LaTex output:

\emph{Facilitator: unless everyone has a textbook, draw the model (\autoref{(null)}) for the group, making sure each circle overlaps the others.} \end{quote}

Which unsurprisingly results in the “…(??)…” final pdf output previously referred to.

(…Although, if I manually insert the image filename in place of (null) … presto, it all works. But why is MMD not supplying the image filename? The MMD syntax would seem to be correct, since it is calling the \autoref statement…?)

If I compile for MultiMarkDown directly, based on the above syntax, it outputs the following (I’ve included the image for reference)

[code]![Tri-fold Model][tri-foldnumbered.png]

Facilitator: unless everyone has a textbook, draw the model for the group, making sure each circle overlaps the others.[/code]

So, I’m stumped. I’ve gone through the Scrivener manual, the MMD manual, the ScML Guide1 etc. as linked from this forum.

As an aside (sort of) I can’t find anywhere that DEFINITIVELY set out the correct syntax for linking to an image in MMD 3.x.

Help, would be greatly appreciated! :open_mouth:

Ok. :blush:

I’ve just discovered I’m using “MultiMarkdown version 4.0b”…

Could this be the problem… Perhaps it doesn’t play nice in some way…even if everything else sort of seems to be working ok?

Any thoughts, anyone? Should I try to revert to MMD 3.n? I’ve not been able to find an installer online (I don’t know how to complete from Fletcher’s Gifhub).

Regards…
:open_mouth: :neutral_face:

Okay, the second syntax is definitely the correct one. You would have used the double square bracket syntax in MMD 1 & 2, but it was changed to work more like a normal URL for image references in 3. I’m not sure why that is, since other internal cross-references to tables and headings still use square brackets; it’s a little confusing and inconsistent, but I do know that square bracket references for images do not work at all.

So in the examples where the syntax is correct, I’m afraid I can’t spot the problems. Since you do indicate you are working with a beta version of MMD, I would recommend posting the raw MMD input and TeX result to the Git ticket system for Fletcher to take a look at.

As far as I can see, there is nothing that Scrivener is doing wrong here (but I have not briefed myself on the MMD4 changes).

P.S. I forgot to mention that the Scrivener manual project uses MMD2, so it’s not the best reference for this particular problem as it uses the old image reference syntax. The Scapple manual is MMD3 compatible, though.

I think this is an MMD 4 issue.

I downloaded the Scapple manual project and compiled a couple of sections to latex on my mac, which has MMD 4.1. Looking at the section Scapple’s Main Interface I got:

Scapple's interface has been designed to be as minimal as possible---for the most part, it's just you and your notes. The provided screenshot of the interface (\autoref{(null)}) has been numbered and explained, below.

I then tried it on Windows 7, which has a fresh Scrivener install and no separate MMD installation, and is therefore running MMD 3.x. The same section gives:

Scapple's interface has been designed to be as minimal as possible---for the most part, it's just you and your notes. The provided screenshot of the interface (\autoref{scappleinterface.png}) has been numbered and explained, below.

So with MMD3 the autoref has the file name and with MMD4 it does’t, giving that persistent b[/b].

Yeah, I can confirm that on my machine as well. Looks like a bug worth reporting to Fletcher; I shall do so.

(Ticket link.)

Thanks, Amber. :smiley:

Belated return to the forum, having got stuck into the project again, after Fletcher either updated the bug or I downloaded a later version…or something. All working smoothly on that front now.