Copy link to clipboard
Copied
I am working on a book of poems. I need to make sure that the (left aligned) text running within each page is centred on the longest line. As far as I am aware there is no mechanism for doing this automatically in inDesign and besides, the optical centre will always be different from the actual centre.
So I need to manually add an indent to every page to indent the text until it feels centred on the page. My problem is that some of the stanzas/paragraphs run between two pages which each need different indentation. I can only apply indent to a whole paragraph, meaning it will effect the beginning of the paragraph on one page and the end on another. If the second page requires a different indent this means the end of the paragraph that has run over from the previous page will indented correctly for the previous page and not the current page or vice-versa.
Is there any sensible solution to this problem?
I've had some good fun setting poetry in the past. Most of it can be scripted. As Ariel and Bill mentioned, each line should be a separate paragraph. Then you can left-align the lines and centre the page on the longest line using the following script:
Select a text frame, then run the script
...if (app.selection.length && app.selection[0] instanceof TextFrame) {
frame = app.selection[0];
longest = Math.max.apply (null, frame.lines.everyItem().endHorizontalOffset);
indent = (frame.geometricBounds[3
Copy link to clipboard
Copied
I can't figure out how to delete this double comment—sorry, folks!
Copy link to clipboard
Copied
Hi there! I'm trying to use this script for a memoir I'm typesetting (with mixed content—some normal paragraph styles, with poems intersperced throughout).
I changed the paragraph style to my own, but when I try to run the script, I'm getting a JavaScript Error:
It seems like something in line 9 is causing the issue and it's probably a simple fix... but this is the ceiling of my JavaScript knowledge. Please help—thank you SO much!
Thanks! Pasting full code below:
/*
0190_PoetryLines_MichelAllio.jsx
based on an orginal code written by Peter Kahrel | See: https://forums.adobe.com/thread/2370094
Written 2017/08/13
*/
app.doScript(main, ScriptLanguage.JAVASCRIPT, [], UndoModes.ENTIRE_SCRIPT, "Poetry Lines! …" );
function main()
{
var myDoc = app.activeDocument,
myPages = myDoc.pages,
P = myPages.length, p;
for ( p = 0; p < P; p++ )
{
var myFrames = myPages[p].allPageItems,
F = myFrames.length, f;
for ( f = 0; f < F; f++ ) {
var myFrame = myFrames[f];
if ( myFrame instanceof TextFrame && myFrame.contents.length > 0 )
{
var longest = Math.max.apply (null, myFrame.lines.everyItem().endHorizontalOffset);
var indent = (myFrame.geometricBounds[3]/2) - (longest/2);
myFrame.lines.everyItem().leftIndent = indent;
}
}
}
var myParas = myDoc.stories.everyItem().paragraphs.everyItem().getElements();
var P = myParas.length, p;
for ( p = 0; p < P; p++ ) myParas[p].appliedParagraphStyle != myDoc.paragraphStyles.item("Poem Body–A (Ljust) START") && myParas[p].clearOverrides();
};
Copy link to clipboard
Copied
FWIW: I marked Peter Kahrel's post from Aug 13, 2017 as the Correct one.
Why? It contains the core code for solving this issue.
Regards,
Uwe Laubender
( ACP )