1

Reading How to automatically hyphenate within \texttt? I could not figure it out how to make the ttfamily to hyphenate automatically. The text on the question wordbreaking, justification and ttfamily is not hyphenated. Is there an example about hyphenation with ttfamily?

I tried adding \hyphenchar\font=`\-\relax as suggested by @Skillmon on Minipage/framebox text is not justified and throws several Underfull \hbox (badness 10000) comment, but it still not justified/hyphenated:

\documentclass[10pt,openright,twoside,a5paper]{memoir}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[]{ragged2e}
\usepackage[showframe]{geometry}
\usepackage[brazil]{babel}

\hyphenchar\font=`\-\relax

\begin{document}
\begin{center}

\hspace*{1cm}
{Catalogação na fonte pela Biblioteca Universitária da Universidade
Universitária da Universidade.}

\framebox[\textwidth]
{
    \begin{minipage}{\textwidth}

        \ttfamily
        Lembre-se: a ficha de identificação da obra elaborada pelo autor deve constar no
        verso da folha de rosto de teses e dissertações de modo a possibilitar sua
        representação precisa pelas informações de autor, título, local, data, número de
        folhas, assunto, etc.

    \end{minipage}
}

\end{center}
\end{document}

enter image description here

user
  • 4,745

1 Answers1

3

You need to copy the complete added code.

Please see the following MWE

\documentclass[10pt,openright,twoside,a5paper]{memoir}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[]{ragged2e}
\usepackage[showframe]{geometry}
\usepackage[brazil]{babel}

%THIS IS THE IMPORTANT PART   % <=========================================
\usepackage{letltxmacro}
\LetLtxMacro\origttfamily\ttfamily
\DeclareRobustCommand*{\ttfamily}{%
  \origttfamily
  \hyphenchar\font=`\-\relax
  \fontdimen3\font=.25em\relax
  \fontdimen4\font=.167em\relax
  \fontdimen7\font=.167em\relax
}

\makeatletter
\DeclareRobustCommand\vttfamily{%
  \not@math@alphabet\vttfamily\relax
  \fontfamily{cmvtt}% cmvtt (Computer Modern) or lmvtt (Latin Modern)
  \selectfont
}
\DeclareTextFontCommand{\textvtt}{\vttfamily}
\makeatother % <=========================================================

\begin{document}
\begin{center}

\hspace*{1cm}
{Catalogação na fonte pela Biblioteca Universitária da Universidade
Universitária da Universidade.}

\framebox[\textwidth]
{
    \begin{minipage}{\textwidth}

        \ttfamily
        Lembre-se: a ficha de identificação da obra elaborada pelo autor deve constar no
        verso da folha de rosto de teses e dissertações de modo a possibilitar sua
        representação precisa pelas informações de autor, título, local, data, número de
        folhas, assunto, etc.

    \end{minipage}
}

\end{center}
\end{document}

and the result:

enter image description here

Mensch
  • 65,388