3

I have the following situation: very long function names that are put into text with a macro \fun{this-is-a-very-long-fuction-name}. This macro includes indexing, but then finally puts the function name in bold as a hyperlink. I want to have LaTeX do line breaks for adjustment, but break the emboldened name only at the hyphens without adding a hyphen; the hyperlink must work. How can I do that? Specifically, my \fun macro is

\def\fun#1{\funbb{#1}{#1}\indexfun{#1}}
\def\funbb#1#2{\hyperlink{#1}{\textbf{#2}}}
\def\indexfun#1{\index{#1@\textbf{#1}}}

The rest of the document should have normal line breaks with adjustment and hyphenation.


Edit: Here is an example:

\documentclass{book}
\usepackage{geometry}
\usepackage{txfonts}
\usepackage[breaklinks]{hyperref}
\geometry{total={115.84mm,195mm}}
\def\fun#1{\hyperlink{#1}{\textbf{#1}}}
\begin{document}
we need to include the lengths of all months from Tishri until \fun{last-month-of-hebrew-year}
\end{document}

When compiled with latex, it produces the following in the DVI:

DVI output

Note that it breaks the function name after the "he" of "hebrew". Also, it is not a hyperlink, as it should be.

ShreevatsaR
  • 45,428
  • 10
  • 117
  • 149
  • 4
    latex doesn't hyphenate hyphenated words, it just breaks at the existing hyphens, so it isn't clear what you need other than teh default behaviour. – David Carlisle Jun 27 '17 at 18:07
  • For example, last-month-of-hebrew-year gets hyphenated after the "he" of "hebrew" and it is not a hyperlink – Edward Reingold Jun 29 '17 at 14:31
  • @EdwardReingold Thanks, I assume you are using latex and not pdflatex, as I was able to reproduce this only with the former. I have edited the question to include your example, and voted to reopen it. (BTW, there is a warning message in the output that says “Package hyperref Warning: You have enabled option breaklinks'. But driverhdvips.def' does not suppport this. Expect trouble with the link areas of broken links.”) – ShreevatsaR Jul 03 '17 at 19:50
  • That explains the broken link; but the bad hyphenation? Is there a way around the two problems? – Edward Reingold Jul 03 '17 at 20:48
  • Using pdflatex instead of latex is the only solution I know of (and it solves both problems; also you don't need the [breaklinks] option as it's set automatically). I don't know if you have compelling reasons to go the DVI route; working around those reasons (so that you can directly produce PDF) may be easier than fixing this. Maybe someone with more knowledge of the inner workings of the hyperref package will post an answer. – ShreevatsaR Jul 04 '17 at 02:35
  • Unfortunately I must use dvips, so I cannot use pdflatex (which would require many, many changes to my manuscript). – Edward Reingold Jul 04 '17 at 14:51
  • 2
    (@ShreevatsaR). I made some experiments with TeX’s tracing facilities, and it turned out that, when the hdvips driver is used, discretionaries are not added after explicit hyphens, contrary to what normally happens (cf. The TeXbook, p. 286, sixth to fourth line from the bottom). Since the \hyphenchar is not changed, in all probability this is achieved by typesetting the link in restricted horizontal mode and subsequently \unhboxing it; in any case, the lack of discretionaries fully explains the fact that the word “hebrew” gets hyphenated (see p. 454, esp. ll. -8 to -5). – GuM Jul 04 '17 at 20:34
  • Cf., indeed, the definition of \pdf@rect in hdvips.def. – GuM Jul 04 '17 at 20:42
  • Via the related questions I found this question. Some of those answers may work for you. Unfortunately none of them do exactly what's asked here, but the implementation of the suggested breakurl package may have some clues… – ShreevatsaR Jul 04 '17 at 21:36
  • Is there a way to set \hyphenchar to nil temporarily in my \fun macro? – Edward Reingold Jul 05 '17 at 14:05
  • Do you have any reason not to compile with pdflatex? – Andrew Swann Nov 05 '17 at 15:32
  • Yes: I need pstricks for the (many, many) diagrams. – Edward Reingold Nov 06 '17 at 21:42
  • Any news here ? – Bobyandbob Jun 03 '18 at 20:29

0 Answers0