[Tex/LaTex] change kerning of \texttt

fontskerningtypewriter

I tried to use a font different than courier for monospaced fonts but none of this list (http://www.ctan.org/topic/font-mono) are available on my system – and as we work in a distributed system custom local additions are not an option. (Build server, standards, etc.)

so question is

  1. is there a usullay available monospace font, that is more condensed, i.e. needs less horizontal space?
  2. how can i reduce the general kerning for all letters in \texttt or the whole font?

Best Answer

Here are two ways: 1) with microtype's \textls macro, and the other, \spaceout, without any packages. I have wrapped those macros into \textttA and \textttB invocation forms.

The \textls macro uses an optional argument to specify the compression or expansion, while \spaceout uses the values of \theLetterSpace and \extraWordSpace to modify the default spacings.

Both approaches support line wrapping.

Summarizing from the comments below, it is worth noting that the \textls approach supports hyphenation, whereas the \spaceout approach does not. In addition, the argument to \spaceout cannot include a macro that itself takes an argument.

\documentclass{article}
\def\theLetterSpace{-0.5pt}
\def\extraWordSpace{-0.5pt}
\newcommand\spaceout[2][\theLetterSpace]{%
  \def\LocalLetterSpace{#1}\expandafter\spaceouthelpA#2 \relax\relax}
\def\spaceouthelpA#1 #2\relax{%
  \spaceouthelpB#1\relax\relax%
  \ifx\relax#2\else\kern\extraWordSpace\ \kern\LocalLetterSpace\spaceouthelpA#2\relax\fi
}
\def\spaceouthelpB#1#2\relax{%
  #1%
  \ifx\relax#2\else
    \kern\LocalLetterSpace\spaceouthelpB#2\relax%
  \fi
}
\parskip 1ex
\usepackage{microtype}
\def\textttA#1{\texttt{\textls*[-70]{#1}}}
\def\textttB#1{\texttt{\spaceout{#1}}}
\begin{document}
\def\mytext{a bit of texttt}
This is \texttt{\mytext}\par
This is \textttA{\mytext}\par
This is \textttB{\mytext}\par
\def\mytext{a bit of texttt. a bit of texttt. a bit of texttt. a bit of texttt. 
a bit of texttt. a bit of texttt. a bit of texttt. a bit of texttt. }
\noindent\hrulefill\sloppy\par
This is \texttt{\mytext}\par
This is \textttA{\mytext}\par
This is \textttB{\mytext}
\end{document}

enter image description here

enter image description here

Related Question