4 Replies Latest reply on Sep 28, 2009 3:37 AM by Kasyan Servetsky

    footnotes solution?

    pretendermadafaka Level 1

      i have a plain text in this format:

       

      Yes, of course it is an experiment! But it is made in corpore vili. It
      is not irreparable, and there is no reason, more's the pity, why I
      should not please myself. I will ask--it is a rhetorical question which
      needs no answer--what is a hapless bachelor to do, who is
      professionally occupied and tied down in a certain place for just half
      the year? What is he to do with the other[1] half? I cannot live on in my
      college rooms, and I am not compelled to do so for economy. I have near
      relations and many friends, at whose houses I should be made welcome.
      But I cannot be like the wandering dove, who found no repose. I have a
      great love of my independence and my liberty. I love my own fireside,
      my own chair, my own books, my own way. It is little short of torture
      to have to conform to the rules of[2] other households, to fall in with
      other people's arrangements, to throw my pen down when the gong sounds,
      to make myself agreeable to fortuitous visitors, to be led whither I
      would not. I do this, a very little, because I do not desire to lose
      touch with my kind; but then my work is of a sort which brings me into

       

      [1] footnote

      [2] footnote

       

      (next paragraph)

      would not. I do this, a very little, because I do not desire to lose
      touch with my kind; but then my work is of a sort which brings me into

      etc-etc-etc....

       

       

      and through out the text this goes on...i have plain texts with more then 200+


      (also there is an option where footnotes are at the end of the text, not as this

      case after the paragraph where they are)

       

      thanks for help!

      footnotes..is there a script that can handle import of the footnotes???

        • 1. Re: footnotes solution?
          Kasyan Servetsky Level 5

          Here is a very basic script I wrote for you to illustrate how this can be done. Run it against the attached file.

           

          Kasyan

           

          var myDoc = app.activeDocument;
          app.findTextPreferences = app.changeTextPreferences = null;
          app.findGrepPreferences.findWhat = "\\>\\[\\d+\\]";
          var arr1 = myDoc.findGrep(true);
          app.findGrepPreferences.findWhat = "^\\[\\d\\].+";
          var arr2 = myDoc.findGrep(true);
          var arr2cont = GetContents(arr2);

           

          for (i = 0; i < arr1.length; i++) {
              myFN = arr1[i].parentStory.footnotes.add(LocationOptions.BEFORE, arr1[i].insertionPoints[0], undefined);
              myFN.texts[0].insertionPoints[-1].contents = arr2cont[i].substr(4);
          }

           

          app.findGrepPreferences.findWhat = "^\\[\\d\\].+\\r";
          myDoc.changeGrep();
          app.findGrepPreferences.findWhat = "\\[\\d+\\]";
          myDoc.changeGrep();

           

          function GetContents(myArray) {
              var myContents =[];
              for (i = 0; i < myArray.length; i++) {
                  myContents.push(myArray[i].contents);
              }
              return myContents;
          }

          • 2. Re: footnotes solution?
            pretendermadafaka Level 1

            thanks man! this works great i tried it!

            also i would appreciate if you could teach me how to adopt the script so that it can handle this cases:

             

            in text mark for footnote is [1] and

            actual footnote is like this [footnote 1: some text]

             

            and there is one more case were footnote is embedded into text like this ...text[footnote 1:some text] text text...

             

            thanks again for the effort you put into this...i think others will appreciate as well. thank you.

            • 3. Re: footnotes solution?
              Kasyan Servetsky Level 5

                                                 

              To do what you want you need to change GREP expression:

              app.findGrepPreferences.findWhat = "(\\[footnote\\s?\\d{1,3}:\\s?)(.+)(\\]\\r?)";

               

               

              But this is not enough. From the scant information you provided, I know that footnote text can be a separate paragraph or a range of text in the middle of a paragraph; colon sometimes is followed by space and sometimes not. The text contains 200+ footnotes — so there is a good chance of mistake to happen — e.g. a footnote entrance is missing the corresponding footnote text. Any such mistake may mess things up.

              So I tried to make the script a little fool proofed — now it checks if the corresponding footnote text for the footnote entrance exists before adding footnote.


              var myDoc = app.activeDocument;
              app.findTextPreferences = app.changeTextPreferences = null;
              app.findGrepPreferences.findWhat = "\\[\\d+\\]";
              var arr1 = myDoc.findGrep();
              app.findGrepPreferences.findWhat = "(\\[footnote\\s?\\d{1,3}:\\s?)(.+)(\\]\\r?)";
              var arr2 = myDoc.findGrep();
              var arr2cont = GetContents(arr2);

               

              var myAsArr2 = {};
              for (c = 0; c < arr2.length; c++) {
                  var myIdString = arr2[c].contents;
                  myIdString = myIdString.match(/\d+/);
                  myIdString = "[" + myIdString + "]";
                  myAsArr2[myIdString] = arr2cont[c];
              }

               

              for (j = arr1.length-1; j >= 0 ; j--) {
                  var myAsArr2id = eval("myAsArr2[\"[" + (j+1) + "]\"]");
                  myFN = arr1[j].parentStory.footnotes.add(LocationOptions.BEFORE, arr1[j].insertionPoints[0], undefined);
                  if (myAsArr2id != undefined) {
                      myFN.texts[0].insertionPoints[-1].contents = myAsArr2id;
                  }
                  else {
                      myFN.texts[0].insertionPoints[-1].contents = "Text for this footnote has not been found.";
                  }
              }

               

              app.findGrepPreferences.findWhat =  "\\[\\d+\\]";
              app.changeGrepPreferences.changeTo = "";
              myDoc.changeGrep();
              app.findGrepPreferences.findWhat = "(\\[footnote\\s?\\d{1,3}:\\s?)(.+)(\\]\\r?)";
              myDoc.changeGrep();

               

              alert("Done.");

               

              function GetContents(myArray) {
                  var myContents =[];
                  for (i = 0; i < myArray.length; i++) {
                      var myString = myArray[i].contents;
                      myString = myString.replace(/\[footnote\s?\d+:\s?/, "");
                      myString = myString.replace(/\]/, "");
                      myString = myString.replace(/\r$/, "");
                      myContents.push(myString);
                  }
                  return myContents;
              }

               

              Frankly, I doubt that the script would work as expected with your 'real' document. Because there are lot of conditions that can influence the script and that I'm unaware of yet. And to develop an unfailing script would require much more time then I've already spent.

               

               

              In the future I recommend you to use the following approach — more simple and reliable. Have you text prepared like so:

               

               

              This is the text blabla <footnote text>. This is <footnote text> some other text.

               

               

              All footnotes should be included between brackets (<>).

               

              Then use this script:

               

              app.findGrepPreferences.findWhat = "<.*?>";
              app.changeGrepPreferences.changeTo = "";
              arrFN = app.documents[0].findGrep(true);
               
              for (i=0; i<arrFN.length; i++) {
                  myFN = arrFN[i].parentStory.footnotes.add(LocationOptions.BEFORE, arrFN[i].insertionPoints[0], undefined);
                  myFN.texts[0].insertionPoints[-1].contents = arrFN[i].contents.substr(2);
              }


              app.documents[0].changeGrep();

               

               

              Kasyan

              • 4. Re: footnotes solution?
                Kasyan Servetsky Level 5

                BTW here is another script that may be of interest to you:

                 

                http://forums.adobe.com/thread/459440

                 

                Edit: Oops! This one is for notes — not for footnotes. Sorry.