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 Alegreya font with PDFLaTeX, and have noticed that the \emph command did not work anymore when nested. To be clearer, this code :

\documentclass{book}
\usepackage{Alegreya}
\begin{document}
Normal text. \emph{Emphasized text.} \emph{Emphasized text including \emph{emphasized} text.}
\end{document}

yields :

Alegreya prevents nested \emph from working properly

instead of the regular nested behaviour (when another or no font is selected) : enter image description here

Any ideas on how to circumvent this problem ?

share|improve this question
    
It's another bug of the Alegreya font metric files: the relevant parameter in the italic font is zero, so LaTeX can't distinguish that the font is italic. –  egreg May 17 at 22:33
    
The most recent update of the Alegreya font didn't fix this but, but solved the other one. When you'll have the new release (it will be in TeX Live 2014), forget about \adjustalegreyaxheight, but the hack remains essentially the same. –  egreg May 22 at 11:52

2 Answers 2

up vote 7 down vote accepted

It's another bug in the metric files for the Alegreya font. None of the italic or slanted fonts has the correct value in \fontdimen1. You can use the same workaround I proposed for How can some eastern European diacritics be correctly displayed with the Alegreya font and pdftex? modified for taking also into account the value in \fontdimen1, but you should file a bug report.

\documentclass{scrbook}
\usepackage[T1]{fontenc}

\DeclareFontFamily{T1}{Alegreya-LF}{}
\newcommand{\adjustalegreyaxheight}{\fontdimen5\font=\fontcharht\font`x }
\newcommand{\adjustalegreyaslant}{\fontdimen1\font=0.25pt }

\makeatletter
\let\Alegreya@@scale\@empty
%%% uncomment the next line if you want to scale the font,
%%% changing the value to what suits you
% \def\Alegreya@@scale{s*[0.9]}%
\makeatother

\DeclareFontShape{T1}{Alegreya-LF}{k}{n}{
      <-> \Alegreya@@scale Alegreya-Black-lf-t1
}{\adjustalegreyaxheight}

\DeclareFontShape{T1}{Alegreya-LF}{k}{it}{
      <-> \Alegreya@@scale Alegreya-BlackItalic-lf-t1
}{\adjustalegreyaxheight\adjustalegreyaslant}

\DeclareFontShape{T1}{Alegreya-LF}{k}{sl}{
      <-> ssub * Alegreya-LF/k/it
}{\adjustalegreyaxheight\adjustalegreyaslant}

\DeclareFontShape{T1}{Alegreya-LF}{b}{n}{
      <-> \Alegreya@@scale Alegreya-Bold-lf-t1
}{\adjustalegreyaxheight}

\DeclareFontShape{T1}{Alegreya-LF}{b}{it}{
      <-> \Alegreya@@scale Alegreya-BoldItalic-lf-t1
}{\adjustalegreyaxheight\adjustalegreyaslant}

\DeclareFontShape{T1}{Alegreya-LF}{b}{sl}{
      <-> ssub * Alegreya-LF/b/it
}{\adjustalegreyaxheight\adjustalegreyaslant}

\DeclareFontShape{T1}{Alegreya-LF}{m}{n}{
      <-> \Alegreya@@scale Alegreya-Regular-lf-t1
}{\adjustalegreyaxheight}

\DeclareFontShape{T1}{Alegreya-LF}{m}{it}{
      <-> \Alegreya@@scale Alegreya-Italic-lf-t1
}{\adjustalegreyaxheight\adjustalegreyaslant}

\DeclareFontShape{T1}{Alegreya-LF}{m}{sl}{
      <-> ssub * Alegreya-LF/m/it
}{\adjustalegreyaxheight\adjustalegreyaslant}

\DeclareFontShape{T1}{Alegreya-LF}{bx}{sl}{
      <-> ssub * Alegreya-LF/b/sl
}{\adjustalegreyaxheight\adjustalegreyaslant}

\DeclareFontShape{T1}{Alegreya-LF}{bx}{n}{
      <-> ssub * Alegreya-LF/b/n
}{\adjustalegreyaxheight}

\DeclareFontShape{T1}{Alegreya-LF}{bx}{it}{
      <-> ssub * Alegreya-LF/b/it
}{\adjustalegreyaxheight\adjustalegreyaslant}

\usepackage{Alegreya}

\begin{document}

Normal text. \emph{Emphasized text.} \emph{Emphasized text including \emph{emphasized} text.}


The x-height: \expandafter\texttt\expandafter{\the\fontdimen5\font}

The height of `x': \expandafter\texttt\expandafter{\the\fontcharht\font`x}

Rodion \^{S}edrin

\u{U}ladz\`{i}m\`{i}r Damarackij

V\^{a}\v{c}\`{e}sla\u{u} Kuzn\^{a}co\u{u} 

\footnotesize

The x-height: \expandafter\texttt\expandafter{\the\fontdimen5\font}

The height of `x': \expandafter\texttt\expandafter{\the\fontcharht\font`x}

Rodion \^{S}edrin

\u{U}ladz\`{i}m\`{i}r Damarackij

V\^{a}\v{c}\`{e}sla\u{u} Kuzn\^{a}co\u{u} 

\end{document}

enter image description here

I've left the bits in the other answer, for completeness.

Explanation

In order to see if a font is slanted, LaTeX examines the parameter \fontdimen1 in the current font. If this is zero, LaTeX assumes it's upright.

More flexible hack

Here is code that should take care of all the four combination (lining/oldstyle, tabular/nontabular) for figures, so that Alegreya can be called with any option.

\documentclass{scrbook}
\usepackage[T1]{fontenc}

%%%%% HACK BEGINS
\def\adjustalegreyaslant{\fontdimen1\font=0.25pt }
\def\adjustalegreyaxheight{}
%%%% remove the following when you have Alegreya
%%%% with the date 2014-01-18 (or later)
\def\adjustalegreyaxheight{\fontdimen5\font=\fontcharht\font`x }

