Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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

share|improve this question
    
This solution doesn't work for me either. –  nnunes Jan 20 '13 at 14:32
    
The encoding is called OT1 not OTl (the number one not the letter l). –  Ulrike Fischer Jan 20 '13 at 14:51
    
@UlrikeFischer yes, sorry, I've now corrected the typo. –  nnunes Jan 20 '13 at 14:54
add comment

2 Answers

up vote 5 down vote accepted

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

share|improve this answer
add comment

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.

share|improve this answer
    
replacing the m series by sbc with those commands in my example still produces the similar LaTeX error, namely Font family: 'T1+lmss unknown'. Following your last suggestion, however, I created a new font definition file and then used \renewcommand\sffamily{<new sf family>}. Many thanks. –  nnunes Jan 21 '13 at 7:25
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.