# Line overflow with long filenames and urls

Consider the following text. Here /etc/postgresql/8.4/main/pg_hba.confoverflows into the margin, and is hypenated. /var/lib/pgsql/data/pg_hba.conf is also hyphenated, but does not overflow.

So, I was wondering what was a good general way to deal with the overflow. I've run into this issue before, and usually I just stick a // before the offending text, but this is not a good general solution. For example, if the text changes, then the line break may be for no good reason.

I'm actually surprised that LaTeX doesn't simply move that text onto the next line. Is there some good general way to say - don't break this text and move it to the next line if it overruns? I've looked at other questions, and it is possible no such thing exists, but maybe I'm missing something.

\documentclass{article}
\usepackage{underscore}
% Text layout
\topmargin 0.0cm
\oddsidemargin 0.5cm
\evensidemargin 0.5cm
\textwidth 16cm
\textheight 21cm
\newcommand{\sourcefile}[1]{\texttt{#1}}

\begin{document}

Therefore, the user running init_db.py needs to have sudo
privileges on the machine, or have a database superuser of the same
name as the shell account. In addition, you may need to modify the
PostgreSQL client authentication configuration. This is located in the
file pg_hba.conf. I give basic instructions about the
necessary modifications in this section. For further information about
PostgreSQL client authentication, see
http://www.postgresql.org/docs/current/static/auth-pg-hba-conf.html

With the Debian and Ubuntu default client authentication configuration
located at \sourcefile{/etc/postgresql/8.4/main/pg_hba.conf}, SNPpy
will run without modification. For other Linux distributions, changes
may be necessary.

For example, the client authentication configuration file is located
in Fedora at \sourcefile{/var/lib/pgsql/data/pg_hba.conf} and its
default values are given in Table 1.

\end{document}

-

You can use the url package:

\usepackage{url}
\newcommand{\sourcefile}{\url}


Using the above, and applying \url{} to the URL yields:

Alternatively, you could use the hyperref package:

\usepackage{hyperref}
\newcommand{\sourcefile}{\url}


If the document is strictly for online viewing you could also use

\href{http://www.postgresql.org/docs/current/static/auth-pg-hba-conf.html}{auth pg hba conf}


and get links with text that does not show the entire URL but whatever text you specify as the second parameter.

As egreg points out, if you don't want click able links on the files, you could use \path{} for the \sourcefiles and use \url for the web links

\usepackage{hyperref}
\newcommand{\sourcefile}{\path}


With the url package, you could also define different macros, and each can have it own style:

\DeclareUrlCommand\email{\urlstyle{rm}}
\DeclareUrlCommand\directory{\urlstyle{tt}}


## Note:

• The showframe package was used to display the margins.

• As Martin Scharrer pointed out is is best to use

\newcommand{\sourcefile}{\path}%  Better!!


or

\let\sourcefile\path%  Better!!


\newcommand{\sourcefile}[1]{\path{#1}}% Not so good


This will allow for the case where there any special characters in the file names as they will be processed in verbatim mode. So, for example, the following will work fine with the either of the "Better" labeled definitions above:

\sourcefile{~/.cshrc}
\sourcefile{abc%20def}

-
Thanks, Peter. Interesting approach, and it does improve the situation. I've got mixed feelings about splitting the filenames, though. What do all the aesthetes out there think? –  Faheem Mitha May 2 '12 at 18:22
I don't see why a file name should be treated any different than a URL as they are really the same thing -- both refer to file names. Alternatively you could put the file name on its own line, but even then it could take up multiples lines depending on the path length. –  Peter Grill May 2 '12 at 18:32
Good point, Peter. –  Faheem Mitha May 2 '12 at 18:38
@MartinScharrer: Can you elaborate on why the latter is better? –  Faheem Mitha May 3 '12 at 16:17

While @Peter's solution is better, if you don't want to split the file names, you have this alternative that makes use of \sloppy.

\documentclass{article}
\usepackage{underscore}
% Text layout
\topmargin 0.0cm
\oddsidemargin 0.5cm
\evensidemargin 0.5cm
\textwidth 16cm
\textheight 21cm
\newcommand{\sourcefile}[1]{\texttt{#1}}

\sloppy
\begin{document}

Therefore, the user running init_db.py needs to have sudo
privileges on the machine, or have a database superuser of the same
name as the shell account. In addition, you may need to modify the
PostgreSQL client authentication configuration. This is located in the
file pg_hba.conf. I give basic instructions about the
necessary modifications in this section. For further information about
PostgreSQL client authentication, see
http://www.postgresql.org/docs/current/static/auth-pg-hba-conf.html

With the Debian and Ubuntu default client authentication configuration
located at \sourcefile{/etc/postgresql/8.4/main/pg_hba.conf}, SNPpy
will run without modification. For other Linux distributions, changes
may be necessary.

For example, the client authentication configuration file is located
in Fedora at \sourcefile{/var/lib/pgsql/data/pg_hba.conf} and its
default values are given in Table 1.

\end{document}


But you will have to sacrifice the killer ability of TeX in adjusting inter word spacing.

-
Hi, Harish. I'm not really clear what \sloppy does. Can someone give me a reference? Based on compiling this example with and without the \sloppy option, it looks like it tells LaTeX to stop keeping interword distances constant, which in general looks much worse. While I think this might make sense on a per-paragraph basis, it definitely does not make sense for a whole documentation. Can this be done on a per-paragraph basis? Thanks. –  Faheem Mitha May 3 '12 at 5:48
@FaheemMitha: This earlier question of mine Why is text being placed beyond the specified line width? has some explanation, and where I discovered that \sloppy` worked for me. –  Peter Grill May 3 '12 at 16:10