Skip to main content
Known Participant
August 26, 2016
Answered

Add sequential endnote numbers using a character style

  • August 26, 2016
  • 2 replies
  • 1346 views

Hello,

I'm wondering if anyone knows of a script that would insert endnote numbers sequentially at each instance of a character style.

In our editing process, we use "hard" endnote numbers that are based on the section numbers of the text. When the editing process is complete, we go through and manually change them to sequential numbers. The endnote numbers have a special character style, so such a script would go to the first instance of that character style, replace the characters with "1", then go to the next instance of the character style and replace the characters with "2", and so on.

Any help would be much appreciated.

Alicia Dole

This topic has been closed for replies.
Correct answer Peter Kahrel

A standard operation. In the third line, replace 'Hard endnote number' with the name of the character style you use for the endnotes.

app.findGrepPreferences = null;

app.findGrepPreferences.findWhat = '\\d+';

app.findGrepPreferences.appliedCharacterStyle = 'Hard endnote number';

found = app.documents[0].findGrep();

for (i = found.length-1; i >= 0; i--) {

  found.contents = String (i+1);

}

Peter

2 replies

Peter Kahrel
Community Expert
Peter KahrelCommunity ExpertCorrect answer
Community Expert
August 28, 2016

A standard operation. In the third line, replace 'Hard endnote number' with the name of the character style you use for the endnotes.

app.findGrepPreferences = null;

app.findGrepPreferences.findWhat = '\\d+';

app.findGrepPreferences.appliedCharacterStyle = 'Hard endnote number';

found = app.documents[0].findGrep();

for (i = found.length-1; i >= 0; i--) {

  found.contents = String (i+1);

}

Peter

Obi-wan Kenobi
Legend
August 28, 2016

Peter, for my learning, is there a real meaning not to write:

for (i = 0; i < found.length; i++) { 

Thanks!

About the op's question, why not use an auto-numbering para style and a simple grep find/replace, or, imho maybe better but depending on the op's context, convert static endnotes to dynamic ones!

Convert footnotes to endnotes | Peter Kahrel

(^/) 

Peter Kahrel
Community Expert
Community Expert
August 28, 2016

You have to process the found numbers back to front to deal with changing number lengths, as in changes from single- to double-digit numbers, and from double- to triple-digit numbers. Suppose you have the numbers 9 and 10, as in

blah9 blabla10

and you're adding 1 to all note references. 'blah9' becomes 'blah10', the insertion of a character causes the found items after the new 10 te become misaligned: What used to be 10 has now become a1.

Why not use auto-numbering? Because that's not so easy in note references. I know it can be done, but it's a lot of of unnecessary overhead. And besides, it's not what Alicia asked

Peter

Obi-wan Kenobi
Legend
August 27, 2016

Can you post screenshots? Thanks!