3

I am trying to use a typewriter font (TXTT) in a document, but it consistently overruns the margins. I don't know if this is expected or if I am making a mistake in my document.

An MWE below:

\documentclass[a4paper, 12pt]{memoir}

% Load packages \usepackage[showframe]{geometry} \usepackage[colorlinks = true, urlcolor = blue, linkcolor = black]{hyperref} \usepackage{enumitem} \setlist{itemsep=0.05em} \usepackage{xfrac} \usepackage{booktabs} \usepackage{tocloft} \usepackage{lipsum}

% TXTT typewriter font \renewcommand\ttdefault{txtt} \renewcommand\familydefault{\ttdefault} %% Only if the base font of the document is to be typewriter style \usepackage[T1]{fontenc}

% Formatting matters \setlength\parskip{1em} \setlength\parindent{0em} \renewcommand\contentsname{} % the empty ToC name \renewcommand{\labelitemii}{$\circ$}

% =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- \begin{document}

\lipsum

\end{document}

Ingmar
  • 6,690
  • 5
  • 26
  • 47
tlmoore
  • 177
  • 1
    It's expected. I think selection teletype font turns off hyphenation. A wider text block and/or smaller type size can help, as can \sloppy. – musarithmia Apr 05 '23 at 13:00
  • 1
    Thanks for the input. It's a bummer because for this use-case the aesthetic is really nice. Cheers! – tlmoore Apr 05 '23 at 13:02
  • 3
    You might have better results with a proportional tt font (e.g., Latin Modern Mono Proportional) or a typewriter-esque slab serif like Computer Concrete. – musarithmia Apr 05 '23 at 13:07
  • 5
    you can enable hyphenation, see https://tex.stackexchange.com/a/204420/2388, but monospaced typewriter fonts don't go well together with justified text, better use \raggedright. – Ulrike Fischer Apr 05 '23 at 13:35
  • 3
    use \raggedright with fixed width space and no hyphenation it is literally impossible to justify the text margins. – David Carlisle Apr 05 '23 at 13:47
  • Using \raggedright also did the trick. I wasn't fixated on keeping the text justified, so this works just fine. – tlmoore Apr 07 '23 at 07:59

1 Answers1

4

You can load yourself the font definition file, modifying it to

  1. allow hyphenation, so removing \hyphenchar\font=\m@ne;
  2. define a stretchability for each of the fonts;
  3. define a shrinkability for each of the fonts.
\documentclass[a4paper, 12pt]{memoir}

% Load packages \usepackage[T1]{fontenc} \usepackage{kantlipsum}

% TXTT font \newcommand{\fixfontdimens}{% \fontdimen3\font=0.5\fontdimen2\font \fontdimen4\font=0.2\fontdimen2\font } \DeclareFontFamily{T1}{txtt}{} \DeclareFontShape{T1}{txtt}{m}{n}{<->t1xtt}{\fixfontdimens} \DeclareFontShape{T1}{txtt}{m}{sc}{<->t1xttsc}{\fixfontdimens} \DeclareFontShape{T1}{txtt}{m}{sl}{<->t1xttsl}{\fixfontdimens} \DeclareFontShape{T1}{txtt}{m}{it}{<->ssub * txtt/m/sl}{} \DeclareFontShape{T1}{txtt}{m}{ui}{<->ssub * txtt/m/sl}{} \DeclareFontShape{T1}{txtt}{bx}{n}{<->t1xbtt}{\fixfontdimens} \DeclareFontShape{T1}{txtt}{bx}{sc}{<->t1xbttsc}{\fixfontdimens} \DeclareFontShape{T1}{txtt}{bx}{sl}{<->t1xbttsl}{\fixfontdimens} \DeclareFontShape{T1}{txtt}{bx}{it}{<->ssub * txtt/bx/sl}{} \DeclareFontShape{T1}{txtt}{bx}{ui}{<->ssub * txtt/bx/sl}{} \DeclareFontShape{T1}{txtt}{b}{n}{<->ssub * txtt/bx/n}{} \DeclareFontShape{T1}{txtt}{b}{sc}{<->ssub * txtt/bx/sc}{} \DeclareFontShape{T1}{txtt}{b}{sl}{<->ssub * txtt/bx/sl}{} \DeclareFontShape{T1}{txtt}{b}{it}{<->ssub * txtt/bx/it}{} \DeclareFontShape{T1}{txtt}{b}{ui}{<->ssub * txtt/bx/ui}{}

\renewcommand\ttdefault{txtt} \renewcommand\familydefault{\ttdefault}

\begin{document}

\kant[1]

\textit{\kant[1][1-3]}

\textbf{\kant[1][4-6]}

\end{document}

enter image description here

egreg
  • 1,121,712