clip-regions feature - #340
Conversation
|
Thanks for your contribution. Can you translate variable names and comments to English? Also, to test it now with CI, you can add a run for your test file in the make file under target |
…p-regions to Makefile
|
Done! Hope it is correct. |
| -- fsarud: if clip-regions is set: | ||
| if score['clip-regions'] and score['clip-regions'] ~= '' then | ||
| -- Override indent | ||
| local hoffset = score.protrusion or 0 |
There was a problem hiding this comment.
I think you should use potrusion_left as was just fixed now in #337
score.potrusion is always 0, I guess
| for i = 1, score.nsystems do table.insert(score.range, i) end | ||
|
|
||
| -- Remove all intermediate .eps files associated with this hash | ||
| pcall(function() |
There was a problem hiding this comment.
Removing intermediate files should be done by the build system (i.e. latexmk or make), not in the score-setup phase. It kills caching and swallows errors. There's also Score:delete_intermediate_files() already
| @@ -863,6 +993,13 @@ function Score:lilypond_cmd() | |||
| local cmd = shell_quote(self.program) .. ' ' | |||
| .. (self.insert == "fullpage" and "" or "-E ") | |||
There was a problem hiding this comment.
To avoid EPS runs, we must ommit the option -E:
((self.insert == "fullpage" or clip_regions) and "" or "-E ")
And before make the bool available:
local clip_regions = self['clip-regions'] and self['clip-regions'] ~= ''
|
There are still some Spanish comments left and you can also omit the author tags (we use Git blame for that already). In general on the comments, let's try to avoid generating EPS at all if you don't use it. Hope it helps :) |
|
Hi. I reworked |
|
Thanks — this is a genuinely nice piece of work, especially for a first PR. Bypassing the book handler to unlock On your function Score:check_protrusion(bbox_func)
self.range = self:calc_range()
if self.insert ~= 'systems'
or (self['clip-regions'] and self['clip-regions'] ~= '')
then return self:is_compiled() endThere is a hard reason too: On the EPS cleanup — the good news is you don't need it at all. The leftover
So in clip mode we can pass neither One thing that surprised me and deserves a comment in the code: your sort is correct, but it looks wrong. LilyPond walks its system list backwards, so Smaller things:
About the conflict: your branch is fine, it just predates the current master. A plain I have the rebase plus the EPS change on a branch here if you would like me to push it somewhere you can pull from; happy to leave it to you either way. Nice feature — looking forward to having it in. |
|
Thanks a lot! Yours is really a detailed and insightful review! Bypassing On the sort: yes, the way lilypond produces the clips it is rather unusual: first the numbered one(s) in decreasing order, then the unnumbered one. Worth a comment, of course. About the rebase: since you already have the rebase and the EPS adjustment ready on your branch, please feel free to push it to this PR! Then, I will gladly add the remaining user-facing items: lyluatex.md, CHANGES, error handling with warn(), the helper Score:clip_files(), and adding myself to Contributors.md. Thanks again for your guidance and kindness! |
|
I can merge it into main (see #341), but for your fork, you'll have to force reset it to |
Description
This PR adds native support for precise, measure-based score clipping using LilyPond's
-dclip-systemsbackend. This is my first PR ever, so I kindly ask for some indulgence regarding any lack of experience on my part.Previously, users had to rely on
print-only, which compiles the entire score and filters pages. By bypassinglilypond-book-preamble.ly's default book-handler specifically for clips, we are able to unlock LilyPond's native vector clipping system.Usage
\lilypondfile[clip-regions=a-b]{file.ly}where
aandbare the measures of the \score block infile.lythat you wish to clip.The clip is forced to begin a new system, so sequential commands like
\lilypondfile[clip-regions=a-b]{file.ly}and\lilypondfile[clip-regions=c-d]{file.ly}(witha<>corb<>d) will generate two different hashes and compile completely independently of one another .Usage with
ragged-right=trueis highly recommended.Changes Introduced
lilypond-book-preamble.lyinjection insideScore:header()to append#(define default-toplevel-book-handler print-book-with-defaults), allowing-dclip-systemsto work.\consists \Clip_break_engraverandclip-regionsmapping inside the generated\layoutblock.-dclip-systemsflag inScore:lilypond_cmd()only whenclip-regionsis used.set_lyscoreandlatex_includesystemsto dynamically parse, sort, and inject the newly generated*-clip.pdf.clip-regionsuse the.pdf, not the.eps. This logic relies directly on the compiled.pdfvectors instead of the.epsfiles, and the latter are cleaned up to optimize space.Verification
Tested on Arch Linux using TeX Live 2026 and Lilypond 2.26.0. Works for both single-system and multi-system clips.