\begingroup\makeatletter
%%% scale option
\let\alegreyascale\@empty
%%% uncomment the next line if you want to scale the font,
%%% changing the value to what suits you
% \def\alegreyascale{s*[0.9]}
%% spaces and end of lines are ignored
\catcode`\ =9 \endlinechar=-1
\newcommand\adjustallalegreyafamilies[2]{
  \def\alegreyasuffix{#1}\def\alegreyainfix{#2}
  \DeclareFontFamily{T1}{Alegreya-\alegreyasuffix}{}
  %
  \DeclareFontShape{T1}{Alegreya-\alegreyasuffix}{k}{n}{
      <-> \alegreyascale Alegreya-Black-\alegreyainfix-t1
  }{\adjustalegreyaxheight}
  %
  \DeclareFontShape{T1}{Alegreya-\alegreyasuffix}{k}{it}{
      <-> \alegreyascale Alegreya-BlackItalic-\alegreyainfix-t1
  }{\adjustalegreyaxheight\adjustalegreyaslant}
  %
  \DeclareFontShape{T1}{Alegreya-\alegreyasuffix}{k}{sl}{
      <-> ssub * Alegreya-\alegreyasuffix/k/it
  }{\adjustalegreyaxheight\adjustalegreyaslant}
  %
  \DeclareFontShape{T1}{Alegreya-\alegreyasuffix}{b}{n}{
      <-> \alegreyascale Alegreya-Bold-\alegreyainfix-t1
  }{\adjustalegreyaxheight}
  %
  \DeclareFontShape{T1}{Alegreya-\alegreyasuffix}{b}{it}{
      <-> \alegreyascale Alegreya-BoldItalic-\alegreyainfix-t1
  }{\adjustalegreyaxheight\adjustalegreyaslant}
  %
  \DeclareFontShape{T1}{Alegreya-\alegreyasuffix}{b}{sl}{
      <-> ssub * Alegreya-\alegreyasuffix/b/it
  }{\adjustalegreyaxheight\adjustalegreyaslant}
  %
  \DeclareFontShape{T1}{Alegreya-\alegreyasuffix}{m}{n}{
      <-> \alegreyascale Alegreya-Regular-\alegreyainfix-t1
  }{\adjustalegreyaxheight}
  %
  \DeclareFontShape{T1}{Alegreya-\alegreyasuffix}{m}{it}{
      <-> \alegreyascale Alegreya-Italic-\alegreyainfix-t1
  }{\adjustalegreyaxheight\adjustalegreyaslant}
  %
  \DeclareFontShape{T1}{Alegreya-\alegreyasuffix}{m}{sl}{
      <-> ssub * Alegreya-\alegreyasuffix/m/it
  }{\adjustalegreyaxheight\adjustalegreyaslant}
  %
  \DeclareFontShape{T1}{Alegreya-\alegreyasuffix}{bx}{sl}{
      <-> ssub * Alegreya-\alegreyasuffix/b/sl
  }{\adjustalegreyaxheight\adjustalegreyaslant}
  %
  \DeclareFontShape{T1}{Alegreya-\alegreyasuffix}{bx}{n}{
      <-> ssub * Alegreya-\alegreyasuffix/b/n
  }{\adjustalegreyaxheight}
  %
  \DeclareFontShape{T1}{Alegreya-\alegreyasuffix}{bx}{it}{
      <-> ssub * Alegreya-\alegreyasuffix/b/it
  }{\adjustalegreyaxheight\adjustalegreyaslant}
}
% execute the above for all four combinations
\adjustallalegreyafamilies{LF}{lf}
\adjustallalegreyafamilies{OsF}{osf}
\adjustallalegreyafamilies{TLF}{tlf}
\adjustallalegreyafamilies{TOsF}{tosf}
\endgroup
%%%%% HACK ENDS
%%%% now you can load the Alegreya package with the desired options
\usepackage[osf]{Alegreya}

\begin{document}

0123456789{\bfseries 0123456789}{\itshape 0123}{\slshape 0123}

Normal text. \emph{Emphasized text.} \emph{Emphasized text including \emph{emphasized} text.}


The x-height: \expandafter\texttt\expandafter{\the\fontdimen5\font}

The height of `x': \expandafter\texttt\expandafter{\the\fontcharht\font`x}

