[Tex/LaTex] Inconsolata italics

fancyvrbfontsitalic

Please see https://stackoverflow.com/questions/23975828/how-to-specify-non-standard-font-in-fancyvrb-verbatim/ for the start of this discussion.

I am using fancyvrb to create a fancy Verbatim environment. I have

\usepackage{inconsolata}

to load the Inconsolata font, then

\DefineVerbatimEnvironment{VerbOut}
  {Verbatim}{fontfamily=zi4,fontsize=\relsize{-1}}

for the environment itself. I would like it to display in italics, but it appears the inconsolata package doesn't load an italicized version of that font. Is there some other package that does, or some other way I can get it?

Best Answer

The font Inconsolata does not have an italic or slanted variant (June 2014).

Some TeX engines can fake a slanted font, based on a font transformation feature of the PDF format (therefore PDF mode only).

LuaTeX/XeTeX

\documentclass{article}
\usepackage{fontspec}
\setmonofont[
  AutoFakeSlant,
  BoldItalicFeatures={FakeSlant},
]{Inconsolatazi4}

\begin{document}
\ttfamily
Regular
\textbf{Bold}
\textsl{Slanted}
\textit{Italics}
\textbf{\textsl{BoldSlanted}}
\textbf{\textit{BoldItalics}}
\end{document}

Result

The slanted/italic versions are only faked. Also the italics correction is not set.

pdfTeX

A SlantFont operator can be used in the .map file.

The following Perl script zi4-sl.pl reads zi4.map (found via kpsewhich) and modifies the entries:

  • -sl is added to the font (TFM) name,
  • .167 SlantFont is added.

Perl script:

#!/usr/bin/env perl
use strict;
$^W=1;

my $outfile = 'zi4-sl.map';
my $infile = `kpsewhich zi4.map`;
chomp $infile;

open(IN, '<', $infile) or die "!!! Error: Cannot open `zi4.map': $!";
open(OUT, '>', $outfile) or die "!!! Error: Cannot write `$outfile': $!";

while (<IN>) {                                                                  
    next if /^\s*$/;                                       
    s/^([^- ]+)-([^- ]+)/$1-$2-sl/ or die "!!! Error: Cannot parse TFM name!\n";
    s/ " / " .167 SlantFont / or die "!!! Error: Cannot insert SlantFont!\n";
} continue {
    print OUT;
}

close(IN);
close(OUT);
__END__

The following example:

  • includes the map file via \pdfmapfile,
  • defines the font shapes (would go into .fd files normally).
\pdfmapfile{+zi4-sl.map}

\documentclass{article}
\usepackage{inconsolata}

\makeatletter
\sbox0{\ttfamily x}% load .fd file
\expandafter\ifx\csname zifour@scaled\endcsname\relax
  \let\zifour@scaled\@empty
\fi
\expandafter\ifx\csname zifour@opt\endcsname\relax
  \def\zifour@opt{\z@}\def\zifour@altopt{\tw@}
\fi
\DeclareFontShape{\f@encoding}{zi4}{m}{sl}{%
  <-> \zifour@scaled ot1-zi4r-sl-\zifour@opt}{}%
\DeclareFontShape{\f@encoding}{zi4}{m}{it}{%
  <-> ssub * zi4/m/sl}{}
\DeclareFontShape{\f@encoding}{zi4}{b}{sl}{%
  <-> \zifour@scaled ot1-zi4b-sl-\zifour@opt}{}
\DeclareFontShape{\f@encoding}{zi4}{bx}{sl}{%
  <-> ssub * zi4/b/sl}{}
\DeclareFontShape{\f@encoding}{zi4}{b}{it}{%
  <-> ssub * zi4/b/sl}{}
\DeclareFontShape{\f@encoding}{zi4}{bx}{it}{%
  <-> ssub * zi4/b/sl}{}
\makeatother

\begin{document}
\ttfamily
Regular  
\textbf{Bold}
\textsl{Slanted}
\textit{Italics}
\textbf{\textsl{BoldSlanted}}
\textbf{\textit{BoldItalics}}
\end{document}

Finally the TFM files are needed. A poor man's solution is to use the TFM files for the original fonts. The example would need (bash syntax):

cp $(kpsewhich ot1-zi4r-0.tfm) ot1-zi4r-sl-0.tfm
cp $(kpsewhich ot1-zi4b-0.tfm) ot1-zi4b-sl-0.tfm

Result

Again, the slanted and italic variants are only faked. Also the italics correction is missing, but it could be added by editing the .tfm files.

Related Question