Ability to refer to an auto counter without incrementing it

This would be useful in order to do such things as be able to refer to what chapter (or section or subsection or whatever) we are in.

My particular usage involves needing to number figures and tables in a chapter.figure format like:

Figure 7.1 Examples of Lepidoptera spp.

Use of things like $hn, $position, and $parentposition don’t work because the chapters are broken down into parts, and often the figures and tables are buried in the hierarchy in subsections. This is a very common way in which technical books are written, so the fact that I can’t find out what chapter I’m in to properly label things is hair tearing out level.

I suggest an extension to the reference syntax so that <$n#chapter> would give the current value of the chapter counter. In a link it should give the chapter counter that would be current in the document linked to in a link so that:

Figure <$n#chapter>.<$n#table:<$title_no_spaces>>

in a link in chapter 14 that references the above Lepidoptera figure in chapter 7 will produce:

Figure 7.1

You can already do this - see the section on figure and table auto-numbering in Help > Placeholder Tags List. E.g:

Chapter <$n:chapter:bob>
Chapter <$n:chapter:sally>

Please refer to Chapter <$n:chapter:bob>.

Results in:

Chapter 1
Chapter 2

Please refer to Chapter 1.

That only works as long as the tables or figures aren’t moved from one chapter to another. If I move something, then I have to go back and fix all the chapter references. I might as well wait until everything is done, and then just put the numbers in myself.

It doesn’t matter where the references are - I don’t know what you mean? The references can be anywhere, in any chapter, and you can move them around as much as you want. The only thing that matters is that the first time time the reference it is used is the time the number will be generated.

Okay, let’s say that I have a figure of an illustration of Lepidoptera (moths and butterfly) mouth parts. Originally I put this figure in chapter 7, titled Lepidoptera, and which has the internal reference $n:chapter:lepidoptera. I put this figure in its own document titled “Lepidoptera mouth parts”, and I enter as the caption under the illustration:

Figure <$n:chapter:lepidoptera>.<$n:figure:<$title_no_spaces>>. Examples of Lepidoptera mouth parts.

All good, this comes out as:

Figure 7.4. Examples of Lepidoptera mouth parts.

I can make internal Scrivener links to this, including forward links using the # syntax if necessary. Such as

See Figure <$n#chapter:lepidoptera>.<$n#figure:<$title_no_spaces>>
to get:

See Figure 7.4

Now, let’s say I decide to move the subsection this figure is in into a different chapter on insect feeding behavior, which is <$n:chapter:insectfeedingbehavior>, and when the document is compiled, comes out as Chapter 14. I now have to manually update the caption, and then go back and find all the links for this specific figure and change <$n:chapter:lepidoptera> to <$n:chapter:insectfeedingbehavior>, in order to have the caption change to

Figure 14.10. Examples of Lepidoptera mouth parts.

And all the references to this figure are now supposed to say “See Figure 14.10”, but if I miss one it’s going to say, “See Figure 7.10” which is pointing to the wrong chapter, and there may not even be a Figure 7.10. And of course, the tags like <$n:chapter:insectfeedingbehavior> are automatically generated by using <$title_no_spaces> in the title prefix in the compiler, and if I change the title, now all my references are busted.

I love Scrivener because of the flexibility in just moving stuff around as you please, but this isn’t flexible, it’s very fragile and prone to produce errors if I move stuff around between chapters.

How are you structuring your work? Do you have sections organised inside chapter folders? If that’s the case, you could do the following:


(I’m not sure why you are putting the chapter title in the figure tag rather than a unique name that represents that particular figure.)

Then, in all documents that refer to the document with the figure in, be sure to add a Scrivener link to the “<$parenttitle_no_spaces>” that points to the document in which the figure appears.

That would do what you want. So, say for example you have a folder titles “Lepidoptera”, and you have a subdocument inside that chapter with the figure in. The above in that subdocument would resolve to: <$n:chapter:Lepidoptera>. When you add the tag to another document that’s in another chapter, by adding a Scrivener link to the “<$parenttitle_no_spaces>” part of the tag that points to the subdocument containing the figure in the other chapter, the tag will resolve to the same thing (<$n:chapter:Lepidoptera>). And if you move the subdocument containing the figure to a completely different chapter, it won’t matter, because now the tags used throughout will pick up the title from its new parent folder.

So, if you have your project structured into folders with subsections, that should do exactly what you want.

Remember you can also use Replacements in Compile to make these tags easier on the eye. For instance, you might set up a replacement as follows:

Replace: [Fig:$@]
with: <$n:chapter:<$parenttitle_no_spaces>><$n:figure:$@>


Then you could just write:


