9

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?

3 Answers3

11

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.

Heiko Oberdiek
  • 271,626
  • 2
    While I admire the technical wizardry in this answer (+1), I cannot refrain from disparaging the purpose to which it is turned. ;) – cfr Jun 05 '14 at 01:32
  • Hmm, looks like fontspec should also slant the bold font with AutoFakeSlant. Bug added. – Will Robertson Jun 05 '14 at 07:01
  • @cfr It should be noted that it's quite common for font designers to simply slant the glyphs for an italic monospaced font. I'd consider this less of a travesty than, say, slanting a text font. – Will Robertson Jun 05 '14 at 07:03
  • This one might give even another option to slant a font. But haven't tried it, so it might give problems. – Manuel Jun 05 '14 at 10:18
  • 1
    @Manuel: There are problems with line and page breaks inside the argument. Then the coordinate systems of TeX and the PDF output device get out of sync. Safely it can be used inside \mbox, which forbids line breaks. – Heiko Oberdiek Jun 05 '14 at 10:48
  • I also needed to copy at at least ot1-zi4r-4.tfm, so I just copied all the .tfm files (from 0 through 7): for i in {0..7}; do; cp $(kpsewhich ot1-zi4r-$i.tfm) ot1-zi4r-sl-$i.tfm; cp $(kpsewhich ot1-zi4b-$i.tfm) ot1-zi4b-sl-$i.tfm; done. – Antal Spector-Zabusky Jul 26 '17 at 15:55
  • @AntalSpector-Zabusky Thanks for the fix for the empty line in the map file. – Heiko Oberdiek Jul 26 '17 at 17:48
4

There are now two variants of Inconsolata that have italics (as well as bold, bold italic and Cyrillic and Greek support for all of the weights and styles).

These are Inconsolata LGC and Inconsolata LGC Markup. The latter also tries to distinguish various kinds of quote and apostrophe-like characters, en/em dashes and hyphens,... It's all listed on the link.

andrejr
  • 141
2

It seems there is no italic version for your font (at least not that I'm aware of), but you can always search for a monospaced font you like in the LaTeX Font Catalogue

Mario S. E.
  • 18,609