[Tex/LaTex] Changing the default series of the sans serif family only

fonts

I'm using pdfLaTeX and a sans serif family that supports a light (l) face. I'd like to substitute the default medium (m) face by l only when \sffamily (or \textsf) is called.

In the next example, egreg's solution is only successfull in changing the \mddefault for the roman family, but not for sans serif.

\documentclass{article}

\usepackage[T1]{fontenc}
\usepackage{lmodern}

\makeatletter
\renewcommand{\mddefault}{\ifx\f@family\sfdefault sbc\else bx\fi}
\makeatother

\setlength\parskip{\baselineskip}\setlength\parindent{0pt}

\begin{document}

\textrm{The brown fox jumps over the lazy dog}                 \\
{\usefont{T1}{lmr}{m}{n}The brown fox jumps over the lazy dog} \\ % medium
{\usefont{T1}{lmr}{b}{n}The brown fox jumps over the lazy dog} \\ % bold
{\usefont{T1}{lmr}{bx}{n}The brown fox jumps over the lazy dog}   % bold expanded

\textsf{The brown fox jumps over the lazy dog}                   \\
{\usefont{T1}{lmss}{sbc}{n}The brown fox jumps over the lazy dog}\\ % semi bold condensed
{\usefont{T1}{lmss}{m}{n}The brown fox jumps over the lazy dog}  \\ % medium
{\usefont{T1}{lmss}{bx}{n}The brown fox jumps over the lazy dog}    % bold expanded

\end{document}

enter image description here

Then I tried to use \DeclareFontShape, but I always get the same type of error. For instance, using an example of pg 425 of The LaTeX Companion :

\documentclass{article}

\DeclareFontShape{0T1}{cmss}{m}{it}{ <-> sub * cmss/m/sl }{} 

\begin{document}
text
\end{document}

I get the error:

enter image description here

Best Answer

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