]> git.donarmstrong.com Git - lilypond.git/blob - Documentation/usage/updating.itely
Add '-dcrop' option to ps and svg backends
[lilypond.git] / Documentation / usage / updating.itely
1 @c -*- coding: utf-8; mode: texinfo; -*-
2
3 @ignore
4     Translation of GIT committish: FILL-IN-HEAD-COMMITTISH
5
6     When revising a translation, copy the HEAD committish of the
7     version that you are working on.  For details, see the Contributors'
8     Guide, node Updating translation committishes..
9 @end ignore
10
11 @c \version "2.16.0"
12
13
14 @node Updating files with convert-ly
15 @chapter Updating files with @command{convert-ly}
16
17 @cindex Updating a LilyPond file
18 @cindex convert-ly
19
20 As LilyPond is improved, the syntax (input language) of some commands
21 and functions can change.  This can result in unexpected errors,
22 warnings or even wrong output when input files, previously created for older
23 versions of LilyPond are then used with later versions.
24
25 To help with this the @command{convert-ly} command can be used to
26 upgrade these older input files to use the newer syntax.
27
28 @menu
29 * Why does the syntax change?::
30 * Invoking convert-ly::
31 * Command line options for convert-ly::
32 * Problems running convert-ly::
33 * Manual conversions::
34 * Writing code to support multiple versions::
35 @end menu
36
37
38 @node Why does the syntax change?
39 @section Why does the syntax change?
40
41 @cindex convert-ly
42 @cindex updating old input files
43
44 Often, syntax changes are made to make the input simpler to both read
45 and write, but occasionally the changes are made to accommodate new
46 features or enhancements to existing functions.
47
48 To illustrate this here is a real example:
49
50 All @code{\paper} and @code{\layout} property names were supposed to be
51 written in the form @code{first-second-third}.  However, in LilyPond
52 version 2.11.60, it was noticed that the @code{printallheaders} property
53 did not follow this convention.  Should this property be left alone
54 (confusing new users with an inconsistent format)? Or should it be
55 changed (annoying old users with existing LilyPond input files)?
56
57 The decision was made to change the name of the property to
58 @code{print-all-headers}, and by using the @command{convert-ly} command
59 the old users had a way to automatically update their existing input
60 files.
61
62 However, the @command{convert-ly} command cannot always be used to
63 manage all syntax changes.  In versions of LilyPond before 2.4.2,
64 accents and non-English characters were entered using standard LaTeX
65 notation. For example the French word for @q{Christmas} was entered as
66 @code{No\"el}.  But in LilyPond 2.6 onwards, the special @code{ë} must
67 be entered directly as a UTF-8 character.  The @command{convert-ly}
68 command cannot change LaTeX special characters into UTF-8 characters, so
69 older LilyPond input files have to edited manually.
70
71 The conversion rules of the @command{convert-ly} command work using text
72 pattern-matching and replacement (rather than @q{understanding} the
73 context of what it is changing within a given input file).  This has
74 several consequences:
75
76 @itemize @bullet
77 @item
78 The reliability of the conversion depends on the quality of each applied
79 rule set and on the complexity of the respective change.  Sometimes
80 conversions may require additional, manual fixes, so the original input
81 files should be kept for comparison just in case.
82
83 @item
84 Only conversions to newer syntax changes are possible: there are no rule
85 sets to go back to older versions of LilyPond.  So the input file
86 should only be upgraded when older versions of LilyPond are no longer
87 being maintained.  Again, the original input files should be kept just
88 in case; perhaps using version control systems (i.e. Git) to help with
89 maintaining multiple versions of your input files.
90
91 @item
92 LilyPond is quite robust when processing @q{creatively} placed or
93 omitted whitespace, but the rules used by @command{convert-ly} often
94 make some stylistic assumptions.  Therefore following the input style as
95 used in the LilyPond manuals is advised for painless upgrades,
96 particularly as the examples in the manuals themselves are all upgraded
97 using the @command{convert-ly} command.
98 @end itemize
99
100
101 @node Invoking convert-ly
102 @section Invoking @command{convert-ly}
103
104 The @command{convert-ly} command uses the @code{\version} number in
105 the input file to detect older versions.  In most cases, to upgrade your
106 input file it is sufficient just to run;
107
108 @example
109 convert-ly -e myfile.ly
110 @end example
111
112 @noindent
113 in the directory containing the input file.  This will upgrade
114 @file{myfile.ly} in-place and preserve the original file by renaming it
115 @file{myfile.ly~}.  The @code{\version} number in the upgraded input
116 file, along with any required syntax updates, is also changed.
117
118 When run, the @command{convert-ly} command will output the version
119 numbers of which conversions have been made to.  If no version numbers
120 are listed in the output for the file, it is already up to date and
121 using the latest LilyPond syntax.
122
123 @warning{For each new version of LilyPond, a new @command{convert-ly}
124 command is created, however not every version of LilyPond will need
125 syntax changes for its input files from the version before.  This means
126 that the @command{convert-ly} command will only convert input files up
127 to the latest syntax change it has and this, in turn, may mean that the
128 @code{\version} number left in the upgraded input file is sometimes
129 earlier than the version of @command{convert-ly} command itself.}
130
131 To convert all input files in a single directory use;
132
133 @example
134 convert-ly -e *.ly
135 @end example
136
137 Linux and MacOS@tie{}X users can both use the appropriate terminal
138 application, but MacOS@tie{}X users can also execute this command
139 directly under the menu entry @code{Compile > Update syntax}.
140
141 A Windows user would run the command;
142
143 @example
144 convert-ly.py -e *.ly
145 @end example
146
147 @noindent
148 entering these commands in a @code{command prompt} usually found under
149 @code{Start > Accessories > Command Prompt} or for version 8 users,
150 by typing in the search window @q{command prompt}.
151
152 To convert all input files that reside in different sets of
153 subdirectories;
154
155 @example
156 find . -name '*.ly' -exec convert-ly -e '@{@}' \;
157 @end example
158
159 This example searches and converts all input files in the current
160 directory and all directories below it recursively.  The converted files
161 will be located in the same directory along with their renamed
162 originals.  This should also work for MacOS@tie{}X users, although only
163 via the terminal app.
164
165 Windows user would use;
166
167 @example
168 forfiles /s /M *.ly /c "cmd /c convert-ly.py -e @@file"
169 @end example
170
171 Alternatively, an explicit path to the top-level of your folder
172 containing all the sub-folders that have input files in them can be
173 stated using the @code{/p} option;
174
175 @example
176 forfiles /s /p C:\Documents\MyScores /M *.ly /c "cmd /c convert-ly.py -e @@file"
177 @end example
178
179 If there are spaces in the path to the top-level folder, then the whole
180 path needs to be inside double quotes;
181
182 @example
183 forfiles /s /p "C:\Documents\My Scores" /M *.ly /c "cmd /c convert-ly.py -e @@file"
184 @end example
185
186
187
188 @node Command line options for convert-ly
189 @section Command line options for @command{convert-ly}
190
191 The program is invoked as follows:
192
193 @example
194 convert-ly [@var{option}]@dots{} @var{filename}@dots{}
195 @end example
196
197 The following options can be given:
198
199 @table @code
200 @item -d, --diff-version-update
201 increase the @code{\version} string only if the file has actually
202 been changed.  In that case, the version header will correspond to
203 the version after the last actual change.  An unstable version
204 number will be rounded up to the next stable version number unless
205 that would exceed the target version number.  Without this option,
206 the version will instead reflect the last @emph{attempted}
207 conversion.
208
209 @item -e, --edit
210 Apply the conversions direct to the input file, modifying it
211 in-place.  The original file is renamed as @file{myfile.ly~}.  This
212 backup file may be a hidden file on some operating systems.
213 Alternatively, if you want to specify a different name for the
214 upgraded file without using the @code{-e} options default @code{~}
215 appended to the old input file, the output can be redirected instead;
216
217 @example
218 convert-ly myfile.ly > mynewfile.ly
219 @end example
220
221 Windows user would use;
222
223 @example
224 convert-ly.py myfile.ly > mynewfile.ly
225 @end example
226
227 @item -b, --backup-numbered
228 When used with the @samp{-e} option, number the backup files so that
229 no previous version is overwritten.  The backup files may be hidden
230 on some operating systems.
231
232 @item -f, --from=@var{from-patchlevel}
233 Set the version to convert from.  If this is not set,
234 @command{convert-ly} will guess this, on the basis of @code{\version}
235 strings in the file. E.g. @option{--from=2.10.25}
236
237 @item -h, --help
238 Print usage help.
239
240 @item -l @var{loglevel}, --loglevel=@var{loglevel}
241 Set the output verbosity to @var{loglevel}. Possible values, in upper
242 case, are @code{PROGRESS} (the default), @code{NONE}, @code{WARNING},
243 @code{ERROR} and @code{DEBUG}.
244
245 @item -n, --no-version
246 Normally, @command{convert-ly} adds a @code{\version} indicator
247 to the output.  Specifying this option suppresses this.
248
249 @item -s, --show-rules
250 Show all known conversions and exit.
251
252 @item -t, --to=@var{to-patchlevel}
253 Explicitly set which @code{\version} to convert to, otherwise the
254 default is the most current value.  It must be higher than the
255 starting version.
256
257 @example
258 convert-ly --to=2.14.1 myfile.ly
259 @end example
260
261 @end table
262
263 To upgrade LilyPond fragments in texinfo files, use
264
265 @example
266 convert-ly --from=@dots{} --to=@dots{} --no-version *.itely
267 @end example
268
269 To see the changes in the LilyPond syntax between two versions, use
270
271 @example
272 convert-ly --from=@dots{} --to=@dots{} -s
273 @end example
274
275
276 @node Problems running convert-ly
277 @section Problems running @code{convert-ly}
278
279 When running convert-ly in a Command Prompt window under Windows
280 on a file which has spaces in the filename or in the path to it,
281 it is necessary to surround the entire input file name with three
282 (!) sets of double quotes:
283
284 @example
285 convert-ly """D:/My Scores/Ode.ly""" > "D:/My Scores/new Ode.ly"
286 @end example
287
288 If the simple @command{convert-ly -e *.ly} command fails because the
289 expanded command line becomes too long, the @command{convert-ly}
290 command may be placed in a loop instead.  This example for UNIX
291 will upgrade all @file{.ly} files in the current directory
292
293 @example
294 for f in *.ly; do convert-ly -e $f; done;
295 @end example
296
297 In the Windows Command Prompt window the corresponding command is
298
299 @example
300 for %x in (*.ly) do convert-ly -e """%x"""
301 @end example
302
303 Not all language changes are handled.  Only one output option can be
304 specified.  Automatically updating scheme and LilyPond scheme
305 interfaces is quite unlikely; be prepared to tweak scheme code
306 manually.
307
308
309 @node Manual conversions
310 @section Manual conversions
311
312 In theory, a program like @command{convert-ly} could handle any
313 syntax change.  After all, a computer program interprets the old
314 version and the new version, so another computer program can
315 translate one file into another@footnote{At least, this is
316 possible in any LilyPond file which does not contain scheme.  If
317 there is scheme in the file, then the LilyPond file contains a
318 Turing-complete language, and we run into problems with the famous
319 @qq{Halting Problem} in computer science.}.
320
321 However, the LilyPond project has limited resources: not all
322 conversions are performed automatically.  Below is a list of known
323 problems.
324
325
326 @verbatim
327 1.6->2.0:
328  Doesn't always convert figured bass correctly, specifically things like {<
329 >}.  Mats' comment on working around this:
330    To be able to run convert-ly
331    on it, I first replaced all occurrences of '{<' to some dummy like '{#'
332    and similarly I replaced '>}' with '&}'.  After the conversion, I could
333    then change back from '{ #' to '{ <' and from '& }' to '> }'.
334  Doesn't convert all text markup correctly.  In the old markup syntax,
335  it was possible to group a number of markup commands together within
336 parentheses, e.g.
337    -#'((bold italic) "string")
338    This will incorrectly be converted into
339    -\markup{{\bold italic} "string"}
340    instead of the correct
341    -\markup{\bold \italic "string"}
342 2.0->2.2:
343  Doesn't handle \partcombine
344  Doesn't do \addlyrics => \lyricsto, this breaks some scores with multiple
345 stanzas.
346 2.0->2.4:
347  \magnify isn't changed to \fontsize.
348     - \magnify #m => \fontsize #f, where f = 6ln(m)/ln(2)
349  remove-tag isn't changed.
350     - \applyMusic #(remove-tag '. . .) => \keepWithTag #'. . .
351  first-page-number isn't changed.
352     - first-page-number no => print-first-page-number = ##f
353  Line breaks in header strings aren't converted.
354     - \\\\  as line break in \header strings => \markup \center-align <
355       "First Line" "Second Line" >
356  Crescendo and decrescendo terminators aren't converted.
357     - \rced => \!
358     - \rc => \!
359 2.2->2.4:
360  \turnOff (used in \set Staff.VoltaBracket = \turnOff) is not properly
361 converted.
362 2.4.2->2.5.9
363  \markup{ \center-align <{ ... }> } should be converted to:
364  \markup{ \center-align {\line { ... }} }
365  but now, \line is missing.
366 2.4->2.6
367  Special LaTeX characters such as $~$ in text are not converted to UTF8.
368 2.8
369  \score{} must now begin with a music expression.  Anything else
370  (particularly \header{}) must come after the music.
371 @end verbatim
372
373 @node Writing code to support multiple versions
374 @section Writing code to support multiple versions
375
376 In some cases, especially when writing @emph{library} code it is desirable
377 to support multiple LilyPond versions across breaking syntax changes.  To
378 do this alternative portions of code can be wrapped into conditional
379 expressions depending on the currently executed LilyPond version.  The
380 Scheme function @code{ly:version?} expects a comparison operator @var{op}
381 and a reference version @var{ver} passed as a list of integers with up to
382 three elements.  Missing elements are ignored so @code{'(2 20)} is
383 equivalent to @emph{any} version of the 2.20 line of versions.
384 Constructs like the following are possible:
385
386 @verbatim
387 #(cond
388   ((ly:version? > '(2 20))
389    (ly:message "This is code to run for LilyPond after 2.20"))
390   ((ly:version? = '(2 19 57))
391    (ly:message "This will only be executed with LilyPond 2.19.57"))
392   (else (ly:message "This will be executed in any other version")))
393 @end verbatim
394
395 Usually this will be integrated in library functions to allow alternative
396 syntax to be used, but it is also possible to use the comparison directly
397 within the music like in the following example:
398
399 @verbatim
400 {
401   c' d' e' f'
402   #(if (ly:version? = '(2 21))
403        #{ \override NoteHead.color = #red #}
404        #{ \override NoteHead.color = #blue #})
405   g' a' b' c''
406 }
407 @end verbatim
408
409 @strong{Note:} This function has been introduced in LilyPond 2.19.57, so
410 it is not possible to compare with versions earlier than that.