Coding question
sub @figures space' @numerators by thinspace;
Comments
-
The single quote signifies the target in a contextual substitution (GSUB Lookup Type 5/6 or GPOS Lookup Type 7/8).
1 -
P.S. So the example you posted, then, translates to “when a space glyph is preceded by any member of the @figures class and followed by any member of the @numerators class, it should be replaced by a thinspace glyph.”
1 -
That indicates the target of substitution in a contextual rule.
sub X Y' Z by W # with tick
will replace any string of the form XYZ with XWZ.
Without the tickmark you'd have a ligature replacement rule:sub X Y Z by W # no tick
would simply replace XYZ with W.
Note that the above can also be written assub X' Y' Z' by W # multiple ticks
which makes it clearer that all three elements on the left side of the rule are being replaced.
The rule you give, which I assume is from a 'frac' feature, substitutes spaces with thinspaces but only when they follow a figure and are followed by a numerator.
1 -
Thought it would be something like that. Thanks again!0
-
Only problem is, space isn't exchanged with thinspace in InDesign. When writing 2 1/8 for example. Any ideas why? The fraction part works, though. Here's the code:
(@numr0 being figures and @numr1 being numerators. Thinspace exists in the font and is mapped to uni2009...)feature frac { # Fractions
sub one [slash fraction] two by onehalf;
sub one [slash fraction] four by onequarter;
sub three [slash fraction] four by threequarters;
lookup SlashToFraction {
ignore sub slash @figures @figures @figures @figures @figures @figures @figures @figures @figures @figures slash';
ignore sub slash' @figures @figures @figures @figures @figures @figures @figures @figures @figures @figures slash;
ignore sub slash @figures @figures @figures @figures @figures @figures @figures @figures @figures slash';
ignore sub slash' @figures @figures @figures @figures @figures @figures @figures @figures @figures slash;
ignore sub slash @figures @figures @figures @figures @figures @figures @figures @figures slash';
ignore sub slash' @figures @figures @figures @figures @figures @figures @figures @figures slash;
ignore sub slash @figures @figures @figures @figures @figures @figures @figures slash';
ignore sub slash' @figures @figures @figures @figures @figures @figures @figures slash;
ignore sub slash @figures @figures @figures @figures @figures @figures slash';
ignore sub slash' @figures @figures @figures @figures @figures @figures slash;
ignore sub slash @figures @figures @figures @figures @figures slash';
ignore sub slash' @figures @figures @figures @figures @figures slash;
ignore sub slash @figures @figures @figures @figures slash';
ignore sub slash' @figures @figures @figures @figures slash;
ignore sub slash @figures @figures @figures slash';
ignore sub slash' @figures @figures @figures slash;
ignore sub slash @figures @figures slash';
ignore sub slash' @figures @figures slash;
ignore sub slash @figures slash';
ignore sub slash' @figures slash;
sub @figures slash' @figures by fraction;
} SlashToFraction;
sub @numr0' fraction by @numr1;
sub @numr0' @numr1 fraction by @numr1;
sub @numr0' @numr1 @numr1 fraction by @numr1;
sub @numr0' @numr1 @numr1 @numr1 fraction by @numr1;
sub @numr0' @numr1 @numr1 @numr1 @numr1 fraction by @numr1;
sub @numr0' @numr1 @numr1 @numr1 @numr1 @numr1 fraction by @numr1;
sub @numr0' @numr1 @numr1 @numr1 @numr1 @numr1 @numr1 fraction by @numr1;
sub @numr0' @numr1 @numr1 @numr1 @numr1 @numr1 @numr1 @numr1 fraction by @numr1;
sub @numr0' @numr1 @numr1 @numr1 @numr1 @numr1 @numr1 @numr1 @numr1 fraction by @numr1;
sub @numr0' @numr1 @numr1 @numr1 @numr1 @numr1 @numr1 @numr1 @numr1 @numr1 fraction by @numr1;
sub [fraction @dnom1] @dnom0' by @dnom1;
sub @numr0 space' @numr1 by thinspace;
} frac;
0 -
Your code, second to last line, says
sub @numr0 space' @numr1 by thinspace;
but I think it should besub @figures space' @numr1 by thinspace;
. You say@numr0
is the same as@figures
, but, why do you then use both?0 -
Yeah I know, I don't remember where I got the code from and it may be a mix from different sources, thus the two identical classes with different names. But should it matter, since they both include figures 0-9?0
-
I think you need to separate the different types of changes you want to make into lookups. As it is, by the time the denominators are changed the code can't go back in the string to fix the space.
0 -
Yes, you might be right, Craig. Or could I execute the thinspace before the fraction, like this:
feature frac { # Fractions
sub one [slash fraction] two by onehalf;
sub one [slash fraction] four by onequarter;
sub three [slash fraction] four by threequarters;
sub @figures space' @figures [slash fraction] by thinspace;
lookup SlashToFraction {
ignore sub slash @figures @figures @figures @figures @figures @figures @figures @figures @figures @figures slash';
ignore sub slash' @figures @figures @figures @figures @figures @figures @figures @figures @figures @figures slash;
ignore sub slash @figures @figures @figures @figures @figures @figures @figures @figures @figures slash';
ignore sub slash' @figures @figures @figures @figures @figures @figures @figures @figures @figures slash;
ignore sub slash @figures @figures @figures @figures @figures @figures @figures @figures slash';
ignore sub slash' @figures @figures @figures @figures @figures @figures @figures @figures slash;
ignore sub slash @figures @figures @figures @figures @figures @figures @figures slash';
ignore sub slash' @figures @figures @figures @figures @figures @figures @figures slash;
ignore sub slash @figures @figures @figures @figures @figures @figures slash';
ignore sub slash' @figures @figures @figures @figures @figures @figures slash;
ignore sub slash @figures @figures @figures @figures @figures slash';
ignore sub slash' @figures @figures @figures @figures @figures slash;
ignore sub slash @figures @figures @figures @figures slash';
ignore sub slash' @figures @figures @figures @figures slash;
ignore sub slash @figures @figures @figures slash';
ignore sub slash' @figures @figures @figures slash;
ignore sub slash @figures @figures slash';
ignore sub slash' @figures @figures slash;
ignore sub slash @figures slash';
ignore sub slash' @figures slash;
sub @figures slash' @figures by fraction;
} SlashToFraction;
sub @numr0' fraction by @numr1;
sub @numr0' @numr1 fraction by @numr1;
sub @numr0' @numr1 @numr1 fraction by @numr1;
sub @numr0' @numr1 @numr1 @numr1 fraction by @numr1;
sub @numr0' @numr1 @numr1 @numr1 @numr1 fraction by @numr1;
sub @numr0' @numr1 @numr1 @numr1 @numr1 @numr1 fraction by @numr1;
sub @numr0' @numr1 @numr1 @numr1 @numr1 @numr1 @numr1 fraction by @numr1;
sub @numr0' @numr1 @numr1 @numr1 @numr1 @numr1 @numr1 @numr1 fraction by @numr1;
sub @numr0' @numr1 @numr1 @numr1 @numr1 @numr1 @numr1 @numr1 @numr1 fraction by @numr1;
sub @numr0' @numr1 @numr1 @numr1 @numr1 @numr1 @numr1 @numr1 @numr1 @numr1 fraction by @numr1;
sub [fraction @dnom1] @dnom0' by @dnom1;
} frac;
0 -
Thanks for the links, by the way.
0 -
Jeff Peters said:Or could I execute the thinspace before the fraction0
-
I don’t recommend executing the thinspace substitution before the fractions. Even though you’ve restricted it to a sequence that includes the slash or fraction.The whole purpose of this particular fraction code is to be able to apply the {frac} feature at a global level and have it parse out fractions. That’s why all those ignore subs are written at the beginning, to skip over things like date format.But if you execute your thinspace anywhere but the end (conditioned by the presence of a numerator), then you risk having thin spaces substituted in situations where it is not wanted when the feature is applied broadly. Perhaps rare, but still less desirable.Just mark it for a separate lookup at the end. (Some implementations choose to leave out this option altogether.)In Tal’s original feature code, all of those numerator and the denominator subs were each marked for separate lookups, which is how it all worked without marking the thinspace sub as such. But if you remove those explicit lookup designations (as your code has), then you need to mark the final sub as its own lookup.BTW, Craig’s second link is missing a colon, so it’s broken as of this writing. Here is a corrected link: Fraction Fever 2. And be sure to read the post for the first version of the code, Fraction Fever, which explains a little more about what went into developing this routine and how it works.1
-
Thanks all, I got it working now. Seems it got confused by the two figure classes and the extra lookup also did the trick.0
-
Strictly speaking, you should create a special “space.thin” glyph, to preserve the original text.0
Categories
- All Categories
- 43 Introductions
- 3.7K Typeface Design
- 798 Font Technology
- 1K Technique and Theory
- 617 Type Business
- 444 Type Design Critiques
- 541 Type Design Software
- 30 Punchcutting
- 136 Lettering and Calligraphy
- 83 Technique and Theory
- 53 Lettering Critiques
- 483 Typography
- 301 History of Typography
- 114 Education
- 68 Resources
- 498 Announcements
- 79 Events
- 105 Job Postings
- 148 Type Releases
- 165 Miscellaneous News
- 269 About TypeDrawers
- 53 TypeDrawers Announcements
- 116 Suggestions and Bug Reports