0

On the question How to automatically hyphenate within \texttt? is explained a lot of things, but I could not understand, or at make it work some things.

On the question Example about hyphenation with ttfamily font I is showed to to apply the ttfont to all text, for example:

\ttfamily
Typewriter/teletype family - (encoding: T1, family: pcr, series: m, 
shape: n, size: 10.5, baseline: 11.0pt)

But how can I wrap it around some words like \texttt{Some text} or an environment?

\documentclass[10pt,a5paper,twoside]{memoir}
\usepackage{lmodern}

\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}

\usepackage[main=english]{babel}
\usepackage[showframe,pass]{geometry}

\begin{document}

\frenchspacing
\texttt{Typewriter/teletype family - (encoding: T1, family: pcr, series: m, shape: n, size: 10.5, baseline: 11.0pt)}

\begin{texttt}
Typewriter/teletype family - (encoding: T1, family: pcr, series: m, shape: n, size: 10.5, baseline: 11.0pt)
\end{texttt}

\end{document}

The texttt is not hyphenating and it generation the warnings:

test2.tex:182: Overfull \hbox (11.9992pt too wide) in paragraph at lines 182--183[]\T1/lmtt/m/n/10 Typewriter/teletype family - (encoding: T1, family:
test2.tex:182: Overfull \hbox (33.7491pt too wide) in paragraph at lines 182--183\T1/lmtt/m/n/10 pcr, series: m, shape: n, size: 10.5, baseline: 11.0pt) 

enter image description here


Related:

  1. Line break in texttt
  2. wordbreaking, justification and ttfamily
1

Besides using the answer here as Ulrike said, which is basically the present question, you could have an easier solution using fontspec and compiling with xelatex:

\documentclass[10pt,a5paper,twoside]{memoir}
\usepackage{lmodern}

\usepackage[english]{babel}
\usepackage[showframe]{geometry}

\usepackage{fontspec,lipsum}
\setmonofont{Latin Modern Mono}

\begin{document}

\frenchspacing


\fontspec{Latin Modern Mono}\footnotesize  

\lipsum[1-3]

\rmfamily


\lipsum[1-3]



\end{document}
  • This only works for the \fontspec{Latin Modern Mono) and not with \ttfamily or \texttt as asked by the OP. – Ulrike Fischer Aug 22 '17 at 12:23
  • Yes, but it works for his purposes, which is to write hyphenated / justified paragraphs in a monospaced font. – Joseph Aug 22 '17 at 13:12
  • I have no idea what are the purposes of the question, imho this is rather unclear, but the title of the question is explicitly about \texttt{} and I only wanted to make clear that your answer doesn't address this point. – Ulrike Fischer Aug 22 '17 at 13:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.