Skip to main content
Inspiring
April 3, 2019
Answered

Finding the number of footnote digits with GREP

  • April 3, 2019
  • 2 replies
  • 2824 views

I want to define a different paragraph style for footnotes of one and two digits (1–99), and footnotes of three digits (in order to increase the separating space for the latter). Can I find the number of digits of a footnote via GREP?

Or is there a better way to this? I aim to have a hanging indent for the footnote number, and then the footnote text aligned. I currently do this with a 5mm indent for the whole style and a -5mm first line indent for the hanging footnote number, which is separated from the text by a tab set to 5mm.

This topic has been closed for replies.
Correct answer Jongware

tntype  wrote

Thanks Chad, a shame that footnotes are still treated like an afterthought in the leading page layout application.

They are not, really. (Actually they are, but for other numerous reasons I could list.) What you are after is equivalent to hoping to find the "2" in an automatic page number "123" -- this Just Won't Happen.

But footnotes can be scripted! The following very quickly written Javascript (so save as "jsx") will apply separate styles to 1-, 2-, and 3-digit footnotes. Make sure the text cursor is inside the story to process before running it.

oneDigitStyle = "one digit note";
twoDigitStyle = "two digit note";
threeDigitStyle = "three digit note";

story = app.selection[0].parentStory;

try {
for (n=1; n<10; n++)
{
  story.footnotes[n-1].texts[0].paragraphs[0].appliedParagraphStyle = oneDigitStyle;
}
for (n=10; n<100; n++)
{
  story.footnotes[n-1].texts[0].paragraphs[0].appliedParagraphStyle = twoDigitStyle;
}
for (n=100; n<1000; n++)
{
  story.footnotes[n-1].texts[0].paragraphs[0].appliedParagraphStyle = threeDigitStyle;
}
} catch (err)
{
/* most likely out of range footnote number, so we don't care */
}

2 replies

Shlomit Heymann
Inspiring
October 20, 2020

Good Morning,

Just found this post, looks exactly what I was looking for but by I have no knowledge in writing scripts.

I tried to copy and paste the script into "ExtendScript Toolkit" app on mac, but I keep get an error. 
"Cannot write to file FootnotesFindDigits.jsx!

IOError: I/O error"

I'm sure i'm doing it all wrong,

 

Can you please help?

Thank you,

Shlomit

 

hammer0909
Community Expert
Community Expert
April 3, 2019

The issue of indenting numbered items always comes down to preference. I understand your issue because when you get to 3 digits, the indent required for a single or even double-digit number often looks odd.

The problem is that the footnote number is a variable of sorts and InDesign doesn't find it as a digit it seems. Even choosing the "include footnotes" option in the GREP Find/Change doesn't find them. Honestly, I think GREP is overkill anyway because it's probably just as quick for you to manually highlight footnote numbers 1-9 and then 10 through 99 and apply a new style to it.

tntypeAuthor
Inspiring
April 4, 2019

Thanks Chad, a shame that footnotes are still treated like an afterthought in the leading page layout application.

Jongware
Community Expert
JongwareCommunity ExpertCorrect answer
Community Expert
April 4, 2019

tntype  wrote

Thanks Chad, a shame that footnotes are still treated like an afterthought in the leading page layout application.

They are not, really. (Actually they are, but for other numerous reasons I could list.) What you are after is equivalent to hoping to find the "2" in an automatic page number "123" -- this Just Won't Happen.

But footnotes can be scripted! The following very quickly written Javascript (so save as "jsx") will apply separate styles to 1-, 2-, and 3-digit footnotes. Make sure the text cursor is inside the story to process before running it.

oneDigitStyle = "one digit note";
twoDigitStyle = "two digit note";
threeDigitStyle = "three digit note";

story = app.selection[0].parentStory;

try {
for (n=1; n<10; n++)
{
  story.footnotes[n-1].texts[0].paragraphs[0].appliedParagraphStyle = oneDigitStyle;
}
for (n=10; n<100; n++)
{
  story.footnotes[n-1].texts[0].paragraphs[0].appliedParagraphStyle = twoDigitStyle;
}
for (n=100; n<1000; n++)
{
  story.footnotes[n-1].texts[0].paragraphs[0].appliedParagraphStyle = threeDigitStyle;
}
} catch (err)
{
/* most likely out of range footnote number, so we don't care */
}