Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to define left-margin #23

Closed
uliska opened this issue Jan 15, 2018 · 4 comments
Closed

Add option to define left-margin #23

uliska opened this issue Jan 15, 2018 · 4 comments
Assignees

Comments

@uliska
Copy link
Collaborator

uliska commented Jan 15, 2018

With a defined left-margin option in the lilypond-score it will be possible to explicitly align the first barline to the text margin, which is something I'd greatly prefer.

Any value set here should be added to line-width. So a left margin of 0.5cm should add 0.5cm to the line width.

@jperon
Copy link
Owner

jperon commented Jan 15, 2018

I'm not sure I understand very well, but I've no objection !

@uliska
Copy link
Collaborator Author

uliska commented Jan 15, 2018

OK, I see now that it's not that simple and that I need some help from the lilypond-user list, but I can fake an example.

By default LaTeX aligns an image with the left margin of the surrounding text. When suppressing parindent this looks like this:

image

However, I would prefer giving users the possibility (because I would usually do it like this) not to align the border of the image but the first barline and have the system bracket (or whatever brackets are used, maybe even short instrument names) protrude in the left margin like this:

image

For this we have to know (set) the exact width of the left margin of the score and offset the position in the LaTeX file accordingly.

Unfortunately the cropped layout always crops the left margin, so we can't easily retrieve the necessary information (because the actual value dependes on the actual staff organization (a PianoStaff brace over three staves is wider than over two etc.). I'll have to see if there's a way to make LilyPond produce a usable score for this use case.

@uliska
Copy link
Collaborator Author

uliska commented Jan 16, 2018

A clearer description of the problem in the attached PDF.

I think this problem is already touched in the code by defaulting the line width to the text's line width minus 10 pt. But as the elements to the left are of arbitrary width this is not a real solution.

@uliska
Copy link
Collaborator Author

uliska commented Jan 16, 2018

Having asked on lilypond-user I found an answer myself. The solution consists of a number of steps, and I would like to give it a try myself:

  • Add a left-margin option to the score definition
    This must be sufficient to handle all protruding elements and small enough to allow line-width to fit on the paper size.
    It must be given in points (\pt => bp/big points in LaTeX)
  • compile using eps backend (as it already is done)
  • read the first value from the BoundingBox line from the main eps file:
    %%BoundingBox: 27 -209 532 -18 means a value of 27 points
    head -n 3 my-file.eps | tail -n 1 | cut -d " " -f 2 does that
    [Edit: I have implemented it in Lua instead]
  • calculate the offset as left-margin minus that bounding box value
  • When copying the value from the -systems.tex file prepend each entry with \hspace*{-<bb-value>}
  • Make sure there is no parindent. Store the current value in a local variable and restore it after the music

@uliska uliska self-assigned this Jan 16, 2018
uliska added a commit that referenced this issue Jan 17, 2018
Deals with #23

I'm trying to pass a 'margin' value into the lilypond_fragment_header function,
as a first step towards implementing proper alignment of full-width scores.

However, using this code the `left_margin` argument reaching
`lilypond_header_fragment` is not 50 or another value given as option
but `true`.
uliska added a commit that referenced this issue Jan 17, 2018
Deals with #23

This is a first step towards implementing proper alignment with protrusion.
Actually I would prefer being able to pass the margin with arbitrary units
(instead of assuming points). This would also make it possible to calculate
a paper width from line-width plus margin, so the score is guaranteed not
to be cut off on any side.
uliska added a commit that referenced this issue Jan 17, 2018
Deals with #23

This commit includes several changes but I couldn't separate them while
staging.

* add function compile_lilypond_fragment
  separate compilation from the generation of the header
* simplify generation of systems
  - it is sufficient to set the option 'backend to 'eps in the ly_code
  - this makes the handling of the command line option and
    passing the parameter around obsolete
* retrieve the horizontal space that has effectively been cropped
  - determine the proper amount of protrusion in the left margin
    (so far it is only stored in the global variable PROTRUDE
  - NOTE: @jperon this value is read from the file <output>.eps, therefore
    I had to change the lilypond options to -dno-delete-intermediate-files.
    Is that OK?
@uliska uliska mentioned this issue Jan 17, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants