I am really tired of them, it over and over again, they never stop coming up. Always there is some new URL which breaks and bring a new bad boxes up. How to fix this url bad box for stackoverflow link?

\usepackage[utf8]{inputenc}
\usepackage[brazil]{babel}

\usepackage[a4paper, margin=2cm]{geometry}
\usepackage[hyphens]{url}
% Bad formatting using URLs in bibtex
\usepackage{etoolbox}

% How to avoid overfull error with url package?
% See also the \usepackage{url} declarationon the file basic.tex.
% Set this to 2mu or 3mu if URL start troubling again.
% https://tex.stackexchange.com/questions/261776/how-to-avoid-overfull-error-with-url-package
\Urlmuskip=0mu plus 1mu

\begin{document}

VS Code is an Editor while VS is an IDE.
\url{https://stackoverflow.com/questions/30527522/what-are-the-differences-between-visual-studio-code-and-visual-studio}

\end{document}


Basic Builder: running pdflatex...done.

No errors. No warnings. Bad Boxes:

D:\temp.tex:25: Overfull \hbox (2.83554pt too wide) in paragraph at lines 25--27\T1/cmtt/m/n/12 30527522 / what -[] are -[] the -[] differences -[] between -[] visual -[] studio -[] code -[] and -[] visual -[] studio\$


I do not want to disable the warning, I want this to not goes out of the page limits automatically. Can ever latex be able to break them to the next line without I manually go all over everything new and figure out some kinda manual hack for each case manually?

• You can also write: \url{https://stackoverflow.com/questions/30527522} or just \url{stackoverflow.com/questions/30527522} to have a shorter link. – dexteritas Aug 2 '17 at 12:39
• – dexteritas Aug 2 '17 at 12:46

METHOD 1

I find URLs are a great place to employ sloppypar.

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[brazil]{babel}

\usepackage[a4paper, margin=3.5cm,showframe]{geometry}
\usepackage[hyphens]{url}
% Bad formatting using URLs in bibtex
\usepackage{etoolbox}

% How to avoid overfull error with url package?
% See also the \usepackage{url} declarationon the file basic.tex.
% Set this to 2mu or 3mu if URL start troubling again.
% https://tex.stackexchange.com/questions/261776/how-to-avoid-overfull-error-with-url-package
\Urlmuskip=0mu plus 1mu

\begin{document}

THIS

VS Code is an Editor while VS is an IDE.
\url{https://stackoverflow.com/questions/30527522/what-are-the-differences-between-visual-studio-code-and-visual-studio}

\bigskip
VERSUS THIS
\begin{sloppypar}
VS Code is an Editor while VS is an IDE.
\url{https://stackoverflow.com/questions/30527522/what-are-the-differences-between-visual-studio-code-and-visual-studio}
\end{sloppypar}
\end{document}


As I mention in comments below, for those hating the typing associated with placing a sloppypar environment around every paragraph that has a \url, one possibility is this in the preamble:

\everypar{\tolerance=200\relax\emergencystretch=0pt\relax\hfuzz=0.1pt\relax\vfuzz\hfuzz}
\let\svurl\url
\renewcommand\url{\sloppy\svurl}


In theory, this would make any paragraph using \url into a \sloppy paragraph. Then, with the \everypar, parameters would be reset to the LaTeX defaults with each new paragraph. Of course, this would conflict with any other package that wished to redefine these parameters for other reasons.

In practice, this has not been tested. And as we know, in theory, theory and practice are the same...in practice, they are not.

METHOD 2

Alternately, you can tell \url to break at any letter (ref Manually URL linebreak with Biblatex):

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[brazil]{babel}

\usepackage[a4paper, margin=3.3cm,showframe]{geometry}
\usepackage[hyphens]{url}
% Bad formatting using URLs in bibtex
\usepackage{etoolbox}

% How to avoid overfull error with url package?
% See also the \usepackage{url} declarationon the file basic.tex.
% Set this to 2mu or 3mu if URL start troubling again.
% https://tex.stackexchange.com/questions/261776/how-to-avoid-overfull-error-with-url-package
\Urlmuskip=0mu plus 1mu

\begin{document}
THIS

VS Code is an Editor while VS is an IDE.
\url{https://stackoverflow.com/questions/30527522/what-are-the-differences-between-visual-studio-code-and-visual-studio}

\bigskip
VERSUS THIS

\makeatletter
\do\/\do\a\do\b\do\c\do\d\do\e\do\f%
\do\g\do\h\do\i\do\j\do\k\do\l\do\m%
\do\n\do\o\do\p\do\q\do\r\do\s\do\t%
\do\u\do\v\do\w\do\x\do\y\do\z%
\do\A\do\B\do\C\do\D\do\E\do\F\do\G%
\do\H\do\I\do\J\do\K\do\L\do\M\do\N%
\do\O\do\P\do\Q\do\R\do\S\do\T\do\U%
\do\V\do\W\do\X\do\Y\do\Z}%
\makeatother
VS Code is an Editor while VS is an IDE.
\url{https://stackoverflow.com/questions/30527522/what-are-the-differences-between-visual-studio-code-and-visual-studio}

\end{document}


• Can I automatically put the \begin{sloppypar} or \makeatletter \g@addto@macro... around every \url{}, so I can never ever had these bad box warnings? – user Aug 2 '17 at 14:06
• @user The problem with that approach is that sloppypar begins and ends a separate paragraph, which I don't think you want for each invocation of \url. – Steven B. Segletes Aug 2 '17 at 14:10
• @user Of course, you could use \sloppy in the preamble to make the whole document conform to the redefined tolerances and stretches, but many would argue that the result would look... well..., more sloppy. – Steven B. Segletes Aug 2 '17 at 14:31
• Well, I just added the macro \makeatletter \g@addto@macro... to my preamble, and the problem is fixed. I did not had noticed the macro was redefining \url. I am putting this \url as default for all my projects. Why latex would not come with this \url by default? – user Aug 2 '17 at 14:36
• If you wanted to automate the 1st approach, maybe this would work in the preamble: \everypar{\tolerance=200\relax\emergencystretch=0pt\relax\hfuzz=0.1pt\relax\vfuzz\hfuzz} \let\svurl\url \renewcommand\url{\sloppy\svurl}. In theory, this would make any paragraph using \url into a \sloppy paragraph. Then, with the \everypar, parameters would be reset to the LaTeX defaults with each new paragraph. Of course, this would conflict with any other package that wished to redefine these parameters for other reasons. – Steven B. Segletes Aug 2 '17 at 14:40