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 am setting e.g. directory names in a typewriter font. These names can become long. With the hyphenat package, I enabled hyphenation. Now, what is missing, is that the hyphenation character is replaced e.g. by a backwards oriented arrow.

Thus, what I want to do is something like

\usepackage[htt]{hyphenat}
\newcommand{\origttfamily}{}%
\let\origttfamily=\ttfamily %
\renewcommand{\ttfamily}{\origttfamily \hyphenchar\font\ensuremath{\hookleftarrow}}
\begin{document}
  \texttt{/etc/really/long{\fshyp}directory{\fshyp}name/}
\end{document}

However, \ensuremath{\hookleftarrow} does not work in this case - it is not a single character.

Can somebody point me towards a solution? Thanks a lot!

(moved from http://stackoverflow.com/questions/4749869/latex-replace-hyphenation-character-by-a-backwards-arrow)

share|improve this question
add comment

3 Answers

up vote 3 down vote accepted

You cannot set the \hyphenchar to a character from a different font, but you can redefine \BreakableSlash:

\documentclass{minimal}
\usepackage[htt]{hyphenat}
\newsavebox\leftarrowbox
\sbox\leftarrowbox{$\leftarrow$}
\makeatletter
\renewcommand*{\BreakableSlash}{%
  \leavevmode
  \prw@zbreak
  /%
  \discretionary{\usebox\leftarrowbox}{}{}%
  \prw@zbreak
}
\makeatother
\begin{document}
\parbox{20mm}{%
  \texttt{/etc\fshyp really\fshyp long\fshyp directory\fshyp name/}%
}
\end{document}
share|improve this answer
add comment

As I know, \hyphenchar can be only used as

\hyphenchar\font=<number>

where \font is a TeX font, and <number> is the code of the glyph in the font. For example:

\font\tenrm=cmr10
\font\tentt=cmtt10
\hyphenchar\tenrm=`\*    % set the hyphenation char of cmr10 to be *
\hyphenchar\font=`\-     % set the hyphenation char of current font to be -
\hyphenchar\tentt=-1     % set the hyphenation char of cmtt19 to be empty

(Here, \* after acute accent means character code of symbol *.)

That is to say, you can't use a hook left arrow symbol as a hyphenation character, if the font you are using doesn't have this glyph.

Maybe you may use some special font to solve this problem, or someone else have other trick.

There is another way to get speical hyphenation manually. For example, we can redefine active character ~ to do this:

\def~{\discretionary{\mbox{$\hookleftarrow$}}{}{}}
\parbox{2em}{dif~fer~ent}
share|improve this answer
add comment

If you come into a situation where you want your hyphenchar to be something like \hookleftarrow, and Philipp's answer does not help, then there's still the option to create a virtual font. By this you can circumvent both the problems that \hookleftarrow is from a different font and that it's not a single character. It's not as hard as it might sound: If you need this, I can fill in the details.

share|improve this answer
    
Details have been requested: tex.stackexchange.com/q/25852/86 –  Andrew Stacey Aug 16 '11 at 14:19
    
@Andrew: Thanks for notifying me. However, it appears that I hardly remember the details :-( –  Hendrik Vogt Aug 16 '11 at 19:46
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.