Copy link to clipboard
Copied
I want to put the line number on the left of my paragraphs (every 5 lines). Is it possible to do it and apply it with a style?
Copy link to clipboard
Copied
There is no way to do that built into InDesign. It would probably require scripting (I'm not a scripter). Maybe someone has a script which could do that.
Copy link to clipboard
Copied
I saw Nigel French set up a variation of this in a MAX presentation. He added line numbers manually to the left and right margins on the parent pages, so that they were visible on all body pages. I suspect he put them on their own layer to control visibllity. Each page restarted with one, of course, and thinking about it, a baseline grid would be necessary, otherwise the alignment would be off after headings.
FrameMaker has an automatic line numbering feature. When I walked into that session and saw this on the overhead projector, I initially thought it was a new (and welcome) feature in InDesign.
~Barb
Copy link to clipboard
Copied
With automatic numbering in a seperate text frame, I wonder if a GREP (or a find/replace) could format multiple of 5 in 'visible' ink (character style 1), then any other number with 'None' ink (character style 2).
Copy link to clipboard
Copied
Thgis script seems to do what you are looking for:
https://www.id-extras.com/products/line-numbers/
or this one:
Copy link to clipboard
Copied
Hi @bRschmid , Also, if one the scripts @jmlevy linked to doesn’t work for you select the text you want to add line numbers to and try this:
var doc = app.activeDocument;
var s = doc.selection[0];
//Script needs a range of text to be selected
if (s.constructor.name == "TextColumn" || s.constructor.name == "Text" || s.constructor.name == "Paragraph" ) {
//allow an undo
app.doScript(numberLines, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, 'Number Lines');
} else {
alert("Please Select More Than One Line of Text")
}
/**
* Numbers every fifth line of the text selection
*
*/
function numberLines(){
app.scriptPreferences.measurementUnit = MeasurementUnits.POINTS;
//the number’s Paragraph style
var nStyle = makeParaStyle(doc, "LineNumbers")
nStyle.properties = {pointSize:9, justification:Justification.RIGHT_ALIGN, appliedFont:s.lines[0].appliedFont}
var nl = "LineNo"
var ntf = doc.textFrames.everyItem().getElements()
for (var n = 0; n < ntf.length; n++){
if (ntf[n].label == nl) {
ntf[n].remove()
}
};
var ln = s.lines.everyItem().getElements()
var x2, y2, nf;
for (var i = 0; i < ln.length; i++){
if (i%5 == 4) {
x2 = ln[i].horizontalOffset-10;
y2 = ln[i].baseline;
nf = s.parentTextFrames[0].parentPage.textFrames.add ({
label: nl,
geometricBounds: [y2-20,x2-20,y2,x2],
contents: (i+1).toString(),
textFramePreferences:{verticalJustification:VerticalJustification.BOTTOM_ALIGN}});
nf.texts[0].appliedParagraphStyle = nStyle;
}
};
app.scriptPreferences.measurementUnit = AutoEnum.AUTO_VALUE;
}
/**
* Makes a new named ParagraphStyle
* @ param the document to add the style to
* @ param style name
* @ return the new paragraph style
*/
function makeParaStyle(d, n){
if (d.paragraphStyles.itemByName(n).isValid) {
return d.paragraphStyles.itemByName(n);
} else {
return d.paragraphStyles.add({name:n});
}
}
Does this, the numbers get a Paragraph Style named Line Numbers
Copy link to clipboard
Copied
Thanks a lot! I'll try that!
Copy link to clipboard
Copied
Here it is as saved .jsx file:
https://shared-assets.adobe.com/link/3007620c-3a68-4ee2-707e-f56d767fa666
Copy link to clipboard
Copied
Will try my best to describe it - others are more than welcome to jump in and clarify it.
You can create 2x ParaStyles - 1st visible and 2nd invisible - with Numbering, same level.
Then create narrow TextFrame on the Master.
Override it on the normal page.
Hit Enter 5x times.
Apply 1st ParaStyle to 1st paragraph, then 2nd to 2-4.
Select all text in this TextFrame, Ctrl+C and few times Ctrl+V - then reflow it to the next page - and so on.
Copy link to clipboard
Copied
What exactly do you want?
A) Number only the lines with text? OR
B) Number all lines on the page?
So the version on the left in the screenshot - or the version on the right?
Also:
May only the "5s" appear in the document because invisible characters are not desired in the output? Or would invisible characters be possible in general?