Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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}
share|improve this question
add comment

2 Answers 2

up vote 13 down vote accepted

You can use the url package:

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

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

enter image description here


Alternatively, you could use the `hyperref package:

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

and get click-able links:

enter image description here

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.

enter image description here


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}

enter image description here

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!!
    

    instead of

    \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}
    
share|improve this answer
    
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
    
Having \newcommand{\sourcefile}{\path} instead of \newcommand{\sourcefile}[1]{\path{#1}} would be better, especially if there are special character included. Then there is also \let\sourcefile\path. –  Martin Scharrer May 3 '12 at 16:15
    
@MartinScharrer: Can you elaborate on why the latter is better? –  Faheem Mitha May 3 '12 at 16:17
show 1 more comment

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.

share|improve this answer
    
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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.