Note

Remapping Rest Names in Lilypond

  • lilypond
  • remap
  • rest

Note

Tested with Lilypond 2.24.1

Lilypond offers a high degree of customization for note names, but unfortunately, changing rest names is not as straightforward. Despite extensive searches through the official documentation and the Snippet Repository, I couldn't find a clear solution. Someone also posted a question about this on Reddit, but didn't get a clear answer.

Upon digging into Lilypond's code, I discovered that rest names are hardcoded within the lexer and parser. Therefore, I created a simple patch that remaps the rest names r/R/s to z/Z/x. By compiling Lilypond with this patch applied, I was able to successfully modify the rest names.

diff --git a/lily/lexer.ll b/lily/lexer.ll
index 45550ec298..c18aa07f77 100644
--- a/lily/lexer.ll
+++ b/lily/lexer.ll
@@ -185,7 +185,7 @@ STRICTREAL      {UNSIGNED}\.{UNSIGNED}
 WHITE		[ \n\t\f\r]
 HORIZONTALWHITE		[ \t]
 BLACK		[^ \n\t\f\r]
-RESTNAME	[rs]
+RESTNAME	[zx]
 ESCAPED		[nt\\''""]
 EXTENDER	__
 HYPHEN		--
@@ -401,8 +401,8 @@ FIG_ALT_EXPR	{WHITE}*{FIG_ALT_SYMB}({FIG_ALT_SYMB}|{WHITE})*
 	return CHORD_REPETITION;
 }

-<chords,notes,figures>R/[-_]	| // pseudo backup rule
-<chords,notes,figures>R		{
+<chords,notes,figures>Z/[-_]	| // pseudo backup rule
+<chords,notes,figures>Z		{
         yylval = SCM_UNSPECIFIED;
 	return MULTI_MEASURE_REST;
 }
diff --git a/lily/parser.yy b/lily/parser.yy
index a5e67c9773..1c872e2612 100644
--- a/lily/parser.yy
+++ b/lily/parser.yy
@@ -3785,7 +3785,7 @@ simple_element:
 	}
  	| RESTNAME optional_notemode_duration		{
 		Music *ev = 0;
- 		if (ly_scm2string ($1) == "s") {
+ 		if (ly_scm2string ($1) == "x") {
 			/* Space */
 			ev = MY_MAKE_MUSIC ("SkipEvent", @$);
 		  }