Skip to main content
Participating Frequently
October 4, 2023
Answered

GREP or script to move punctuation to before a footnote reference in an InDesign text.

  • October 4, 2023
  • 6 replies
  • 858 views

I'm designing a textbook with a lot of footnote reference numbers. They all have the Characterstyle "Footnote_Numbers" (I made them pink). Two things: 1) The punctuation is now AFTER the Footnote Numbers, instead of before. 2) There are also footnote numbers in the middle of a scentence and in those cases I need to remove the space that precedes those footnote references, because those all have a white-space before the superiour digits. This white-space has NO character style. I'm trying to get a script or GREP to solve both problems.... Hope one of you wizzards has a solution? THANKS!!

 

 

 

 

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

Manually -- the thought!

 

Here's another approach. The script now looks for anything in the FootnoteNumbers style, and if the following character is punctuation,  it's moved.

 

You'll have to run it against a version of the document as it was before you ran the previous script.

 

app.findGrepPreferences = null;
app.findGrepPreferences.appliedCharacterStyle = 
  app.activeDocument.characterStyles.item('Footnote_Numbers');
found = app.activeDocument.findGrep();
for (i = found.length-1; i >= 0; i--) {
  x = found[i].parentStory.characters[found[i].insertionPoints[-1].index];
  if ('.,;!?'.indexOf(x.contents) >= 0) {
    x.move (LocationOptions.BEFORE, found[i].insertionPoints[0]);
  }
}

6 replies

Peter Kahrel
Community Expert
Peter KahrelCommunity ExpertCorrect answer
Community Expert
December 13, 2023

Manually -- the thought!

 

Here's another approach. The script now looks for anything in the FootnoteNumbers style, and if the following character is punctuation,  it's moved.

 

You'll have to run it against a version of the document as it was before you ran the previous script.

 

app.findGrepPreferences = null;
app.findGrepPreferences.appliedCharacterStyle = 
  app.activeDocument.characterStyles.item('Footnote_Numbers');
found = app.activeDocument.findGrep();
for (i = found.length-1; i >= 0; i--) {
  x = found[i].parentStory.characters[found[i].insertionPoints[-1].index];
  if ('.,;!?'.indexOf(x.contents) >= 0) {
    x.move (LocationOptions.BEFORE, found[i].insertionPoints[0]);
  }
}
Peter Kahrel
Community Expert
Community Expert
December 13, 2023

I corrected the script, above (= should be ==). I didn't see the error here because of, well, because. Sorry. 

Participating Frequently
December 13, 2023

You are a hero! How happy one can be when a script works... ridiculous. What I forgot was that there are superiour numbers with more than 1 reference. They even have punctuation in that style "Footnote_Numbers" as you can see, I think I will correct that by hand?

 

 

Peter Kahrel
Community Expert
Community Expert
December 13, 2023

So they're endnotes, not footnotes 🙂

 

You need this version of the script:

 

 

app.findGrepPreferences = null;
app.findGrepPreferences.findWhat = '\\d+[[:punct:]]';
found = app.activeDocument.findGrep();
for (i = found.length-1; i >= 0; i--) {
  if (found[i].characters[0].appliedCharacterStyle.name == 'Footnote_Numbers') {
    found[i].characters[-1].move (
      LocationOptions.BEFORE, found[i].insertionPoints[0]
    );
  }
}

 

Participating Frequently
December 13, 2023

Hihi, very much ENDNOTES! I keep calling them all footnotes, but now I hopefully am cured. I am getting an error though.

Peter Kahrel
Community Expert
Community Expert
December 12, 2023

in my text some numbers are superiour and they have the Characterstyle "Footnote_Numbers".

 

Are those superior numbers real footnote references? (Sorry, I have to ask.)

Participating Frequently
December 13, 2023

No, good question! I have the impression that that is the core of my problem, they are just superior numbers, the link to the references is broken...

 

Peter Kahrel
Community Expert
Community Expert
December 13, 2023

So the footnote texts are in separate frames at the foot of the pages, correct? If not, what does it look like? Can you show a screenshot? Please enable the display of frames and hidden characters. Or post your document.

Participating Frequently
December 12, 2023

Unluckily, this solution doesn't work, nothing happens when running the script:

 

app.findGrepPreferences = app.findChangeGrepOptions = null;
app.findGrepPreferences.findWhat = '~F[[:punct:]]';
found = app.documents[0].findGrep();
for (i = found.length-1; i >= 0; i--) {
found[i].characters[0].move (LocationOptions.AFTER, found[i].characters[1]);
}

What do i do wrong? To explain my problem again: in my text some numbers are superiour and they have the Characterstyle "Footnote_Numbers". The punctuation is now AFTER these superiour numbers instead of before. 

Peter Kahrel
Community Expert
Community Expert
October 4, 2023

This has come up before, several times. Google finds e.g. this post:

https://community.adobe.com/t5/indesign-discussions/find-and-swap-position-of-period-footnote/m-p/11269257

 

The script there looks for 

 

'[[:punct:]]~F'

 

to move punctuation after the footnote reference, which is the opposite of what you want. So you should change the above to

 

'~F[[:punct:]]'

 

You then deal with the spaces in a separate query, no script required:

Find what: \h(?=[[:punct:]]?)
Change to: <leave empty>

That is, look for a (horizontal) space followed a punctuation mark (optionally) and a space. Replace the space with nothing.