Skip to content

Instantly share code, notes, and snippets.

@rauschma
Last active February 8, 2024 18:36
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save rauschma/d76643bab3ab7550b2dcf465e772b389 to your computer and use it in GitHub Desktop.
Save rauschma/d76643bab3ab7550b2dcf465e772b389 to your computer and use it in GitHub Desktop.

LaTeX: preventing text from overflowing into margins

There are multiple approaches one could take.

Explicit breaks inside \texttt{}

Automatic breaks via \path{}

Add or remove characters to \UrlBreaks as necessary; currently the whole alphabet is in there, which isn’t always necessary.

\usepackage{url}
\renewcommand{\UrlBreaks}{\do\-\do\.\do\_\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}

\path{this-is-long-text-that.should.break}

\url{}

\UrlBreaks should work for \url{}, too. In case it doesn’t, there is package breakurl, which has the option anythingbreaks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment