为什么 \usepackage[lighttt]{lmodern} 会将斜体字体更改为倾斜字体?

为什么 \usepackage[lighttt]{lmodern} 会将斜体字体更改为倾斜字体?

使用打字机字体时,我喜欢使用lighttt变体lmodern来获得粗体关键字。问题是它似乎用“倾斜”斜体而不是真正的斜体覆盖了默认的斜体样式。有什么方法可以反转此设置吗?

MWE(有问题):

\documentclass{article}
\usepackage[lighttt]{lmodern}

\begin{document}
\texttt{\textit{Hi there, how are you?}}
\end{document}

MWE(没有问题):

\documentclass{article}
\usepackage{lmodern}

\begin{document}
\texttt{\textit{Hi there, how are you?}}
\end{document}

下面是存在问题的图像(上图)和不存在问题的图像(下图)。 在此处输入图片描述 在此处输入图片描述

答案1

如果我们仔细查看lmodern.sty,就会lighttt发现

\DeclareOption{lighttt}{%
  \let\lmtt@use@light@as@normal\@empty
}

如果我们检查该文件ot1lmtt.fd,我们会发现它有条件地用于设置字体系列:

\ifx\lmtt@use@light@as@normal\@empty
% macro defined, so we use the light variant as medium (m), and
...
\DeclareFontShape{OT1}{lmtt}{sb}{it}
     {<-> rm-lmtti10}{}
\DeclareFontShape{OT1}{lmtt}{sb}{sl}
     {<-> rm-lmtto10}{}
...

因此,当您使用此选项切换到半粗体时,您会获得斜体和倾斜的不同字体。

%%%%%%%% light (l), light condensed (lc), and dark (b) variants:
...
\DeclareFontShape{OT1}{lmtt}{m}{it}
     {<->sub*lmtt/m/sl}{}
\DeclareFontShape{OT1}{lmtt}{m}{sl}
     {<-> rm-lmtlo10}{}
...

但这表明,使用常规粗细时,斜体将代替斜体。我认为这意味着此粗细中没有斜体。匹配粗细的斜体被认为是最佳选择。

\else
% usual setup of variants:
...
\DeclareFontShape{OT1}{lmtt}{m}{it}
     {<-> rm-lmtti10}{}
\DeclareFontShape{OT1}{lmtt}{m}{sl}
     {<-> rm-lmtto10}{}
...

如果没有该lighttt选项,则表示您将获得常规(m)粗细的不同斜体和倾斜字体。

%%%%%%%% light (l), light condensed (lc), and dark (b) variants:
...
\DeclareFontShape{OT1}{lmtt}{l}{it}
     {<->sub*lmtt/l/sl}{}
\DeclareFontShape{OT1}{lmtt}{l}{sl}
     {<-> rm-lmtlo10}{}
...

但是如果你切换到细体(l),你将会再次看到斜体代替了斜体。

因此,技术答案是由于.fd文件中的这些行。但是,这些行这样写的原因是斜体打字机并非在所有重量下都可用。无论是否lighttt可用,包都会在请求时使用斜体(itshape如果可用),否则将替换为倾斜。

答案2

