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

strange size selection for italic with \setmainfont{Latin Modern Roman} after using \slshape #486

Open
cabohah opened this issue Jun 24, 2023 · 10 comments

Comments

@cabohah
Copy link

cabohah commented Jun 24, 2023

When a LuaLaTeX document with base font size 12pt and \setmainfont{Latin Modern Roman} switches to \slshape and than switches to \itshape the italic text is printed smaller.

\documentclass[12pt]{report}

\usepackage{fontspec}
\setmainfont{Latin Modern Roman}

\begin{document}
Some text.

\itshape Some italic text with correct size.

\normalfont\slshape Some slanted text.

\normalfont\itshape Some italic text, which is smaller without using any fontsize command.

\end{document}

Results in:

smaller second italic text

As you can see, the fourth line is printed smaller than the second, which should not happen.

See also https://tex.stackexchange.com/q/689449/277964 where the issue has been reported first.

@u-fischer
Copy link
Member

you get a font warning in the log:

LaTeX Font Info:    Font shape `TU/LatinModernRoman(0)/m/sl' in size <12> not available
(Font)              Font shape `TU/LatinModernRoman(0)/m/it' tried instead on input line 211.

I don't know if fontspec could catch that, but you can avoid it by setting the slantedfont explicitly

\documentclass[12pt]{report}

\usepackage{fontspec}

\setmainfont{Latin Modern Roman}[SlantedFont=LatinModernRoman/I]

\begin{document}
Some text.

\itshape Some italic text with correct size.

\normalfont\slshape Some slanted text.

\normalfont\itshape Some italic text, which is smaller without using any fontsize command.

\end{document}

@cabohah
Copy link
Author

cabohah commented Jun 24, 2023

I've seen the Font Info, but IHMO an automatic font replacement should not change the size of another font, i.e., not if that other font already has been used with the correct size.

On TeX.Stackexchange (see the link above) I've also already commented, that either setting ItalicFont or SlantedFont explicitly, fixes the problem. But IMHO this is suboptimal. I would maybe understand, if the SlantedFont would have been in the wrong size. But that selecting slanted breaks the italic font is unexpected not only for me, but IMHO for the average user.

@wspr
Copy link
Collaborator

wspr commented Apr 29, 2024

I don't fully understand what is happening here, but I agree it's not good!

@FrankMittelbach
Copy link
Member

It looks to me as if the source of the trouble is this NFSS macro

\def\do@subst@correction{%
       \xdef\subst@correction{%
          \font@name
          \global\expandafter\font
            \csname \curr@fontshape/\f@size\endcsname
            \noexpand\fontname\font
           \relax}%
       \aftergroup\subst@correction
}

Its long long time ago but the code attempts to reset the display name in something like \showoutput for the the font that was the source of of the of the substitution, if I remember correctly (the docs are somewhat sketchy).

If an external font was used with two \font declarations then TeX would always reports the last macro as the font selector and the \do@subst@correction was correcting that, ie avoiding that with

\documentclass{article}

\begin{document}

foo

\font\xxx=cmr10

bar

\showoutput
\end{document}

you still see \OT1/cmr/m/n/10 and not suddenly \xxx (the font shape that was subsituted to also mean cmr10) all over the place.

Obviously, this seems to fails with fontspec when (as @u-fischer pointed out to me) fonts with optical sizes are involved.
@zauguin any thoughts from your end?

@FrankMittelbach
Copy link
Member

FrankMittelbach commented Apr 29, 2024

By the way, the problem is luatex specific, with XeTeX the \do@subst@correction code behaves correctly.

@u-fischer
Copy link
Member

The problem is that with fonts with optical sizes \fontname\font doesn't give back the size:

\input{luaotfload.sty}
\font\test={name:LatinModernRoman:mode=node;script=latn;language=dflt;+tlig;} at 12pt
\test aaa

\immediate\write17{\fontname\font}

\font\testB = \fontname\font \testB 
aaa

\font\test={name:arial:mode=node;script=latn;language=dflt;+tlig;} at 12pt
\test aaa

\immediate\write17{\fontname\font}

\font\testB = \fontname\font \testB 
aaa
\bye

types out

name:LatinModernRoman:mode=node;script=latn;language=dflt;+tlig;
name:arial:mode=node;script=latn;language=dflt;+tlig; at 12.0pt

and the "reused" font are smaller for latin modern:

image

Imho that is something that should be handled by luaotfload.

@zauguin
Copy link
Member

zauguin commented Apr 29, 2024

Does anyone see an issue with just always adding the size in \fontname and other places by claiming a designsize of 0?

@FrankMittelbach
Copy link
Member

Well, what is important is basically a way to be able feed in the result of \fontname\font into a a font declaration and this way produce that same font selector again, sort of

...currently in some font ...
\edef\foo{\fontname\font}
...
\font\xxx=\foo\relax

Now \xxx should produce the same fontselector (with the same size) as we started with.

I would be possible to do this on the macro level (given that we know the \f@size), via

\edef\foo{\fontname\font\space at \f@size pt}

but that would badly fail if the font does already has some at...pt
so the code would need to analyse the result and append only if necessary (but that is fixing a problem that shouldn't be there in the first place).

So it would be much better if \fontname really contains what it should, which is data that allows for the roundtrip. pdfTeX and XeTeX do while luatex doesn't. Not sure if this is a bug in the primitive or if there is no primitive in luaTeX and the data is produced by luaotfload ... in either case I think it should be correct at the engine/luaotfload side.

If pretending a design size of 0 does the trick I don't know.

@zauguin
Copy link
Member

zauguin commented May 1, 2024

I now implemented the "design size 0" approach in luaotfload's dev branch, so far it looks like it's working.

@FrankMittelbach
Copy link
Member

FrankMittelbach commented May 1, 2024

sounds good @zauguin! much better if this works out of the box rather than having to analyze the return value of \fontname and try to correct it on macro level.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants