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

possibility to set interwordspacetext to the actual space dimension of the font #1036

Closed
eroux opened this issue Mar 15, 2016 · 14 comments
Closed

Comments

@eroux
Copy link
Contributor

eroux commented Mar 15, 2016

It would be very useful to be able to set interwordspacetext to the actual space dimension of the text font. The dimension is in \fontdimen2\font, there should be a simple way to map it on interwordspace, maybe at the beginning of each score... @rpspringuel would you be interested in looking into this?

@rpspringuel
Copy link
Contributor

This should already be possible. Simply use the em or ex unit to set the size of interwordspacetext. Because that space is used in a lyric context, em should be (roughly) the font size (technically the width of the bounding box for M) and ex some fraction thereof (technically the height of the bounding box for x) of the font being used for the lyrics.

Indeed, this was one of the primary goals of storing the dimensions as strings rather than dimensions, so that dimensions set in em and ex would pick up the right font relative sizes at the time of use.

@eroux
Copy link
Contributor Author

eroux commented Mar 16, 2016

Yes, the thing is, I'm not talking about em or ex values, but \fontdimen2, which is the space set by the font itself. I think the way to get this exact amount into interwordspacetext (but setting the plus/minus by hand) would be very useful, maybe just in the tips and tricks section. It should be possible by selecting the font, reading the value, and set it into interwordspacetext, but it certainly implies some \expandafter and \the which are not really obvious...

@eroux
Copy link
Contributor Author

eroux commented Mar 16, 2016

hint: using

\showthe\numexpr((1000*\numexpr(\dimexpr(\the\fontdimen2\font)))/\numexpr(\dimexpr(1em)))\relax

with various fonts, you'll see that you'll obtain different results, a space in libertine in 0.25 em, while in lmodern (the default when using fontspec), it is 0.326 em.

@eroux
Copy link
Contributor Author

eroux commented Mar 16, 2016

Another example (I think these values would make nice defaults):

\documentclass[12pt]{book}
\usepackage{geometry}
\geometry{a5paper}
\usepackage{fontspec}
\usepackage{gregoriotex}
\usepackage{libertine}
\begin{document}

\def\GreStar{*}

\gabcsnippet{(c4) Pro(d)phé(ddo>)tæ(c) pre(d)di(f)ca(e)vé(d)runt(dc~) *() na(f)sci(g) Sal(h>)va(g)tó(f_0fg)rem(f_) (,) de(f) Vír(f)gi(g)ne(e) Ma(f)rí(d.)a.(d.) <eu> (::) E(h) u(h) o(g) u(f) a(gh) e(g) </eu>(::)}

\grechangedim{interwordspacetext}{\the\fontdimen2\font plus \dimexpr((\the\fontdimen3\font)*2) minus \the\fontdimen4\font}{scalable}%
\grechangedim{interwordspacetext@euouae}{\dimexpr((\the\fontdimen2\font) * 8 / 10) plus \dimexpr((\the\fontdimen2\font) * 4 / 10) minus \the\fontdimen5\font}{scalable}%
\grechangedim{interwordspacetext@bars@notext}{\the\fontdimen2\font}{scalable}%
\grechangedim{interwordspacetext@bars@notext@euouae}{\dimexpr((\the\fontdimen2\font)*7/10)}{scalable}%
\grecreatedim{interwordspacetext@bars}{\dimexpr((\the\fontdimen2\font)*7/10)}{scalable}%
\grecreatedim{interwordspacetext@bars@euouae}{\dimexpr((\the\fontdimen2\font)*7/10)}{scalable}%

\gabcsnippet{(c4) Pro(d)phé(ddo>)tæ(c) pre(d)di(f)ca(e)vé(d)runt(dc~) *() na(f)sci(g) Sal(h>)va(g)tó(f_0fg)rem(f_) (,) de(f) Vír(f)gi(g)ne(e) Ma(f)rí(d.)a.(d.) <eu> (::) E(h) u(h) o(g) u(f) a(gh) e(g) </eu> (::)}

\noindent \hbox{Prophétæ predicavérunt * nasci Salvatórem de Vírgine María.}

\end{document}

the only problem is that these values should be reevaluated if the font changes. I'm not sure about the best way to set these as default for any font... I'm not sure it's achievable easily...

@henryso
Copy link
Contributor

henryso commented Mar 16, 2016

This smells like a problem of preventing premature expansion of the macros in the dimension. Any luck with \string or \noexpand?

@eroux
Copy link
Contributor Author

eroux commented Mar 16, 2016

I didn't really try... I don't have much time to spend on the issue, I'll configure this by hand for the big projects

@rpspringuel
Copy link
Contributor

