3

This applies to running text, not math or diagrams. I am using TeXlive 2023 on Linux, compiling with lualatex. UTF-8, Left-to-right text, Latin-based letters plus the usual typographic support (I expect this will also apply to Greek and Cyrillic).

If I uderstand how Italics correct \/ works, it dates back to pre-lualatex days, and assumes that the fonts (probably Type 1) each come with tfm support. The value of correction is read from the tfm (it is a binary file). Contemporary OpenType fonts, especially those that are not part of the LaTeX font distribution, do not have that.

Searching here at SE, the only things I found on his topic dated to many years ago, when lualatex was new. Also, those questions involved math.

I imagine that per-character Italic correction could be determined on-the-fly, by reading the final character of a text string, and measuring its height in a box. That does not require Lua code. Depending on the box height, extra space would be added after the Italic string. Thus, letters at X-height would get a different dorrection than letters at X-height (including letters with ascenders). This could also compensate for diacriticals.

The amount of added space could be generic, or specified per-font by the user, or possibly (with Lua support) by measuring the right bearing. But this last method might extend compile time too much?

It might also be possible to look at the next-to-last character, if the last character is period or comma.

MWE showing the measurement, in a Regular font. The \foobar would only contain text, but some of that text might be expandable macros that resolve to text.

\documentclass{article}
\usepackage{fontspec} % If compiling with lualatex
\usepackage{xstring}
\newsavebox\mybox
\begin{document}
\def\foobar{foo bar} % case 1
\StrRight{\foobar}{1}[\barfoo]
\barfoo\savebox\mybox{\barfoo}\the\ht\mybox\typeout{completed case 1}
\def\foobar{f\'o\'o bar\'o} % case 2, correctly gets the final odieresis.
\StrRight{\foobar}{1}[\barfoo]
\barfoo\savebox\mybox{\barfoo}\the\ht\mybox\typeout{completed case 2}
\def\foobar{fo\kern-.5pto bar} % case 3, using kern does not hurt.
\StrRight{\foobar}{1}[\barfoo]
\barfoo\savebox\mybox{\barfoo}\the\ht\mybox\typeout{completed case 3}
\def\foobar{foo\\bar} % case 4, with double-backslash linebreak.
\StrRight{\foobar}{1}[\barfoo]
\barfoo\savebox\mybox{\barfoo}\the\ht\mybox\typeout{completed case 4}
\long\def\foobar{foo\par bar} % case 5, with manual paragraph ending.
\StrRight{\foobar}{1}[\barfoo]
\barfoo\savebox\mybox{\barfoo}\the\ht\mybox\typeout{completed case 5}
\long\def\foobar{foo

bar} % case 6, with double-linespace paragraph.
\StrRight{\foobar}{1}[\barfoo]
\barfoo\savebox\mybox{\barfoo}\the\ht\mybox\typeout{completed case 6}
%\def\foobar{foo\linebreak bar} % Does not work. Not really a problem.
\end{document}

My question: Am I on the right track? Or is there some other method that I do not know about? Or, is this kind of thing already in lualatex ?

Incidentally, I used xstring because I already use that package for many other purposes.

3
  • I don't think the height is really the issue, L might be taller than f but almost certainly f will need a larger italic correction Feb 28 at 18:34
  • 1
    I'd avoid xstring there are usually better, often expandable, functions predefined in latex, in the L3 programming layer. Feb 28 at 18:35
  • @DavidCarlisle Yes, I see that there would be issues with L versus f, and many others. Since I work in a limited character set, it would be possible to fork according to the actual character, rather than its metrics. But your answer, below, shows that none of that is worth pursuing, as the problem is already solved. Also: I use xstring vecuase it is easy to understand, and I have not (yet) have expansion problems. Yet! Will have a look at what L3 does, exentually,
    – rallg
    Feb 28 at 19:28

1 Answer 1

7

Luatex or xetex take the italic correction from the OpenType font metrics and expose them in the same way as etex does with tfm metrics.

luatex shows

> 0.0pt.
l.7 \showthe\fontcharic\font`X
                            
? 
> 0.0pt.
l.9 \showthe\fontcharic\font`L
                            
? 
> 1.02pt.
l.13 \showthe\fontcharic\font`X
                             
? 
> 0.17pt.
l.15 \showthe\fontcharic\font`L
                             
? 

for

\documentclass{article}
\usepackage{fontspec} % If compiling with lualatex

\newsavebox\mybox
\begin{document}

\showthe\fontcharic\font`X

\showthe\fontcharic\font`L

\itshape

\showthe\fontcharic\font`X

\showthe\fontcharic\font`L

\end{document}

showing the italic correction is 0 in the upright font and positive in the italic font (but not closely related to the character height)

If you have the string in a macro and want the final italic correction, you can use \/ and see how much it adds.

\def\foo{abcdef}
\sbox0{\upshape \foo\/\showthe\lastkern}
\sbox0{\itshape \foo\/\showthe\lastkern}

produces

> 0.0pt.
<argument> \upshape \foo \/\showthe \lastkern 
                                   
l.18 \sbox0{\upshape \foo\/\showthe\lastkern}
                                           
? 
> 1.65pt.
<argument> \itshape \foo \/\showthe \lastkern 
                                   
l.19 \sbox0{\itshape \foo\/\showthe\lastkern}
                                           
? 
4
  • Thanks. That's what I really needed to know. It is already done, so no need for me to reinvent the wheel (using wooden wheels). When I searched before asking, what I found was previous to the methods you described above.
    – rallg
    Feb 28 at 19:24
  • @rallg not sure what you mean by previous, but everything I show here has been available in xetex and luatex since they started decades ago Feb 28 at 19:26
  • "Previous" in the sense that I didn't know. Still learning. I usually find information by looking at what others asked or did, and almost all of that involved math-related issues.
    – rallg
    Feb 28 at 19:30
  • The more I look at this, the more I like it. :)
    – rallg
    Feb 29 at 17:51

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .