2.2.9 Bar_number_engraver

A bar number may be created at any bar line, subject to the barNumberVisibility callback. By default, it is put on top of all staves and appears only at the left side of the staff. The staves are taken from stavesFound, which is maintained by Staff_collecting_engraver. This engraver usually creates BarNumber grobs, but when centerBarNumbers is true, it makes CenteredBarNumber grobs instead.

Properties (read)

alternativeNumber (non-negative, exact integer)

When set, the index of the current \alternative element, starting from one. Not set outside of alternatives. Note the distinction from volta number: an alternative may pertain to multiple volte.

alternativeNumberingStyle (symbol)

The scheme and style for numbering bars in repeat alternatives. If not set (the default), bar numbers continue through alternatives. Can be set to numbers to reset the bar number at each alternative, or set to numbers-with-letters to reset and also include letter suffixes.

barNumberFormatter (procedure)

A procedure that takes a bar number, measure position, and alternative number and returns a markup of the bar number to print.

barNumberVisibility (procedure)

A procedure that takes a bar number and a measure position and returns whether the corresponding bar number should be printed. Note that the actual print-out of bar numbers is controlled with the break-visibility property.

The following procedures are predefined:


Enable bar numbers for all bars, including the first one and broken bars (which get bar numbers in parentheses).


Enable bar numbers for all bars (including broken bars) except the first one. If the first bar is broken, it doesn’t get a bar number either.


Enable bar numbers for all bars (including broken bars) except the first one. A broken first bar gets a bar number.


Enable bar numbers for all bars except the first bar and broken bars. This is the default.

(every-nth-bar-number-visible n)

Assuming n is value 2, for example, this enables bar numbers for bars 2, 4, 6, etc.

(modulo-bar-number-visible n m)

If bar numbers 1, 4, 7, etc., should be enabled, n (the modulo) must be set to 3 and m (the division remainder) to 1.

centerBarNumbers (boolean)

Whether to center bar numbers in their measure instead of aligning them on the bar line.

currentBarNumber (integer)

Contains the current bar number. This property is incremented at every bar line.

currentCommandColumn (graphical (layout) object)

Grob that is X-parent to all current breakable items (clef, key signature, etc.).

forbidBreak (boolean)

If set to #t, prevent a line break at this point, except if explicitly requested by the user.

forceBreak (boolean)

Set to #t when an event forcing a line break was heard.

measurePosition (moment)

How much of the current measure have we had. This can be set manually to create incomplete measures.

stavesFound (list of grobs)

A list of all staff-symbols found.

This engraver creates the following layout object(s): BarNumber and CenteredBarNumber.

Bar_number_engraver is part of the following context(s) in \layout: Score and StandaloneRhythmScore.

LilyPond Internals Reference v2.25.18 (development-branch).