]> git.donarmstrong.com Git - lilypond.git/blob - input/lsr/adding-the-current-date-to-a-score.ly
e74bd664d57e1849f42286c746b9a14236e9d066
[lilypond.git] / input / lsr / adding-the-current-date-to-a-score.ly
1 %% Do not edit this file; it is auto-generated from LSR!
2 %% Tags: titles
3 \version "2.11.35"
4
5 \header { texidoc = "
6 I often find it useful to include a date on printed music, so that I
7 can see if I'm using the latest version, or tell someone else that he
8 should only use the version after a certain date. A simple solution is
9 to enter the date manually to the @code{.ly} file. But that's very
10 error prone. It's easy to forget updating the date. So i thought it
11 would be useful if you can add the date on which the PDF file is
12 generated automatically. I did't figure it out myself, but I asked on 
13 lilypond-user@gnu.org. And guess what? Someone came with an excellent
14 solution! So thank you very much Toine Schreurs for sending this
15 solution to the user mailing list. I post it here for future reference.
16
17 The solution is to use two scheme functions called @code{strftime} and
18 @code{localtime}, as shown in the snippet. It is a very flexible
19 solution, you can format the date just as you like it by adapting the
20 @code{\"%d-%m-%Y\"} string. See the Guile documentation for more
21 details on this format string: Formatting Calendar Time.
22 " }
23 % begin verbatim
24 \version "2.11.35"
25 % first, define a variable to hold the formatted date:
26 date = #(strftime "%d-%m-%Y" (localtime (current-time)))
27
28 % use it in the title block:
29 \header {
30   title = "Including the date!"
31   subtitle = \date
32 }
33 % begin verbatim
34 \score {
35   \relative c'' {
36     c4 c c c
37   }
38 }
39 % and use it in a \markup block:
40 \markup {
41   \date
42 }