### 2.2.1 Accidental_engraver

Make accidentals. Catch note heads, ties and notices key-change events. This engraver usually lives at Staff level, but reads the settings for Accidental at `Voice` level, so you can `\override` them at `Voice`.

Properties (read)

> `accidentalGrouping` (symbol)

>   If set to `'voice`, accidentals on the same note in different octaves may be horizontally staggered if in different voices.

> `autoAccidentals` (list)

>   List of different ways to typeset an accidental.

>   For determining when to print an accidental, several different rules are tried. The rule that gives the highest number of accidentals is used.

>   Each entry in the list is either a symbol or a procedure.

>   symbol

>     The symbol is the name of the context in which the following rules are to be applied. For example, if context is Score then all staves share accidentals, and if context is Staff then all voices in the same staff share accidentals, but staves do not.

>   procedure

>     The procedure represents an accidental rule to be applied to the previously specified context.

>     The procedure takes the following arguments:

>     `context`

>       The current context to which the rule should be applied.

>     `pitch`

>       The pitch of the note to be evaluated.

>     `barnum`

>       The current bar number.

>     `measurepos`

>       The current measure position.

>     The procedure returns a pair of booleans. The first states whether an extra natural should be added. The second states whether an accidental should be printed. `(#t . #f)` does not make sense.

> `autoCautionaries` (list)

>   List similar to `autoAccidentals`, but it controls cautionary accidentals rather than normal ones. Both lists are tried, and the one giving the most accidentals wins. In case of draw, a normal accidental is typeset.

> `extraNatural` (boolean)

>   Whether to typeset an extra natural sign before accidentals that reduce the effect of a previous alteration.

> `harmonicAccidentals` (boolean)

>   If set, harmonic notes in chords get accidentals.

> `internalBarNumber` (integer)

>   Contains the current barnumber. This property is used for internal timekeeping, among others by the `Accidental_engraver`.

> `keySignature` (list)

>   The current key signature. This is an alist containing `(step . alter)` or `((octave . step) . alter)`, where step is a number in the range 0 to 6 and alter a fraction, denoting alteration. For alterations, use symbols, e.g. `keySignature = #`((6 . ,FLAT))`.

> `localKeySignature` (list)

>   The key signature at this point in the measure. The format is the same as for `keySignature`, but can also contain `((octave . name) . (alter barnumber . measureposition))` pairs.

Properties (write)

> `localKeySignature` (list)

>   The key signature at this point in the measure. The format is the same as for `keySignature`, but can also contain `((octave . name) . (alter barnumber . measureposition))` pairs.

This engraver creates the following layout object(s):

Accidental, AccidentalCautionary, AccidentalPlacement and AccidentalSuggestion.

`Accidental_engraver` is part of the following context(s): GregorianTranscriptionStaff, KievanStaff, MensuralStaff, PetrucciStaff, Staff and VaticanaStaff.

#### Internals Reference v2.18.2 (稳定分支).