3

Below is my code,

\documentclass{article}
\usepackage[breaklinks]{hyperref}
\usepackage{breakurl}
\usepackage{url}
\hypersetup{
pdfpagemode=none,%
colorlinks,%
citecolor=blue,%
filecolor=blue,%
linkcolor=blue,%
urlcolor=blue
}

\begin{document}

If you have any questions, at \burlalt{www.goooooggggggle.comssss}{32, 396, (1964)}

If you have any questions, at \burlalt{www.goooooggggggle.comssss}{\textbf{32}, 396, (1964)}

If you have any questions, at have any questions, at have have \burlalt{www.goooooggggggle.comssss}{32, 396, (1964)}

L.~A.~Anchordoqui, H.~Goldberg, and G.~Steigman, Phys.
Lett. B
\burlalt{http://dx.doi.org/10.1016/j.physletb.2012.12.019}{718, 1162 (2013)}.


\end{document}

when i use \textbf{} inside \burlalt, it throws some error, is it possible to use those commands inside \burlalt, please guide me, i am new to latex

1
  • BTW, UseNone is the correct value for pdfpagemode. See also the .log file that lists the accepted values in the warning message. Commented May 23, 2014 at 1:54

2 Answers 2

5

The following example defines macro \breakhref, which can be used similar to \href. The first argument is the URL as in the first argument of \href.

The second argument of \href can contain quite general LaTeX text. It is non-trivial to divide this text at hyphenation and breaking points to insert links for each part (syllables, spaces, ...) later. This is the domain of package soul. It has an interface to define custom drivers, where only the handling of the different element types are defined.

Dividing a general LaTeX text string into atomic units (syllables, ...) is far from trivial. There are some restrictions to be respected. Reading the documentation of package soul is therefore highly recommended, especially sections "2.1 Some things work ..." and "2.2 ... other don't".

Remarks:

  • The implementation takes some effort to retain the flexibility of the interword spaces without leaving gaps in the link.

  • Each atomic unit gets a \vphantom{<complete text>} to get a uniform height and depth of the link. For example, if links are underlined, the line should therefore be at the same vertical positions for the elements on the same line. Underlining means underlined links of the PDF annotation (via hyperref option pdfborderstyle). Since the DVI format does not retain the box dimensions, the underlining in xdvi's is "ragged".

  • Implicit hyphens, set by the hyphenation at the end of the line, are not part of the links due to limitations of \discretionary, which does not allow \special for the link feature inside its lists. This can also be considered as feature, because this hyphens does not originally belongs to the link text.

    Explicit hyphens are supported as links.

  • This method increases the number of link annotations, because each part constitutes a new independent link.

Full example:

% latex/dvips/ps2pdf
\documentclass[a5paper]{article}
\usepackage{hyperref}
\usepackage{url}
\usepackage{xcolor}
\hypersetup{
  pdfpagemode=UseNone,
  colorlinks,
  allcolors=blue,
  % allbordercolors=blue,
  % pdfborderstyle={/S/U/W 1},
}

\usepackage{soul}

\makeatletter
\newcommand*{\breakhref}{}
\DeclareRobustCommand*{\breakhref}{%
  \begingroup
  \hyper@normalise\breakhref@
}
\newcommand*{\breakhref@}[2]{%
  \endgroup
  \SOUL@setup
  \def\SOUL@everyspace##1{%
    ##1%
    \dimen@=\fontdimen2\font
    \advance\dimen@ by \fontdimen3\font
    \cleaders\hbox to \dimen@{%
      \hss
      \href{#1}{\ \vphantom{#2}}%
      \hss
    }\hskip\dimen@\relax
    \hspace{-\fontdimen3\font
        plus \fontdimen3\font minus \fontdimen3\font}%
  }%
  \def\SOUL@everysyllable{%
    \href{#1}{\the\SOUL@syllable\vphantom{#2}}%
  }%
  \def\SOUL@everyhyphen{%
    \discretionary{-}{}{}%
  }%
  \def\SOUL@everyexhyphen##1{%
    \SOUL@setkern\SOUL@hyphkern
    \href{#1}{##1\vphantom{#2}}%
    \discretionary{}{}{%
      \SOUL@setkern\SOUL@charkern
    }%
  }%
  \SOUL@{#2}%
}
\makeatother

\begin{document}

If you have any questions, at
\breakhref{http://www.example.org/}{32, 396, (1964)}

If you have any questions, at
\breakhref{http://www.example.org/}{\textbf{32}, 396, (1964)}

\medskip

L.~A.~Anchordoqui and H.~Goldberg, Phys.
Lett. B
\breakhref{http://dx.doi.org/10.1016/j.physletb.2012.12.019}{%
  718, 1162 (2013)}.

\medskip

\breakhref{http://www.example.net}{%
  This little macro will hardly be good enough for linguists.
  Example-with-explicit-hyphens.}

\medskip

\parbox{1mm}{%
  \breakhref{http://www.example.net}%
  {This little macro is non-trivial.}
}
\end{document}

Result/colorlinks

Variant with underlined links via

allbordercolors=blue,
pdfborderstyle={/S/U/W 1},

Result/underline

In the third-last line the explicit hyphen in non- is linked, the implicit hyphen in the second-last line triv- is not. The partial overlap is due to a negative kerning between v and - that is not ignored by soul.

Not recommended are boxed links, because each element is boxed:

Result/boxes

1
  • Thank you very much, this saved a lot of Headache, it works like charm
    – user52124
    Commented May 23, 2014 at 9:15
1

\burlalt is meant for two urls not for one url and arbitrary text. Use \href instead:

 \href{www.goooooggggggle.comssss}{\textbf{32}, 396, (1964)}
6
  • The problem is i used \href and had breaking problem, so i shifted to \burlalt to counter that :-)
    – user52124
    Commented May 21, 2014 at 12:23
  • But you don't display an url but arbitrary text with spaces in it. There will no problem with hyphenation there. (btw: imho the breakurl documentation confused the two argument. It displays the first and not the second.) Commented May 21, 2014 at 12:31
  • Actually i want "32, 396 (1964)" as display and it is working fine, only thing is i need to make bold for 32
    – user52124
    Commented May 21, 2014 at 12:40
  • Did you try my code? Is there a problem with it? Commented May 21, 2014 at 12:41
  • @Fischer, I used that code \href already, problem with that is when we use DVI2ps and PS2PDF, the link won't be generated in PDF, for the broken link text, that's why i switched to \burlalt
    – user52124
    Commented May 22, 2014 at 4:39

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .