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.

When using a long tag for an equation, is there a way to have an equivalent of \eqref that would allow LaTeX to break the reference between words, or even within words.

In the example below I get overfull \hbox. And when adding \sloppy, I will get huge spaces between words instead.

(As a bonus constraint, it should actually work with \documentclass{llncs}.)

\documentclass[draft,11pt]{article}


\usepackage{amsmath}

\begin{document}


\begin{equation}
\label{eq:inframetric}
d(x,y)\leq \rho \max(d(x,z),d(z,y))
\tag{$\rho$-inframetric inequality}
\end{equation}

\begin{equation}
\label{eq:triangle_inequality}
d(x,y)\leq d(x,z)+d(z,y)
\tag{triangle inequality}
\end{equation}


\medskip

a, b, c, d, e, f, g, \eqref{eq:triangle_inequality}, \eqref{eq:inframetric},     
\eqref{eq:triangle_inequality}, \eqref{eq:triangle_inequality}, \eqref{eq:inframetric},     
\eqref{eq:inframetric}

\medskip


$a_1,a_2,a_3,a_1,a_2,a_3,a_1,a_2,a_3,a_1,a_2,a_3,a_1,a_2,a_3,a_1,a_2,a_3$
\eqref{eq:triangle_inequality},
\end{document}
share|improve this question

1 Answer 1

up vote 6 down vote accepted

You can define a command \seqref that mimics what \eqref does, without using a box; we have to use refcount to allow hyphenation also in the last word. I wouldn't redefine \eqref, because hyphenation of tags should not be used generally.

\documentclass[draft,11pt]{article}

\usepackage{amsmath,refcount}
\newtheorem{thm}{Theorem}

\makeatletter
\newcommand{\seqref}[1]{\textup{\tagform@split{\getrefnumber{#1}}}}
\newcommand\tagform@split[1]{%
  \begingroup
  \m@th\normalfont(\ignorespaces #1\unskip\@@italiccorr)%
  \endgroup
}
\makeatother

\begin{document}


\begin{equation}
\label{eq:inframetric}
d(x,y)\leq \rho \max(d(x,z),d(z,y))
\tag{$\rho$-inframetric inequality}
\end{equation}

\begin{equation}
\label{eq:triangle_inequality}
d(x,y)\leq d(x,z)+d(z,y)
\tag{triangle inequality}
\end{equation}


\medskip

a, b, c, d, e, f, g, \seqref{eq:triangle_inequality}, \seqref{eq:inframetric}, 
\seqref{eq:triangle_inequality}, \seqref{eq:triangle_inequality}, \seqref{eq:inframetric}, 
\seqref{eq:inframetric}

\medskip

\begingroup\itshape
a, b, c, d, e, f, g, \seqref{eq:triangle_inequality}, \seqref{eq:inframetric}, 
\seqref{eq:triangle_inequality}, \seqref{eq:triangle_inequality}, \seqref{eq:inframetric}, 
\seqref{eq:inframetric}
\endgroup

\begin{thm}
a, b, c, d, e, f, g, \seqref{eq:triangle_inequality}, \seqref{eq:inframetric}, 
\seqref{eq:triangle_inequality}, \seqref{eq:triangle_inequality}, \seqref{eq:inframetric}, 
\seqref{eq:inframetric}
\end{thm}


$a_1,a_2,a_3,a_1,a_2,a_3,a_1,a_2,a_3,a_1,a_2,a_3,a_1,a_2,a_3,a_1,a_2,a_3$
\seqref{eq:triangle_inequality},
\end{document}

Of course, bad line breaks are not automatically solved; they would be the same if you typed the tags directly.

enter image description here

share|improve this answer
    
Thanks, this is doing what I was hoping for. –  sunless Feb 20 at 16:50
1  
i'd like to point out that any \ref, not just \eqref, has this problem. (in this respect, \eqref{xxx} is equivalent to (\ref{xxx}) with the addition of \upshape.) –  barbara beeton Feb 20 at 16:51
    
@barbarabeeton No, \ref doesn't box the reference. –  egreg Feb 20 at 16:57
    
@barbarabeeton I have \normalfont after \begingroup, so the behavior is exactly the same as \eqref's. –  egreg Feb 20 at 17:11
    
@egreg -- agreed re boxing; i'll add that to the list of questions for amsthm, with thanks. however, a question: i tested, replacing \eqref{...} by (\ref{...}) and "inequality" in the second paragraph doesn't hyphenate, although the patterns allow it as in-equal-ity; happens with \seqref as well as with \ref. overlong box warning shows ... (tri-an-gle inequality[]). so something else is at work here. any idea what? –  barbara beeton Feb 20 at 17:24

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.