5

In my document, the symbol / is active. This leads to the problem with links. Instead of the slash they contain expansion of the slash.

Wanted:

http://aaa/ggg/ddd/

Got:

http://www.\discretionary%20{.com/}{}{/ }\discretionary%20{/}{}{/}aaa\discretio nary%20{/}{}{/}ggg\discretionary%20{/}{ }{/}ddd\discretionary%20{/}{}{/}

How to get the desired result?

\documentclass{article}
\usepackage{lipsum}
\usepackage{hyperref}

\def\SlashDesc{\discretionary{/}{}{/}}
\AtBeginDocument{\catcode`\/=\active}
\catcode`\/=\active
\def/{\SlashDesc}

\pdfstringdefDisableCommands{\def/{X}} % Doesn't help

\begin{document}

\begin{minipage}{5cm}
\lipsum*[75]
\href{http://aaa/ggg/ddd/}{aaa/bbb/ccc/ddd/eee/fff/ggg/hhh/iii/jjj/kkk/lll}
\end{minipage}

\end{document}
  • You shouldn't activate / in the first place. – egreg Feb 12 '14 at 11:19
  • You can try \href{http://aaa/ggg/ddd/}{\url{aaa/bbb/ccc/ddd/eee/fff/ggg/hhh/iii/jjj/kkk/lll}} without using an active / character – user2478 Feb 12 '14 at 11:57
4

You shouldn't be activating / in the first place. The control sequence \slash already does (better) what you want for \SlashDesc.

If you insist for this, then you have to add the setting of / to the \hyper@normalise list. Here's a way; I have also streamlined your definition of the active slash.

\documentclass{article}
\usepackage{lipsum}
\usepackage{hyperref}

\makeatletter
\let\ORIG@hyper@normalise\hyper@normalise
\def\hyper@normalise{%
  % make / other
  \begingroup\@makeother\/%
  % now expand the original and gobble the leading \begingroup
  \expandafter\@gobble\ORIG@hyper@normalise}
\makeatother

\AtBeginDocument{\catcode`\/=\active}
\begingroup\lccode`~=`/ \lowercase{\endgroup\let~}\slash

\begin{document}

\makeatletter

\begin{minipage}{5cm}
\lipsum*[75]%
\href{http://aaa/ggg/ddd/}{aaa/bbb/ccc/ddd/eee/fff/ggg/hhh/iii/jjj/kkk/lll}
\end{minipage}

\end{document}

(Sorry, but the interface for adding pictures seems not to be working.)

  • Thanks. The next level of complications is \def\aaa{minipage code is here}\aaa. The link now is http://www.\penalty%20\exhyphenpenalty%20.com/\penalty%20\exhyphenpenalty%20aaa/\penalty%20\exhyphenpenalty%20ggg/\penalty%20\exhyphenpenalty%20ddd/\penalty%20\exhyphenpenalty%20 – olpa Feb 12 '14 at 13:17
  • @olpa No, that will definitely not work. – egreg Feb 12 '14 at 13:22
0

Thanks egreg a lot for the suggestion how to inject into \hyper@normalise. It is a new and very useful trick for me.

The solution can be generalized for other active symbols as well.

\documentclass{article}
\usepackage{lipsum}
\usepackage{hyperref}

\makeatletter
\let\ORIG@hyper@normalise\hyper@normalise
\def\ORIG@slash@letter{/}
\catcode`\/=\active
\edef\hyper@normalise{%
  \begingroup
  \def\noexpand/{\ORIG@slash@letter}%
  \noexpand\expandafter\noexpand\@gobble\noexpand\ORIG@hyper@normalise}
\makeatother

% http://tex.stackexchange.com/questions/97310/
\AtBeginDocument{\catcode`\/=\active \def/{\slash\hspace{0pt}}}

\begin{document}

\def\aaa{
\begin{minipage}{5cm}
\lipsum*[75]%
\href{http://tex.stackexchange.com/questions/160031/}{aaa/bbb/ccc/ddd/eee/fff/ggg/hhh/iii/jjj/kkk/lll}
\end{minipage}
}
\aaa

\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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