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

Move more than one paragraph through footnote script

Explorer ,
May 13, 2019 May 13, 2019

Copy link to clipboard

Copied

Hi,

I am working on a document which contains a lot of footnotes with many footnotes having more than one paragraph. Each footnote has a common reference and marker "\[\d+\]". To cite with an example:

Capture.PNG

Footnote 1 text has two paragraphs whereas Footnote 2 text has only one paragraph break.

Thanks to Mr. Kahrel's footnote script (grateful for his effort and time), if the footnote references and texts have the same GREP marker, then, the footnotes can can be placed with the help of the script, however, the script just takes one paragraph break into account.

Kahrel sir's script:

//Footnote

 

 

if (parseFloat(app.version) < 6) 

    main(); 

else 

    app.doScript(main, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, "Footnote"); 

 

function main() { 

var  

    myDoc = app.activeDocument, 

mStory = app.selection[0].texts[0].parentStory, 

    mEndNotes = myDoc.textFrames.add( {name:"EndNotes"} ), 

    k, len, cIP, currPara, currFoot, mMarkers; 

 

app.findGrepPreferences = app.changeGrepPreferences = null; 

//--------------------------------------------- 

// edit doc.footnoteOption here 

with (myDoc.footnoteOptions)  

    { 

    showPrefixSuffix = FootnotePrefixSuffix.PREFIX_SUFFIX_BOTH; 

    prefix = "["; 

    suffix = "]"; 

    separatorText = "\t"; 

    markerPositioning = FootnoteMarkerPositioning.NORMAL_MARKER; 

    } 

//------------------------------------------------------------ 

// move endnotes to a separate textFrame 

for (k=mStory.paragraphs.length - 1; k >=0; k--)  

    { 

    if (mStory.paragraphs.contents.search(/^\[\d+\]/) == 0)  

        { 

        currPara = mStory.paragraphs.move(LocationOptions.AT_BEGINNING, mEndNotes.parentStory); 

        currPara.words[0].remove(); 

        } 

    } 

//-------------------------------------- 

// create footnote markers 

app.findGrepPreferences.findWhat = "\\[\\d+\\]"; 

mMarkers = mStory.findGrep(); 

len = mMarkers.length; 

while (len-->0) { 

    cIP = mMarkers[len].insertionPoints[0].index; 

    mMarkers[len].remove(); 

    mStory.footnotes.add( LocationOptions.AFTER, mStory.insertionPoints[cIP] ); 

    } 

//------------------------------------------------------- 

// fill footnote contents with proper text 

for (k=0; k < mStory.footnotes.length; k++) { 

    currFoot = mStory.footnotes

    mEndNotes.paragraphs[0].texts[0].move(LocationOptions.AT_END, currFoot.texts[0]); 

    if (mStory.footnotes.characters[-1].contents == "\r") mStory.footnotes.characters[-1].remove(); 

    } 

 

mEndNotes.remove(); 

}

Is it possible to tweak the script in such a way that it takes all the paragraph breaks just before the next text marker or if I define a particular paragraph style to the footnote text then, it picks up all the paragraphs having the footnote paragraph style till it finds the next footnote marker?

Result:

Any kind of help/advise would be greatly appreciated.

Thanks & Regards,

Aman Mittal

TOPICS
Scripting

Views

910

Translate

Translate

Report

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
Guide ,
May 14, 2019 May 14, 2019

Copy link to clipboard

Copied

Hi Aman,

Peter's script convert “inline” footnotes into actual footnotes, and what is nice with it is that it does not assume that inline footnotes are grouped at the end of the story. As long as they are properly ordered, they can be anywhere in the stream, as in the below example :

FootnotePatch01.png

But this freedom comes at a price: each inline footnote is specified by a start tag — the [<digits>] stuff — but has no explicit end marker. So, it is supposed to be the entire (single) paragraph containing the tag.

Of course the script could be rewritten to handle a specific end marker and then it could deal with multiple-line footnotes. But maybe there is a simpler way to fix this. Let's keep the single paragraph postulate and use FORCED LINE BREAKS to indicate newlines within a footnote. From then, all we have to do is to add a few lines in the original script so it finally converts forced line breaks into paragraph breaks:

// Add the patch below at the end of the script

// . . .

// fill footnote contents with proper text

for( k=0 ; k < mStory.footnotes.length ; k++ )

{

    currFoot = mStory.footnotes;

    mEndNotes.paragraphs[0].texts[0].move(LocationOptions.AT_END, currFoot.texts[0]);

   

    // Patch: convert \n into \r

    // ===========================

    var tx = mStory.footnotes.texts[0];

    if( tx.characters[-1].contents == '\r' ) tx.characters[-1].remove();

    var s = tx.contents;

    var p = s.length;

    while( -1 != (p=s.lastIndexOf('\n',p-1)) ) tx.characters

.contents = '\r';

    // ===========================

    // End of the patch

}

mEndNotes.remove();   

}

You can then use line breaks to specify multiple paragraphs in a footnote:

FootnotePatch02.png

(I've assumed that you don't need actual forced line breaks in your FNs!)

Hope that helps.

@+

Marc

Votes

Translate

Translate

Report

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 ,
Jul 29, 2019 Jul 29, 2019

Copy link to clipboard

Copied

LATEST

Hello Mr. Marc,

Apologies for the late reply. Have been out for a while that is why, couldn't reply back. Secondly, thank you for taking out the time to reply to the query. Grateful to you! As you rightly pointed out that Mr. Kahrel's script considered forced breaks as characters, and till now, I had been doing the same as well.

Before running the script, I used to convert all the extra paragraph breaks into forced breaks. Then, after running the script I had to find all those forced breaks and turn them back into paragraph breaks. With regard to the assumption, my working method would take care of the required forced breaks for poems and/or other required forced breaks, however, it would lead to time consuming task of converting forced breaks to paragraph breaks for normal paragraphs.

Hence, your contribution to the query would definitely save a lot of time in case of large number of footnotes (500+ or so). In relative terms, the conversion patch shall lead to a more efficient work process.

Thank you so much for all your guidance and expertise. Much appreciated!

Thanks & Regards,

Aman Mittal

Votes

Translate

Translate

Report

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