Changing the default series of the sans serif family only

There are a number of issues to solve. The first is that redefining \mddefault in that way will not help, because \mddefault is not executed as part of \sffamily. The second is a traditional puzzle caused by some command being \long in a context and not \long in others.

A possible workaround is to redefine \curr@fontshape, that provides LaTeX with the current font attributes for later processing by NFSS.

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{pdftexcmds}
\renewcommand{\sfdefault}{SourceSansPro-LF}

\makeatletter
\def\curr@fontshape{%
  \f@encoding/\f@family/%
  \ifnum\pdf@strcmp{\f@series}{\mddefault}=\z@
    \ifnum\pdf@strcmp{\f@family}{\sfdefault}=\z@
      l%
    \else
      \f@series
    \fi
  \else
    \f@series
  \fi/\f@shape}
\makeatother

\begin{document}
\sffamily abcdef

\rmfamily abcdef
\end{document}

I used Source Sans Pro because it has the "light" series. More tests are needed if other font attributes need to be changed depending on the current family.

enter image description here


I would use the \DeclareFontShape route. The main problem is that the family (and the encoding) must be known before you can use the command. The easiest way to achieve this is to call the font. So in your example above you can replace the m series by sbc with this commands:

\usepackage{lmodern}
\sffamily %to make lmss known.
\DeclareFontShape{T1}{lmss}{m}{n}{ <-> sub * lmss/sbc/n }{}

You can also make a copy of T1lmss.fd and call it e.g. T1lmssl.fd and then change all lmss to lmssl and the declarations to your liking and then use lmssl as sans serif family.

Tags:

Fonts