为了避免混淆,如果有帮助的话,在 OpenType 中,在 TT 等宽字体或比例宽度字体中,没有粗体斜体。(/texlive/2022/texmf-dist/fonts/opentype/public/lm/

低分子肝素转移酶

平均能量损失

\documentclass[12pt]{report}
\usepackage{xcolor}
\usepackage{tabularray}
\usepackage{fontspec}
\usepackage{tikz}
\newcommand\balla{\tikz \shade (0,0) circle (1ex);}
\newcommand\ballb{\tikz \shadedraw [shading=ball,ball color=blue!20] (0,0) circle (0.8ex);}
\newcommand\ball{\ballb}


%---
\setmainfont[
Path=C:/.../texlive/2022/texmf-dist/fonts/opentype/public/lm/,
%Extension=.otf,
UprightFont=lmroman12-regular.otf,
BoldFont=lmroman12-bold.otf,
ItalicFont=lmroman12-italic.otf,
BoldItalicFont=lmroman10-bolditalic.otf,
SlantedFont=lmromanslant12-regular.otf,
BoldSlantedFont=lmromanslant10-bold.otf,
SwashFont=lmromandunh10-regular.otf,
%BoldSwashFont=***,
FontFace={m}{swsl}{Font=lmromandunh10-oblique.otf},
FontFace={m}{unsl}{Font=lmromanunsl10-regular.otf},
FontFace={sc}{n}{Font=lmromandemi10-regular.otf},
FontFace={sc}{sl}{Font=lmromandemi10-oblique.otf},
UprightFeatures={
        SmallCapsFont={lmromancaps10-regular.otf},
        },
SlantedFeatures={
        SmallCapsFont={lmromancaps10-oblique.otf},
        },
]{Latin Modern Roman}


\DeclareRobustCommand\scseries{\fontseries{sc}\selectfont}
\DeclareTextFontCommand{\textsc}{\scseries}



\DeclareRobustCommand\swslshape{\fontshape{swsl}\selectfont}
\DeclareTextFontCommand{\textswsl}{\swslshape}
\DeclareRobustCommand\unslshape{\fontshape{unsl}\selectfont}
\DeclareTextFontCommand{\textunsl}{\unslshape}


%-----

\setsansfont[
Path=C:/.../texlive/2022/texmf-dist/fonts/opentype/public/lm/,
%Extension=.otf,
UprightFont=lmsans12-regular.otf,
BoldFont=lmsans10-bold.otf,
%ItalicFont=lmroman12-italic.otf,
%BoldItalicFont=lmroman10-bolditalic.otf,
SlantedFont=lmsans12-oblique.otf,
BoldSlantedFont=lmsans10-boldoblique.otf,
%SwashFont=lmromandunh10-regular.otf,
%BoldSwashFont=***,
FontFace={m}{quot}{Font=lmsansquot8-regular.otf},
FontFace={b}{quot}{Font=lmsansquot8-bold.otf},
FontFace={m}{quotsl}{Font=lmsansquot8-oblique.otf},
FontFace={b}{quotsl}{Font=lmsansquot8-boldoblique.otf},
FontFace={sc}{n}{Font=lmsansdemicond10-regular.otf},
FontFace={sc}{sl}{Font=lmsansdemicond10-oblique.otf},
%UprightFeatures={
%       SmallCapsFont={lmromancaps10-regular.otf},
%       },
%SlantedFeatures={
%       SmallCapsFont={lmromancaps10-oblique.otf},
%       },
]{Latin Modern Sans}

\DeclareRobustCommand\quotshape{\fontshape{quot}\selectfont}
\DeclareTextFontCommand{\textquot}{\quotshape}
\DeclareRobustCommand\quotslshape{\fontshape{quotsl}\selectfont}
\DeclareTextFontCommand{\textquotsl}{\quotslshape}

%---

\setmonofont[
Path=C:/.../texlive/2022/texmf-dist/fonts/opentype/public/lm/,
%Extension=.otf,
UprightFont=lmmono12-regular.otf,
%BoldFont=lmsans10-bold.otf,
ItalicFont=lmmono10-italic.otf,
%BoldItalicFont=lmroman10-bolditalic.otf,
SlantedFont=lmmonoslant10-regular.otf,
BoldSlantedFont=lmsans10-boldoblique.otf,
%SwashFont=lmromandunh10-regular.otf,
%BoldSwashFont=***,
%FontFace={m}{quot}{Font=lmsansquot8-regular.otf},
%FontFace={b}{quot}{Font=lmsansquot8-bold.otf},
%FontFace={m}{quotsl}{Font=lmsansquot8-oblique.otf},
%FontFace={b}{quotsl}{Font=lmsansquot8-boldoblique.otf},
FontFace={lc}{n}{Font=lmmonoltcond10-regular.otf},
FontFace={lc}{sl}{Font=lmmonoltcond10-oblique.otf},
FontFace={l}{n}{Font=lmmonolt10-regular.otf},
FontFace={l}{sl}{Font=lmmonolt10-oblique.otf},
FontFace={lb}{n}{Font=lmmonolt10-bold.otf},
FontFace={lb}{sl}{Font=lmmonolt10-boldoblique.otf},
FontFace={prop}{n}{Font=lmmonoprop10-regular.otf},
FontFace={prop}{sl}{Font=lmmonoprop10-oblique.otf},
FontFace={propl}{n}{Font=lmmonoproplt10-regular.otf},
FontFace={propl}{sl}{Font=lmmonoproplt10-oblique.otf},
FontFace={proplb}{n}{Font=lmmonoproplt10-bold.otf},
FontFace={proplb}{sl}{Font=lmmonoproplt10-boldoblique.otf},
UprightFeatures={
        SmallCapsFont={lmmonocaps10-regular.otf},
        },
SlantedFeatures={
        SmallCapsFont={lmmonocaps10-oblique.otf},
        },
]{Latin Modern Mono}

\DeclareRobustCommand\lcseries{\fontseries{lc}\selectfont}
\DeclareTextFontCommand{\textlc}{\lcseries}
\DeclareRobustCommand\lbseries{\fontseries{lb}\selectfont}
\DeclareTextFontCommand{\textlb}{\lbseries}
\DeclareRobustCommand\lseries{\fontseries{l}\selectfont}
\DeclareTextFontCommand{\textl}{\lseries}

\DeclareRobustCommand\propseries{\fontseries{prop}\selectfont}
\DeclareTextFontCommand{\textprop}{\propseries}
\DeclareRobustCommand\proplseries{\fontseries{propl}\selectfont}
\DeclareTextFontCommand{\textpropl}{\proplseries}
\DeclareRobustCommand\proplbseries{\fontseries{proplb}\selectfont}
\DeclareTextFontCommand{\textproplb}{\proplbseries}



\newcommand\textsample{ABC abc}
\newcommand\textsamplex{--}
\newcommand\textsamplec[1]{\ball~The cat sat on the mat and the Quick Brown Fox jumps over the Lazy Dog. iiiii mmmmm ({\propseries\color{blue}#1}). }


\begin{document}

\rmfamily

rmfamily


\begin{tblr}{
    colspec={Q[l]Q[l]Q[l]Q[l]Q[l]},
    row{odd}={bg=blue!5},
    row{1}={bg=blue!12},
    cell{3}{1}={halign={r},font=\small},
    cell{6}{1}={halign={r},font=\small},
}
Shape 
& Regular
& Bold
& SC-Regular
& SC-Bold
\\
\hline
Upright
& \textsample
& \bfseries \textsample
& \scshape \textsample
& \scshape \textsamplex
\\
Demi
& \textsamplex
& \scseries \textsample
& \scshape \textsamplex
& \scseries \textsamplex
\\
Italic
& \itshape \textsample
& \itshape \bfseries \textsample
& \itshape \textsamplex
& \itshape \bfseries \textsamplex
\\
Slanted
& \slshape \textsample
& \slshape \bfseries \textsample
& \slshape \scshape \textsample
& \slshape \scshape \textsamplex
\\
Demi Slanted
& \slshape \textsamplex
& \slshape \scseries \textsample
& \slshape \scshape \textsamplex
& \slshape \scshape  \textsamplex
\\
Swash
& \swshape \textsample
& \swshape  \textsamplex
& \swshape  \textsamplex
& \swshape  \textsamplex
\\
Swash Slanted
& \swslshape \textsample
& \swslshape  \textsamplex
& \swslshape  \textsamplex
& \swslshape   \textsamplex
\\
Unslanted
& \unslshape \textsample
& \unslshape  \textsamplex
& \unslshape  \textsamplex
& \unslshape   \textsamplex
\\
\end{tblr}


\bigskip
\noindent
{\textsamplec{<rmfamily>}}
{\bfseries\textsamplec{bfseries}}
{\scshape\textsamplec{scshape}}
{\scseries\textsamplec{scseries}}

\bigskip
\noindent 
{\itshape\textsamplec{itshape}}
{\itshape\bfseries\textsamplec{itshape bfseries}}
{\slshape\textsamplec{slshape}}
{\slshape\bfseries\textsamplec{slshape bfseries}}
{\slshape\scshape\textsamplec{slshape scshape}}
{\slshape\scseries\textsamplec{slshape scseries}}


\bigskip
\noindent 
{\swshape\textsamplec{swshape}}
{\swslshape\textsamplec{swslshape}}
{\unslshape\textsamplec{unslshape}}




%%%%%%%%%%%%%%%%%%%%%%%%

\newpage
\sffamily

sffamily


\begin{tblr}{
    colspec={Q[l]Q[l]Q[l]Q[l]Q[l]},
    row{odd}={bg=blue!5},
    row{1}={bg=blue!12},
    cell{3}{1}={halign={r},font=\small},
    cell{6}{1}={halign={r},font=\small},
}
Shape 
& Regular
& Bold
& SC-Regular
& SC-Bold
\\
\hline
Upright
& \textsample
& \bfseries \textsample
&  \textsamplex
& \textsamplex
\\
Demi
& \textsamplex
& \scseries \textsample
&  \textsamplex
& \scseries \textsamplex
\\
Italic
&  \textsamplex
&  \bfseries \textsamplex
&  \textsamplex
&  \bfseries \textsamplex
\\
Oblique
& \slshape \textsample
& \slshape \bfseries \textsample
& \slshape  \textsamplex
& \slshape  \textsamplex
\\
Demi Oblique
& \slshape \textsamplex
& \slshape \scseries \textsample
& \slshape  \textsamplex
& \slshape   \textsamplex
\\
Quot
& \quotshape \textsample
& \quotshape \bfseries \textsample
& \quotshape \textsamplex
& \quotshape \bfseries \textsamplex
\\
Quot Oblique
& \quotslshape \textsample
& \quotslshape \bfseries \textsample
& \quotslshape \textsamplex
& \quotslshape \bfseries \textsamplex
\\
\end{tblr}


\bigskip
\noindent 
{\textsamplec{<sffamily>}}
{\bfseries\textsamplec{bfseries}}
{\scseries\textsamplec{scseries}}

\bigskip
\noindent 
{\slshape\textsamplec{slshape}}
{\slshape\bfseries\textsamplec{slshape bfseries}}
{\slshape\scseries\textsamplec{slshape scseries}}

\bigskip
\noindent 
{\quotshape\textsamplec{quotshape}}
{\quotshape\bfseries\textsamplec{quotshape bfseries}}
{\quotslshape\textsamplec{quotslshape}}
{\quotslshape\bfseries\textsamplec{quotslshape bfseries}}




%--------------------------------------------------
\newpage
\ttfamily

ttfamily

\begin{tblr}{
    colspec={Q[l]Q[l]Q[l]Q[l]Q[l]},
    row{odd}={bg=blue!5},
    row{1}={bg=blue!12},
%   cell{3}{1}={halign={r},font=\small},
%   cell{6}{1}={halign={r},font=\small},
}
Shape 
& Regular
& Bold
& SC-Regular
& SC-Bold
\\
\hline
Upright
& \textsample
&  \textsamplex
&  \scshape \textsample
& \textsamplex
\\
Italic
& \itshape \textsample
&  \textsamplex
&  \textsamplex
&  \textsamplex
\\
Oblique
& \slshape \textsample
& \slshape  \textsamplex
& \slshape  \scshape \textsample
& \slshape  \textsamplex
\\
Light Condensed
& \lcseries \textsample
& \slshape  \textsamplex
& \slshape  \textsamplex
& \slshape   \textsamplex
\\
LC Oblique
& \slshape \lcseries \textsample
& \slshape  \textsamplex
& \slshape  \textsamplex
& \slshape   \textsamplex
\\
Light Upright
&  \lseries \textsample
&  \lbseries \textsample
&   \textsamplex
&    \textsamplex
\\
Light Oblique
& \slshape \lseries \textsample
& \slshape \lbseries \textsample
& \slshape  \textsamplex
& \slshape   \textsamplex
\\
Prop Upright
& \propseries \textsample
&  \propseries \textsamplex
&   \textsamplex
&    \textsamplex
\\
Prop Oblique
& \slshape \propseries \textsample
& \slshape \propseries \textsamplex
& \slshape  \textsamplex
& \slshape   \textsamplex
\\
Prop Lt Upright
&  \proplseries \textsample
&  \proplbseries \textsample
&   \textsamplex
&    \textsamplex
\\
Prop Lt Oblique
& \slshape \proplseries \textsample
& \slshape \proplbseries \textsample
& \slshape  \textsamplex
& \slshape   \textsamplex
\\
\end{tblr}



\bigskip
\noindent 
{\textsamplec{<ttfamily>}}
{\scshape\textsamplec{scshape}}
{\itshape\textsamplec{itshape}}
{\slshape\textsamplec{slshape}}
{\slshape\scshape\textsamplec{slshape scshape}}


\bigskip
\noindent 
{\lcseries\textsamplec{lcseries}}
{\slshape \lcseries\textsamplec{slshape lcseries}}
{\lseries\textsamplec{lseries}}
{\lbseries\textsamplec{lbseries}}
{\slshape\lseries\textsamplec{slshape lseries}}
{\slshape\lbseries\textsamplec{slshape lbseries}}


\bigskip
\noindent 
{\propseries\textsamplec{propseries}}
{\proplseries\textsamplec{proplseries}}
{\proplbseries\textsamplec{lbpropseries}}
{\slshape\propseries\textsamplec{slshape propseries}}
{\slshape\proplseries\textsamplec{slshape proplseries}}
{\slshape\proplbseries\textsamplec{slshape proplbseries}}






\end{document}

相关内容