schlcht / microtype

The microtype package
https://ctan.org/pkg/microtype
LaTeX Project Public License v1.3c
81 stars 4 forks source link

OpenType case-senstive forms break microtype's protrusion for hyphens #33

Closed archifont closed 10 months ago

archifont commented 11 months ago

Description

By enabling the OpenType feature case-senstive forms ([Letters=Uppercase]), vertically lifted brackets, hyphens, or parentheses for example) via setmainfont with fontspec, I loose the protrusion for word break hyphen glyphs done by microtype:

\setmainfont[Letters=Uppercase,StylisticSet={02,04}]{ESAllianz}
\microtypesetup{activate={true,nocompatibility},final,babel=true,factor=1000,stretch=20,shrink=20}

Since I use LuaLaTex, I found microtype's documentation the following on page 19:

The situation is different with LuaTeX and XeTeX, however: the default inheritance settings only contain those glyhps that can safely be assumed to exist in any font; but since OpenType fonts may contain many more glyphs for different scripts (languages), it is quite probable that font-specific settings are necessary, which should be specified in the font’s configuration file (see next section).

Indeed, the standard hyphen is replaced by a case-sensitive hyphen (while still being the same character in Unicode: U+002D).

Link to tex.stackexchange.com, but not much output there …

I tried with \DeclareCharacterInheritance{family={ES Allianz}}{\symbol{"002D}=-} Where \symbol{"002D} is the LaTeX command printing a hyphen, to inherit the protrusion settings of a non-uppercase hyphen -.

I also tried font spec's HyphenChar = + to get a plus character, (via XeLaTeX, since LuaLaTeX doesn't support HypenChar), all worked well, but the protrusion of the (changed into the plus sign) hyphen: not protruded.

On to of that, I tried it with other (professionally crafted) fonts as well, same output.

Desired outcome case-sensitive forms in my text, and still correctly protuded hyphens for word breaks.

I tried also to \SetProtrusion{{\symbol{"002D} ={500,500}}}, but that didn't work.

See the images for the difference:

image

↑ without case-sensitive forms, but with correct protrusion for the hyphen.

image

↑ with case-sensitive forms, but without protrusions for the hypen (please take note of the brackets etc that have their case-senstive form now. The period (.) is actually protruded.

schlcht commented 11 months ago

to repeat my comment from TeX.SX: you shouldn't use the command \symbol in the settings, this will never work; instead, just specify the glyph id number (prefixed with " for hexadecimal, or with ' for octal), so in your case: "002D (see microtype.pdf, section 5). (I can't test it though, because I don't have the font.)

archifont commented 11 months ago

Thanks, @schlcht, for your reply. I didn't know you are the same person on TeX.SX and I am very grateful you gave me a reply at all.

I tried to remove \symbol in \DeclareCharacterInheritance, but it also doesn't work.

I can imagine that for all exceptions that are part of an OpenType font a tailored solution can be the only case to solve this for me. And since it is a specific font you don't have, I understand that it is difficult to test.

In a general, non case-sensitive form, I tried this for the capital letter A, unicode glyph id number, hexadecimal, 0041, in the following expression: - \SetProtrusion{encoding={OT1,T1,TS1},family={*},series={*},size={*}}{"0041={1000,1000},} but no extra protrusion for the capital letter A happens in my output. I do not know what I do wrong here, I just put this after the \microtypesetup:

- \UseMicrotypeSet{all}
- \microtypesetup{activate={true,nocompatibility},final,babel=true,factor=1000,stretch=15,shrink=15}
- \SetProtrusion{encoding={OT1,T1,TS1},family={*},series={*},size={*}}{"0041={1000,1000},}

In the case of the case-sensitive forms, the unicode glyph id numbers are the same: Screenshot 2023-10-31 at 13 55 45 Screenshot 2023-10-31 at 13 56 07

As is for the parenthesis: Screenshot 2023-10-31 at 13 57 01 Screenshot 2023-10-31 at 13 57 17

I think I am too unexperienced to get an understanding for this. My desired output is that the case-sensitive forms the used characters protrude as well, when using in the \setmainfont environment Letters=Uppercase as an option.

I hope you can help me!

schlcht commented 11 months ago

You can access the glyphs via their names instead of Unicode numbers; the simplest would probably be to let the case-sensitive forms inherit the values from the regular ones, e.g.:

\DeclareCharacterInheritance
  { encoding = TU,
    family   = ESAllianz }
  { - = /hyphen.case,  % as per your screenshot
    ) = /parenright.case, 
    % ...
  } 

Note that you always have to specify at least one encoding (in the case of lualatex this would be TU). Also note that the asterisk does not stand for any encoding/family/series/shape/size, but for the default ones (I know this is somewhat counter-intuitive...).

Hope this helps!

archifont commented 10 months ago

Thank you so much, @schlcht, for your reply and your time! It works!

Screenshot 2023-11-15 at 15 44 01

The two mistakes I made: not naming the (right) encoding TU, that is clarified now; and using the name of glyph. This is perfect.

I am still learning the right syntaxes for LaTeX/YAML headers to get a, for me, perfect working routine: creating my second brain, notes, and other academic material in Obsidian (Markdown) and, ultimately, convert everything seamlessly via pandoc into shareable, beautiful, and lightweight PDF's. Forgive me my beginner's mistake :–)

Since I am a sucker for typography—and all its quirky details—the microtype package is a truly great pursuing that goal!