I did some testing and it seems that if I define a macro like so: \def\test{\the\dimexpr\the\fontdimen2\font *2\relax} then \test will evaluate to the twice of \fontdimen2 for the current font, even if I've changed fonts since making the definition. Thus I think that the desired feature is already possible with one possible exception (which I haven't tested yet): the scaling which occurs when \grechangestaffsize is called.

@eroux, do you expect to need to change the staff size after defining a distance in terms of \fontdimen2 (or any of the 7 \fontdimen's)?

I'll do some more testing tomorrow to try and determine the current limits of what is possible here.

@eroux
Copy link
Contributor Author

eroux commented Mar 28, 2016

Thanks a lot for the testing! I don't think it really makes sense to change the staff size in the middle of a document, but in case it doesn't work, it should be documented how to rebuild the distances (maybe just giving their definition again?). Anyway, if it already works that's great! The spaces between words are currently too large, that will make them smaller (maybe a bit too small... we'll see).

@rpspringuel
Copy link
Contributor

After some further testing this is what I have discovered:

  1. In order to use \dimexpr or \glueexpr in setting a distance, you must prepend it by \the. (Incidental, but it does indicate a problem with the example which @eroux posted above.)
  2. Because \grechangedim uses \edef, \grechangedim{interwordspacetext}{\the\fontdimen2\font}{scalable} will result in the interwordspacetext being set based on the font at the time it is called. It will not dynamically resize when the font changes. However, \grechangedim{interwordspacetext}{\unexpanded{\the\fontdimen2\font}}{scalable} prevents \edef from expanding the reference, so the distance will dynamically resize when the font changes. (\unexpanded is an eTeX primitive and thus should be available on all systems on which GregorioTex is usable.)
  3. \grechangestaffsize also uses \edef so if a distance is scalable, changing the staff size will break any link the distance has to a \fontdimen. Unfortunately there is no way to avoid this by inserting an \unexpanded on the user's end: the arguments to which that would need to be applied are determined internally and buried to deep.
  4. Distances which are fixed will not be broken when \grechangestaffsize is called. Given that the distances which are most likely to be linked to a \fontdimen are ones which apply to the text rather than the notes, it is quite possible that one would want those distances to resize based on changes in the text font, not on changes in the staff size. As a result making them fixed relative to the staff size but linked to a \fontdimen (and thus scalable relative to the font size) is likely a reasonable work around.

So, given this information, is there a need to make any changes to the code (apart from changing defaults)? I.e. Is there a need for a distance to be scalable with both the font size and the staff size? I have some ideas for how this could be accomplished, but making it a reality would involve totally rewriting the scaling algorithms, so if there is no need for this feature, then I'd prefer not to undertake that process.

If the way things are is sufficient, then what sort of documentation of this feature is needed? Perhaps a Tips'n'Tricks page on the website? Or should there be something in GregorioRef? Further, do we want to change the default distances related to text in gsp-default.tex to take advantage of this hidden feature in any way?

@eroux
Copy link
Contributor Author

eroux commented Mar 29, 2016

I think it's fine like this, no need to change the code, I don't think there is any case where the distance has to scale with both the staff and the font, so it's perfect that way! Changing the defaults is indeed fine, and documenting the feature in both GregorioRef (this is complex enough to have a small sub*subsection on its own), and gsp-default (in a comment above the first space on which we'll use that) is fine. Thanks a lot for your research!

@rpspringuel
Copy link
Contributor

The documentation for interwordspacetext indicates that the stretch and shrink values are the same as the ones for interwordspacenotes and that they should remain that way. Is there a reason for this or should I just remove said indication?

@eroux
Copy link
Contributor Author

eroux commented Mar 30, 2016

It's important yes, it's linked with #923, the idea is the have the same stretching whatever the enddifference (in one case, the stretching used will be interwordspacetext, in another interwordspacenotes). At least I think so...

@rpspringuel
Copy link
Contributor

Okay. After looking at bit harder at #923, I'm going to punt on that issue for now and just try to wrap this one up as tightly as possible. It means employing another work around to ensure that the stretch/shrink is the same for interwordspacetext and interwordspacenotes, but that work around is easier to do than implementing #923 at the moment (something I don't have the time for right at the moment).

Assuming no unexpected test results, I should be able to create the PR for this issue later tonight or tomorrow morning.

rpspringuel added a commit to rpspringuel/gregorio that referenced this issue Apr 1, 2016
`interwordspacetext` distances are changed to be dependent on the font
Instructions are added to GregorioRef for how the above is accomplished so that the user can do the same.
@rpspringuel
Copy link
Contributor

See #1058.

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

3 participants