Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
6

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

Explorer ,
Oct 04, 2023 Oct 04, 2023

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!!

Screenshot 2023-10-04 at 17.18.30.pngScreenshot 2023-10-04 at 17.33.18.png

 

 

 

 

TOPICS
Scripting
555
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 2 Correct answers

Community Expert , Oct 04, 2023 Oct 04, 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

...
Translate
Community Expert , Dec 13, 2023 Dec 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-
...
Translate
Community Expert ,
Oct 04, 2023 Oct 04, 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/11...

 

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Dec 12, 2023 Dec 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. 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 12, 2023 Dec 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.)

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Dec 13, 2023 Dec 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...

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 13, 2023 Dec 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Dec 13, 2023 Dec 13, 2023

Screenshot 2023-12-13 at 12.56.20.png

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Dec 13, 2023 Dec 13, 2023

the footnotes itself are at the end of the chapter.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Dec 13, 2023 Dec 13, 2023

Screenshot 2023-12-13 at 12.58.08.pngScreenshot 2023-12-13 at 12.58.22.png

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 13, 2023 Dec 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]
    );
  }
}

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Dec 13, 2023 Dec 13, 2023

Hihi, very much ENDNOTES! I keep calling them all footnotes, but now I hopefully am cured. I am getting an error thoughScreenshot 2023-12-13 at 14.37.56.png.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 13, 2023 Dec 13, 2023

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Dec 13, 2023 Dec 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?

 

 

Screenshot 2023-12-13 at 17.17.39.png

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 13, 2023 Dec 13, 2023
LATEST

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]);
  }
}
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines