Use GREP to Put In Footnote Reference
Learn / Forums / General InDesign Topics / Use GREP to Put In Footnote Reference
- This topic has 10 replies, 4 voices, and was last updated 7 years, 7 months ago by Emiel Stegeman.
-
AuthorPosts
-
-
March 17, 2016 at 7:09 am #82993Ari SingerMember
Hi, I received a Microsoft Word file created by an amateur, and instead of creating real footnotes it was faked. So the body copy is full of fake footnote references and at the bottom there are the fake footnote copy. (Shudder…)
So I’m trying to use GREP to help me out in automatically finding every instance of a fake reference in the body copy and replacing it with a real footnote reference. So the Find What part was easy, as all the fake references are enclosed in square brackets I just searched for: [.]
But the problem is in the Change To field, In the flyout menu there’s no such option as entering a footnote reference, so I’m not sure if it’s even possible. But I do know that a lot of GREP codes are not listed in the flyout menu.
So to all GREP experts out there: is it possible to this in GREP?
Thanks in advance!
-
March 17, 2016 at 7:14 am #82995Peter KahrelParticipant
You can’t do that with Find/Change: because the footnotes don’t exist as InDesign footnotes, you’ll have to create them. Manually, you’s go to the text of footnote 1, cut it, go to the reference [1], delete that, and add a footnote, pasting the text you cut earlier. All that could be scripted, but it’s not trivial.
Peter
-
March 17, 2016 at 9:51 am #83023Ari SingerMember
Thanks. I understood that Find/Change can’t do the entire process (and I wish there would be a script for that), but at least I wanted that Find/Change should at least just enter empty references in the body copy so I don’t have to delete the fake reference and enter a real one manually. Is this possible?
-
March 17, 2016 at 3:20 pm #83050Peter KahrelParticipant
Here is a script that places empty footnotes at the fake footnote references and removes the references:
app.findGrepPreferences = null; app.findGrepPreferences.findWhat = '\\[\\d+\\]'; found = app.activeDocument.findGrep(); for (i = found.length-1; i >= 0; i--) { found[i].insertionPoints[0].footnotes.add(); found[i].remove(); }
What’s left to do is move the fake footnote texts to the real footnote frames at the foot of each frame.
Peter
-
March 17, 2016 at 4:36 pm #83051Ari SingerMember
Thank you so so much for the script! But unfortunately, it’s not working by me. This is the error that pops up:
Error Number: 23
Error String: = does not have a value
…
…
Line: 4
Source: for (i = found.length-1; i >= 0; i–) {
Offending Text: =I do have to clarify that the references are not in numbers, nor alphabets, it’s actually in Hebrew Alphabets. So the GREP code in the script as to be made to work for that, and not only digits.
But this doesn’t seem to be the issue, because I manually entered in one of them a number instead of a Hebrew alphabet to try it out, and it still didn’t work.
But one more curious question: I’m not an expert in GREP, but the code that is written in the script seems strange to have all those backslashes. Isn’t it supposed to be: ‘\[\d=\]’ ?
Thanks for the help!!
-
March 17, 2016 at 5:14 pm #83053Peter KahrelParticipant
That little script works fine on a sample I put together. Your document may have some structure that I’m not aware of, but what the script has to do is simple so I had expected it to work. I also don’t understand the error message, I can’t reproduce it.
If the numbers aren’t always plain digits, and if brackets are used for footnote references only, you could try replacing line 2 with this one:
app.findGrepPreferences.findWhat = '\\[.+?\\]';
As to all the backslashes, to use a basckslash as a literal you have escape it, as the saying goes. Thus, in InDesign’s Find/Change window you’d use
\[.+?\]
, but when you define a string with that GREP, you have to use ‘\\[.+?\\]
‘. If you don’t, and use'\[.+?\]'
, then \[ and \] will be interpreted as special characters, not as the string \[. Compare that with e.g. $: it has a special meaning in GREP (‘end of string’) and in order to use it literally, as a currency symbol, you have to escape it and use \$.Peter
-
August 23, 2016 at 3:59 am #87717Emiel StegemanMember
Dear Peter,
I am completely new to GREP.
Let’s say that I am like Ari’s amateur, using a word processor without footnote options and temporarily formatting footnotes like this.[[Footnote text here]]
Would I replace the ‘\\[\\d+\\]’; with ‘\\[[\\d+\\]]’; and get the same results?
-
-
March 17, 2016 at 5:32 pm #83054Ari SingerMember
I’m so sorry for driving you crazy, it was my mistake! When saving the script in Notepad I forgot to change the seting from ‘Text Document’ to ‘All Files’! Now it works beautifully! Thank you very much!
-
August 24, 2016 at 4:33 pm #87782Peter KahrelParticipant
Emiel,
If your dummy footnotes are formatted [[Abc]] and a footnote should be created with content Abc to replace [[Abc]], then you’d need something like this script:
(function () { var i; var placeholders; var fnote; app.findGrepPreferences = null; app.findGrepPreferences.findWhat = '\\[\\[(.+?)\\]\\]'; placeholders = app.documents[0].findGrep(); for (i = placeholders.length-1; i >= 0; i--) { fnote = placeholders[i].insertionPoints[0].footnotes.add(); placeholders[i].move (LocationOptions.AFTER, fnote.insertionPoints[-1]); } }());
You end up with [[ and ]] in your footnotes, which you can remove with some find/replace operation.
Peter
-
August 25, 2016 at 3:29 am #87795Emiel StegemanMember
Works like a charm, thank you!
(Just don’t apply the script twice in a row, it will also locate the [[text]] that is already in footnotes.)
-
-
August 24, 2016 at 11:50 pm #87793Gert VerreptMember
@Ari: maybe this thread can help you: https://forums.adobe.com/message/6056001#6056001.
We get a lot of fake footnotes from our sources. They all have the same “style” and are at the end of the document preceded by a title “endnotes”.
Maybe, with some adapting, this can be useful. All credits to the creator of the script of course.
-
-
AuthorPosts
- You must be logged in to reply to this topic.