Skip to main content
bRschmid
Participant
July 12, 2023
Question

Lines numbering

  • July 12, 2023
  • 6 replies
  • 1542 views

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?

This topic has been closed for replies.

6 replies

pixxxelschubser
Community Expert
Community Expert
July 12, 2023

@bRschmid 

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?

Robert at ID-Tasker
Legend
July 12, 2023

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.

 

rob day
Community Expert
Community Expert
July 12, 2023

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

 

 

bRschmid
bRschmidAuthor
Participant
July 13, 2023

Thanks a lot! I'll try that!

rob day
Community Expert
Community Expert
July 13, 2023
jmlevy
Community Expert
Community Expert
July 12, 2023
Barb Binder
Community Expert
Community Expert
July 12, 2023

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

 

~Barb at Rocky Mountain Training
Eric Dumas
Community Expert
Community Expert
July 12, 2023

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

Steve Werner
Community Expert
Community Expert
July 12, 2023

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.