Rodion \^{S}edrin

\u{U}ladz\`{i}m\`{i}r Damarackij

V\^{a}\v{c}\`{e}sla\u{u} Kuzn\^{a}co\u{u} 

\footnotesize

The x-height: \expandafter\texttt\expandafter{\the\fontdimen5\font}

The height of `x': \expandafter\texttt\expandafter{\the\fontcharht\font`x}

Rodion \^{S}edrin

\u{U}ladz\`{i}m\`{i}r Damarackij

V\^{a}\v{c}\`{e}sla\u{u} Kuzn\^{a}co\u{u} 

\end{document}
share|improve this answer
    
I always thought checking \fontdimen1 was an odd way for \em to be implemented; in early XeTeX days this was a frequent problem with poorly-implemented fonts. fontspec patches \em to simply uses the current NFSS shape, which is more reliable. (You probably know that already though.) –  Will Robertson May 23 at 1:54
    
Your solution works, but seems to fail when old style figures are passed as an option to the font, ie. \usepackage[osf]{Alegreya} still prevents the \emph nesting. –  Browaeys May 24 at 1:32
1  
@Browaeys In that case you should use -OsF instead of -LF and -osf- instead of -lf-. I'll try making a more flexible hack. –  egreg May 24 at 9:16

That's odd, it looks like something strange in the font metrics fontdimen1 (the font slant) is set to 0 even for the clearly sloped italic font, so \emph does not recognise it as being a sloped font. You can set it as:

enter image description here

\documentclass{book}
\usepackage{Alegreya}
\begin{document}

{\itshape \fontdimen1\font=.25pt}


Normal text. \emph{Emphasized text.} \emph{Emphasized text including \emph{emphasized} text.}
\end{document}
share|improve this answer
    
This workaround ({\itshape \fontdimen1\font=.25pt}) still works with \usepackage[osf]{Alegreya}. A (very) small caveat is that it does not work within a \title (displayed with \maketitle), as it does using @egreg solution. –  Browaeys May 24 at 1:43

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.