Placeholder Tags

For me the most difficult thing about Scrivener is Forward References with Placeholder tags. I use templates for numbering Figures and Chapters. However when I run off a new version of a book I frequently find that would should be Chapter 23 is numbered Chapter 12 (though in its correct order). Basically the only difference between a regular(backward and current) reference, and a Forward reference (that waits until that reference has been found before assigning a number) is replacing the “:” after “$n” with “#”. It is really easy to mess this up so that the number is assigned to what should be a Forward Reference. Moreover big problems arise when Chapters are moved to different locations so that references to items that were in the past suddenly become future reference relevant codes have to be changed.

This might seem obscure but working all this out, and finding the problematic references, is one of the most annoying and time consuming tasks that arises when running over a new version of the Manuscript.

I’m not sure how this can be fixed. Maybe a special code for the actual Chapter or Figure name so that the program would know this is the one that the relevant number should be assigned to, and a slightly different code for references to that item, without having to work out whether it has yet appeared in the text.

Perhaps a key missing point is that this code isn’t strictly a forward reference, it is just a reference. The “#” method always works, no matter where it is found in the compiled content. How I would approach this, if you need a lot of cross-references and cannot anticipate where they will be made from, is to keep a sharp distinction between the code you use for referencing and the code you use for making numbers. Only ever use the “:” code when you need to generate a new number, never for any other purpose, and always use the “#” when referring to that number.

Thank you very much.

One slight trick that might make using this easier and less prone to error.

The place where a number is actually assigned is usually a Scrivener document of it’s own: either a chapter heading for a Figure.

Put the code that generates the number with the Figure (or chapter)in the main pane of this document where it will enter the text.

Figure <$n:Chapter:Conventionalized_Signs>.<$n:figure:Candy_GFruit>

Then copy this to the Document Notes panel, change the colons to hash tags:

Figure <$n#Chapter:Conventionalized_Signs>.<$n#figure:Candy_GFruit>s

Then copy from this, the version in the notes, for all other references to this place within the main text of the document.

This saves you from having to change the colons to hashtags every time you make a reference in the midst of what is a rather complex and confusing string of characters.

In case it is useful to anyone here is a detailed set of instructions for using placeholders to generate numbers for Chapters and Figures in Scrivener

dl.dropboxusercontent.com/u/332 … bering.pdf

Great, good stuff! Thanks for posting your tips as an extensive tutorial.

This post on creating dynamic captions may also give you some ideas. Of course the premise of that post isn’t really applicable to what you are doing, but the trick to use Replacements in the compile pane to keep these long and easy to typo codes out of the editor is a concept that can be applied to a wide variety of applications.

In fact we even have a simple example of how you can do that, wired up in the general non-fiction template. In there, you can type in something like !fig(Candy_GFruit) and have it turned into <$n:figure:Candy_GFruit> when you compile, which in turn then gets processed as a number.

The way I would approach this is to have one unified compound code that generates the entire figure string for you, by typing in something like the following:

[Conventionalized_Signs:Candy_GFruit]

When compiled with the right settings, this would be used as source material by the search engine generate your entire caption string, grabbing the first and second labels into the replacement text for you, formatting it with the period between them and putting the word “Figure” in front. When you want to refer to that image, you’d use the same exact code but with the proper punctuation switch:

[Conventionalized_Signs#Candy_GFruit]

How this would work in the Replacements pane is by using regular expressions, which have the ability to extract parts of what you are searching for and insert those into the replacement value in whatever order you prefer. In these examples, we could use the same exact search code for both, as we really have three variables here:

  1. The chapter code first.
  2. The type of placeholder we need (counter vs. reference).
  3. The figure code last.

Here is a regular expression that would detect this formation of text and extract these three variables:

\[(\w+?)([:#])(\w+?)\]

I know, right? It looks like a ASCII art that went horribly wrong, but that searches for text inside of square brackets which is comprised of two blocks of letters (underscores are considered “connector punctuation” and thus part of a word) separated by either a colon or a hashmark.

When this is regular expression is used and it finds a match, it will create three numbered variables ($1, $2 and $3) that can be used within the replacement string, like so:

Figure <$n$2chapter:$1>.<$n$2figure:$3>

$2 is equal to the separator punctuation that was used in the original text, so with the first example, $2 would print “:” and in the second, it would print “#”, wherever you see it used in the replacement string. We then use $1 and $3 to print the chapter and figure labels respectively.

Just make sure to check off the “RegEx” flag in the Replacements pane, otherwise it will search for all of that gibberish literally and of course find nothing, unless maybe if you have ASCII art in your manuscript. :wink:

Of course another advantage of using this method is that it centralises your caption format. If you find out midway through writing that the preferred style you need to use is “Fig.” instead of “Figure”, no problem! Just go into the Replacements pane and change the replacement template to Fig. <$n….

I have attached a sample project that demonstrates the features.
smart_captions.zip (193 KB)

@Chuck Thanks for taking the time to post your informative PDF. I have lots of images, so this is invaluable.

… and, the link is dead. Could it be reposted as zip or whatever is appropriate?