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.

I've been struggling with nameref for some time now. I am trying to make them respect the available space there is on a line, but I can't seem to find how.

The LaTeX code is the following:

\documentclass{report}
%\documentclass{scrreprt}
\usepackage[inner=3.5cm,outer=2.5cm,top=2.5cm,bottom=2.5cm,pdftex]{geometry}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{lmodern}
\usepackage[pdftex]{hyperref}

\hypersetup{
    colorlinks = true
}

\overfullrule=15pt % debug

\begin{document}

\chapter{Chapter name}

\section{Section name}

\subsection{XML\_DOM\_NodeFirstSonGet}\label{XMLDOMNodeFirstSonGet}
\subsection{XML\_DOM\_NodeSonsCount}\label{XMLDOMNodeSonsCount}
\subsection{XML\_DOM\_NodeSonsGet}\label{XMLDOMNodeSonsGet}
\subsection{XML\_DOM\_NodeSonsNodesCount}\label{XMLDOMNodeSonsNodesCount}
\subsection{XML\_DOM\_NodeSonsNodesCount}\label{XMLDOMNodeSonsNodesGet}

Normal text:\\\newline
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse\\


See \nameref{XMLDOMNodeFirstSonGet}, \nameref{XMLDOMNodeSonsCount}, \nameref{XMLDOMNodeSonsGet}, \nameref{XMLDOMNodeSonsNodesCount}, \nameref{XMLDOMNodeSonsNodesGet}.\\

See \nameref{XMLDOMNodeFirstSonGet}, \nameref{XMLDOMNodeSonsCount}, \nameref{XMLDOMNodeSonsNodesCount}, \nameref{XMLDOMNodeSonsNodesGet}.\\


See \nameref{XMLDOMNodeFirstSonGet}, \nameref{XMLDOMNodeFirstSonGet}, \nameref{XMLDOMNodeFirstSonGet}, \nameref{XMLDOMNodeSonsCount}, \nameref{XMLDOMNodeSonsNodesCount}, \nameref{XMLDOMNodeSonsNodesGet}, \nameref{XMLDOMNodeFirstSonGet}.
\end{document}

And the resulting PDF looks like this:

enter image description here

As you can see, the second and third line containing \namerefs are overfull and won't respect the line width as the normal text does.

The result is even worst with \documentclass{scrreprt} as they are all overfull and cropped by the page limit:

enter image description here

As I don't know the length of the string that will be displayed, I can't arbitrarily force a new line.

What also strikes me is that I didn't find any information about this behavior. Is there a way to fix this?

share|improve this question

migrated from stackoverflow.com Jan 28 '13 at 10:32

This question came from our site for professional and enthusiast programmers.

    
Welcome to TeX.sx! Your post was migrated here from another Stack Exchange site. Please register on this site, too, and make sure that both accounts are associated with each other (by using the same OpenID), otherwise you won't be able to comment on or accept answers or edit your question. –  Martin Schröder Jan 28 '13 at 12:09
add comment

1 Answer

up vote 4 down vote accepted

The paragraph structure for those containing \nameref is "bad" since TeX has no way of forcing a line-break within the unknown "words". As a possible correction, and to see how bad it may look if TeX didn't care so much about making things look pretty, add \sloppypar (or at least scope it within a group {...} around the affected paragraphs) before the \nameref paragraphs. Alternatives include using \raggedright or perhaps a breakable underscore (or combination of either):

enter image description here

enter image description here

enter image description here

enter image description here

Here's a complete example:

\documentclass{report}
%\documentclass{scrreprt}
\usepackage[inner=3.5cm,outer=2.5cm,top=1cm,bottom=1cm]{geometry}
\usepackage{lmodern}
\usepackage{hyperref}

\hypersetup{
    colorlinks = true
}

\overfullrule=15pt % debug

\begin{document}

\chapter{Chapter name}

\section{Section name}

\subsection{XML\textunderscore DOM\textunderscore NodeFirstSonGet}\label{XMLDOMNodeFirstSonGet}
\subsection{XML\textunderscore DOM\textunderscore NodeSonsCount}\label{XMLDOMNodeSonsCount}
\subsection{XML\textunderscore DOM\textunderscore NodeSonsGet}\label{XMLDOMNodeSonsGet}
\subsection{XML\textunderscore DOM\textunderscore NodeSonsNodesCount}\label{XMLDOMNodeSonsNodesCount}
\subsection{XML\textunderscore DOM\textunderscore NodeSonsNodesCount}\label{XMLDOMNodeSonsNodesGet}

