Replacements and Placeholder tags

I was playing with the Replacements tab of compile, having it replace the end of each paragraph (CMD-Return) with CMD-Return<$n>, in the hopes of getting a crude paragraph numbering output on compile (paragraph numbering on compile isn’t an option tucked away somewhere, is it?).

What I’m getting on output is:

<$n>1 Paragraph text and stuff.
<$n>2 Another paragraph and stuff.
<$n>3 Paragraph.

etc… It seems that the numbering is taking place, but it’s appending to the placeholder tag instead of substituting with the numbers.

There isn’t a feature for adding line numbering in compile. RTF does have a mode for this, but it is soft-break based, not paragraph (at least that’s how I’ve always seen it done).

I think what you are noting here is the duplication bug. Basically Replacements are running twice now, and that can cause problems if part of the search term is included in the replacement value. This can be most easily seen by adding a replacement for ‘a’ → ‘aa’. Instead of ‘caat’, you’ll get ‘caaaat’. 8)

I’m not sure why the second replacement sweep isn’t evaluated for placeholders, but that does seem to be what is happening. If you switch of placeholder evaluation in the Transformations pane, you get “<$n> <$n> Lorem ipsum dolor…”.

This is because replacements get called before and after auto-numbering is done. Replacements are done once one the text of each section, and then again on the whole text (to pick up text placed in, for instance, separators).

Unfortunately, there’s no perfect way to handle replacements, because users so often like to mix up the tags in various places, meaning that they sometimes need multiple passes. Argh.

It’s not a huge deal. If I were really determined to number my paragraphs, I’d do a project search & replace, possibly adding in a SHIFT-TAB to put the numbers into the left margin area (I assume that’s how it’d work). Later, a Replacements entry could be added to strip all of the <$n:para> tags for a clean compile.

Honestly, while it’d be occasionally handy to have paragraph/line numbering on compile, especially if it could be matched up to the paragraph numbering in the editor, There are other approaches to matching up hand-written notes to text in Scrivener. No need to complicate things further for an edge-case. It’d be nice if individual replacements could be forced to just before or just after placeholder substitution, so that they only run once, but I bet that would confuse more people than it would help.

I wonder if this could be done. Make each paragraph its own document in Scrivener, then when you compile, put the number of the document in as a run-in head?

  • asotir