# With newenvironment for font an Overfull\hbox warning is shown within itemize [duplicate]

When I run the following code I get an Overfull\hbox(... too wide) in paragraph warning.

\documentclass{scrartcl}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\newenvironment{fonttfp}{\fontfamily{cmtt}\selectfont}{\par}

\begin{document}
\begin{itemize}
\item[] {\fonttfp Afghanistan\_Albania Algeria\_Andorra Angola\_Antigua and Barbuda\_Argentina Armenia\_Australia Austria\_Azerbaijan}
\end{itemize}
\end{document}


How can I get it away. When I remove the \fonttfp statement the warning disappears. I've also tried to use sloppypar and the package microtype. Both approaches do not clear the warning.

• A question out of curiosity: Why don't you just issue \ttfamily? Your current use of \fonttfp will always result in an error, because the environment isn't ended (formally there's no \endfonttfp), but as you use it it should be a command. – TeXnician May 5 '17 at 15:52

# Version No. 1

You could do it as you would when using an environment with \fonttfp ... \endfonttfp, what would give you this:

\documentclass{scrartcl}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\newenvironment{fonttfp}{\fontfamily{cmtt}\selectfont}{\par}

\begin{document}
\begin{itemize}
\item[] {\fonttfp Afghanistan Albania Algeria Andorra Angola Antigua and Barbuda Argentina Armenia Australia Austria Azerbaijan \endfonttfp}
\end{itemize}
\end{document}


# Version No. 2

You could do it the LaTeX way (\begin{fonttfp}...\end{fonttfp}):

\documentclass{scrartcl}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\newenvironment{fonttfp}{\fontfamily{cmtt}\selectfont}{\par}

\begin{document}
\begin{itemize}
\item[] \begin{fonttfp}Afghanistan Albania Algeria Andorra Angola Antigua and Barbuda Argentina Armenia Australia Austria Azerbaijan\end{fonttfp}
\end{itemize}
\end{document}


# Version No. 3

Use a command.

\documentclass{scrartcl}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\newcommand{\fonttfp}[1]{\begingroup\fontfamily{cmtt}\selectfont#1\endgroup\par}

\begin{document}
\begin{itemize}
\item[] \fonttfp{Afghanistan Albania Algeria Andorra Angola Antigua and Barbuda Argentina Armenia Australia Austria Azerbaijan}
\end{itemize}
\end{document}


# Version No. 4

Do the same as in (3), but without argument and add \par manually.

• Thanks for your effort! When I run the different versions I always get the same error. It might be useful to change the way of dealing with the different font for one item or small text passages, but the answer is not answering the question. – So S May 5 '17 at 16:02
• @SoS Well, I get no error using this. or do you just ask how to avoid an overfull box warning? – TeXnician May 5 '17 at 16:06
• I asked how to avoid the warning. Maybe that wasn't clear in my comment. Sorry for that. – So S May 5 '17 at 16:16

It's not \newenvironment, but \newcommand.

You can set \spaceskip with some flexibility:

\documentclass{scrartcl}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}

\newcommand{\fonttfp}{%
\fontfamily{cmtt}\selectfont % better \ttfamily
\spaceskip=.3em plus 0.2em minus .1em
}
\DeclareTextFontCommand{\texttfp}{\fonttfp}

\begin{document}

\begin{itemize}
\item[] {\fonttfp Afghanistan Albania Algeria Andorra Angola Antigua and
Barbuda Argentina Armenia Australia Austria Azerbaijan}
\item[] \texttfp{Afghanistan Albania Algeria Andorra Angola Antigua and
Barbuda Argentina Armenia Australia Austria Azerbaijan}
\end{itemize}

\end{document}


• Thanks for this answer. It is removing the warning. When I tried to provide a minimal example, I've removed the underscores between the words. Now, when I tried this solution within my working environment (with the underscores), the warning is again produced. How do the underscores affect this? – So S May 6 '17 at 11:16
• @SoS There is no break point between the names. – egreg May 6 '17 at 12:22