Normal text:

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse

Using \verb|\sloppypar|:

{\sloppypar
See \nameref{XMLDOMNodeFirstSonGet}, \nameref{XMLDOMNodeSonsCount}, \nameref{XMLDOMNodeSonsGet}, \nameref{XMLDOMNodeSonsNodesCount}, \nameref{XMLDOMNodeSonsNodesGet}.

See \nameref{XMLDOMNodeFirstSonGet}, \nameref{XMLDOMNodeSonsCount}, \nameref{XMLDOMNodeSonsNodesCount}, \nameref{XMLDOMNodeSonsNodesGet}.

See \nameref{XMLDOMNodeFirstSonGet}, \nameref{XMLDOMNodeFirstSonGet}, \nameref{XMLDOMNodeFirstSonGet}, \nameref{XMLDOMNodeSonsCount}, \nameref{XMLDOMNodeSonsNodesCount}, \nameref{XMLDOMNodeSonsNodesGet}, \nameref{XMLDOMNodeFirstSonGet}.
}

\bigskip

Using \verb|\raggedright|:

{\raggedright
See \nameref{XMLDOMNodeFirstSonGet}, \nameref{XMLDOMNodeSonsCount}, \nameref{XMLDOMNodeSonsGet}, \nameref{XMLDOMNodeSonsNodesCount}, \nameref{XMLDOMNodeSonsNodesGet}.

See \nameref{XMLDOMNodeFirstSonGet}, \nameref{XMLDOMNodeSonsCount}, \nameref{XMLDOMNodeSonsNodesCount}, \nameref{XMLDOMNodeSonsNodesGet}.

See \nameref{XMLDOMNodeFirstSonGet}, \nameref{XMLDOMNodeFirstSonGet}, \nameref{XMLDOMNodeFirstSonGet}, \nameref{XMLDOMNodeSonsCount}, \nameref{XMLDOMNodeSonsNodesCount}, \nameref{XMLDOMNodeSonsNodesGet}, \nameref{XMLDOMNodeFirstSonGet}.
}

\bigskip

Different \verb|\textunderscore|:

{\let\oldtextunderscore\textunderscore%
\renewcommand{\textunderscore}{\oldtextunderscore\hspace{0pt}}%
See \nameref{XMLDOMNodeFirstSonGet}, \nameref{XMLDOMNodeSonsCount}, \nameref{XMLDOMNodeSonsGet}, \nameref{XMLDOMNodeSonsNodesCount}, \nameref{XMLDOMNodeSonsNodesGet}.

See \nameref{XMLDOMNodeFirstSonGet}, \nameref{XMLDOMNodeSonsCount}, \nameref{XMLDOMNodeSonsNodesCount}, \nameref{XMLDOMNodeSonsNodesGet}.

See \nameref{XMLDOMNodeFirstSonGet}, \nameref{XMLDOMNodeFirstSonGet}, \nameref{XMLDOMNodeFirstSonGet}, \nameref{XMLDOMNodeSonsCount}, \nameref{XMLDOMNodeSonsNodesCount}, \nameref{XMLDOMNodeSonsNodesGet}, \nameref{XMLDOMNodeFirstSonGet}.
}

Different \verb|\textunderscore| + \verb|\sloppypar|:

{\let\oldtextunderscore\textunderscore\sloppypar%
\renewcommand{\textunderscore}{\oldtextunderscore\hspace{0pt}}%
See \nameref{XMLDOMNodeFirstSonGet}, \nameref{XMLDOMNodeSonsCount}, \nameref{XMLDOMNodeSonsGet}, \nameref{XMLDOMNodeSonsNodesCount}, \nameref{XMLDOMNodeSonsNodesGet}.

See \nameref{XMLDOMNodeFirstSonGet}, \nameref{XMLDOMNodeSonsCount}, \nameref{XMLDOMNodeSonsNodesCount}, \nameref{XMLDOMNodeSonsNodesGet}.

See \nameref{XMLDOMNodeFirstSonGet}, \nameref{XMLDOMNodeFirstSonGet}, \nameref{XMLDOMNodeFirstSonGet}, \nameref{XMLDOMNodeSonsCount}, \nameref{XMLDOMNodeSonsNodesCount}, \nameref{XMLDOMNodeSonsNodesGet}, \nameref{XMLDOMNodeFirstSonGet}.
}

\end{document}
share|improve this answer
    
That did the trick. I'll use the last one, '\textunderscore + \sloppypar'. Thanks a lot for your time Werner. –  timetear Jan 27 '13 at 20: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.