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

  • You did not read the answer to the linked question wordbreaking, justification and ttfamily very carefully did you? You have to alter the \ttfamily macro (or invoke the changes in a second macro just after it). – Skillmon Aug 16 '17 at 12:42
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

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.