And link the document containing the figure to this entire tag. The replacement during Compile will then replace this tag with <$n:chapter:<$parenttitle_no_spaces>><$n:figure:lep_mouth> and will apply the link to the entire tag, but it would only be used by the <$parenttitle_no_spaces> part since the rest of the tags here ignore the links. This will make your test a lot more readable throughout, obviously.

Hope that helps.

All the best,

There are also subsections, which makes using $parenttitle not work (it then refers to the section title). I’m also not aware of any way to create a scrivener link to anything other than a document, which given that I want eventual html and ebook versions to have active links to the referred figures, the figures and tables themselves have to go in their own documents.

I’m not putting the the chapter title in the figure tag, I’m using the chapter reference to get the number of the chapter so that it ends up being Figure 7.4 (7 being the chapter number), instead of just Figure 4. The unique name that represents the figure is the title of the figure document, not the chapter title. The unique name that ends up representing the example figure I gave ends up being $n:figure:Lepidopteramouthparts, because “Lepidoptera mouth parts” is the title of the document that contains the figure.

It is extremely common for technical books to have figures and tables labeled using the chapter.figure method, so this affects a lot more books than mine. I need to have active links to the referred tables and figures in the HTML and ebook versions, so I can’t flatten the structure and fake the subsections (a few of which have links to them as well).

You can create Scrivener links only to documents, correct - there’s no way to link within documents. That may be added in the future as it comes up occasionally, but it’s not on the mid-term list I’m afraid. But if your figure is inside a document of its own, then that will work for HTML - just link to the figure document.

To be honest, I’m not really sure what else Scrivener can do here with regards to the auto counter, short of adding <$grandparent_title_no_spaces> tag, perhaps. The trouble is that you have to pieces of information in the numbering - chapter and figure - and by moving the document you are breaking the connection. Scrivener provides <$parent_title…> for this sort of thing, but if that won’t work with your structure, I’m not sure what solution could be provided (except for the grandparent tag, but when what if you put the figure even further down the hierarchy into a sub-sub-section?). Scrivener has no concept of chapters and the structure is entirely up the end user, and there’s only so much automation that can be provided in that set-up. I’m open to suggestions but I can’t think offhand what sort of tag could be added.

Perhaps a parent counter? <$parent>/<$parent1>, with <$parent2> being the grandparent and <$parent3> being the great-grandparent and suchlike. Again, linkable in the same way <parent…> is. But this would depend on your figure being at the same place in the hierarchy at any point, so moving it deeper or higher would break it. Perhaps a better solution would be <$level1>, <$level2> etc, which would point to the document at that level in the branch of the current document (or the linked document). Presumably your chapter titles are always at the same level, so that should provide a workable solution if implemented.

At any rate, I have been doing my best to help you towards a solution, so I’m sorry that you are not happy with what I’ve suggested.

Well, this is why I suggested in my original post to have the ability to refer to named auto_numbering streams without incrementing them. Extending the “forward reference” syntax in a logical fashion, such that <$n#chapter> refers to the current value of the chapter stream without incrementing it, and putting <$n#chapter> in a scrivener link refers to the value of the chapter stream in the linked document (I realize this is pretty hairy, and probably the hard part of making this work). If it could be made to work, it would be a perfect solution. It imposes no concept of chapters on Scrivener, structure is still entirely up to the end user, and no matter where material is moved around to, it just works.

Making some sort of generalized <$parentparenttitle> scheme (where the number of "parent"s is arbitrary and up to the user) is kind of halfway, but as you point out, it breaks if material is moved from one level of the hierarchy to another.

Given that this is the wish list forum, I’m less looking for a solution to my current problem (I have resigned to tagging all the places where I need to fix things up, and going in at the end when nothing is going to move around any more and adding the numbers manually, not looking forward to future editions with revisions), than I am to hope that future versions would have a better solution. Given the general nature of technical books, I’m just surprised that no general solution is available yet. For instance, Scrivener Absolute Beginner’s Guide uses the same chapter.figure scheme, has active links to figures in the ebook version, and according to figure 19.10 in that book, uses a hierarchy that goes down to subsections.

Hi Quadruped,

Could you maybe elaborate on the system you are using now? I’m facing the same problem, and asked for a solution for this (together with a more customized numbering of headings) here:

Thanks for a reply

Did anyone ever find a solution to this? I am having the same issue…and all I need is just something that points to the position of the “grand” or “master” parent. The problem with figures and tables in sub-sections is that the “parentposition” is the position of the sub-section which makes the ordering of the figure incorrect if you have use labeling such as Fig 1.1. I guess this would be no issue if you only moved figures around to their same levels…so frustrated, but I guess its just a small issue in a rather great software.

Any ideas would be great.