How can I use the chapter number to reference an Image

I’m new to scrivener, I’m evaluating it to write a software manual, and I’m very satisfied.
I may abandon Microsoft Word.

But I need help because I’m not understanding how I have to use the chapter tag that I’ve used in the compiling “section layout” <$n:chapter> to automatically put the number chapter before the number of an image.

Result that I need

Figure 5.9: The main menu.

where 5 is the number obtained during the compiling process with the <$n:chapter> tag
and 9 it’s the number of the image in chapter 5

Thank you

Thanks for taking a look at Scrivener! As you are writing a software manual, you might be interested in the Scrivener projects used to create our documentation. They are available for download from the support page. The Scapple project is newer, and has a few tricks you might find useful. For example, if a keyboard shortcut in Scapple were ever changed, I would only need to change it once, in the menu appendix. All references to the shortcut in the text refer back to that piece of data.

Anyway, to your question: if I understand correctly, you are trying to use the <$n:chapter> placeholder, both to generate chapter numbers, and to refer to those numbers periodically throughout the chapter text. There is another placeholder type you use should in this situation: <$n:chapter:name_of_chapter> (obviously the last part is up to you just like the “chapter” part is, feel free to use Italian if you prefer! :wink:). These are referred to as named counters, because you can elsewhere refer to them by name to print the number, without incrementing the “chapter” number stream.

When you wish to refer to specific named counter, whether it has even been used yet in the flow of the text (for example, a reference from chapter 2 to chapter 10), the placeholder is: <$n#chapter:name_of_chapter>.

That’s all well and good, but when it comes to putting these placeholders in the compiler, you can only supply one generic placeholder for all of the items, yet with this technique, you need each item to have a unique name. The solution is another placeholder: <$title_no_spaces>. When this placeholder is encountered, the compiler will print the binder title for the section it is compiling, but with the spaces between words stripped out (that makes it easier for the compiler to recognise that this is all one tag). When combined with the above technique, we can embed this placeholder inside of the chapter numbering placeholder, like so:


By example: say you have a chapter named “Installing and Updating”. When you compile, internally the above placeholder will convert to:


In another compile pass, this gets turned into a number, let’s say “2” for this example, but the important thing is that this is your reference code, once you use a “#” instead of a “:”, like so (note it isn’t case-sensitive):

Figure <$n#chapter:installingandupdating>.<$n:figure>

Of course if you plan on referring to these figures in the text, by number, you might want to expand these tricks to the figure numbering stream as well. Each figure can have its own unique name, and thus become a cross-reference hook.

Finally, all of that gets pretty ugly in the text editor, and having to type in all of those punctuation codes leads to error by typo. In our general non-fiction starter template, you’ll find a trick described in the “about” file, and demonstrated in the Replacements compile option pane, under the “Preset Replacements” tab. The trick is that since Scrivener’s numbering codes are plain text, a tool that uses search and replace can modify the text you type into something else. The Replacements pane provides that tool.

In that template I referred you to, you can type: !fig(NameOfFigure) and the compiler will turn it into <$n:figure:NameOfFigure>. If you are familiar with Regular Expressions, note they can be used here. You could create some very easy to type and look at replacements, such as: {NameOfChapter; NameOfFigure}. That’s all the specific information you need to construct the full chapter + figure placeholder syntax (along with some punctuation to help the regular expression find it). Since the rest of the placeholder syntax is identical from one to the next, there is no reason to type it in over and over (but like I say, you can if you want, no need to get complicated!).

You can read more about these codes in the Help/Placeholder Tags List… menu, on the Mac (for the time being these more advanced codes do not work in the Windows compiler).

Thank you so much.
I’ve switched to scrivener, it’s an amazing software.
I’ll do my best to promote it.

One more question, what is your suggestion about images (ex. manual’s screenshots) at the moment I’ve decided to import them inside the project, but I’ve realised that when you drag and drop the image that is already inside the project inside the text the image is duplicated inside the text ( i don’t want to use the <$img:imgName> tag in text because I like to see the image before compiling while I write).

If I use the menu “Insert Image Linked to File…” I get what I desire, changing the image in the text - changing the image in the Finder, but I’me quite scared because if I move the image, or I need to move the project on another Mac or Pc I may lose the image inside the text because the path as changed.

There is a way to replace images path inside the text with “replace all”?

Or any other suggestion?


[For anyone reading this post I’m using GraphicConverter that provide extremely useful tool to crop and convert images automatically, so doing this manual I’ve abandoned Microsoft Word and Adobe Photoshop after more than 20 years of use - Scrivener and GraphicCoverter are more useful to me]

Yes, at the moment you have a good understand of the various ways to work with images. There will be more options in the future though.

It’s not as bad as you think, perhaps. Sure, if the file is not where expected (and when crossing between Mac and PC, that will always be the case since these two operating systems use completely different addressing schemes to files) then nothing can be displayed in the editor but a placeholder. Nothing is harmed by this however. The image link is just a static text address to a location on your disk, so when you return to the computer that does have the image in the expected location, it will load in the editor again.

That safeguard aside, it is just general good practice to set up resource hierarchies that remain stable, when using software that links to these resources. Someone working with InDesign for example would have all of the same constraints you mentioned—having to keep pictures in the right place with the right name—that’s just how you work when you use these tactics. Of course this capability is also an advantage: it means you can swap out sets of images as needed. Use RGB for the digital document and CMYK for print, smaller images for e-books, etc.

Not at the moment, and there isn’t even a way to update one single image to a new path. Things won’t stay that way however.

Thanks for supporting the software—and yes, cheers to GraphicConverter! I’ve been using that program since System 7, I think. A while now. :slight_smile: