Use GREP to Put In Footnote Reference

Learn / Forums / General InDesign Topics / Use GREP to Put In Footnote Reference

Tagged: ,

Viewing 7 reply threads
  • Author
    Posts
    • #82993
      Ari Singer
      Member

      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!

    • #82995
      Peter Kahrel
      Participant

      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

    • #83023
      Ari Singer
      Member

      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?

    • #83050
      Peter Kahrel
      Participant

      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

    • #83051
      Ari Singer
      Member

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

    • #83053
      Peter Kahrel
      Participant

      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

      • #87717

        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?

    • #83054
      Ari Singer
      Member

      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!

      • #87782
        Peter Kahrel
        Participant

        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

      • #87795

        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.)

    • #87793
      Gert Verrept
      Member

      @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.

Viewing 7 reply threads
  • You must be logged in to reply to this topic.
>
Notice: We use cookies on our websites to give you a great online experience. If you keep browsing, we'll assume you're ok with this. For more information, see our privacy policy. By closing this banner, you agree to the use of cookies.I AGREENo