9

In many place in my current text I have to insert something like Name_of_model for instance. I found the last suggestion in this answer very helpful. However, I am facing a problem when it come to hyphenation of the argument of the macro \escapeus. How can I improve \escapeus so it will enable hyphenation of the argument. In particular, if hyphenation is needed, it should put it right after an underscore, for example: Name_of_-model.

Inspired by this one, I tried to modify the definition given by @egreg above as follows:

\DeclareRobustCommand*{\escapeus}[1]{%
  \begingroup\@activeus\scantokens{#1\endinput}\endgroup}
\begingroup\lccode`\~=`\_\relax
\lowercase{\endgroup\def\@activeus{\catcode`\_=\active \let~\_\discretionary{-}{}{}}}

All my attempts (which included moving the _ around) failed.

How can I improve the code above, so it will enable hyphenation of the argument of \escapeus?

7
\let~\_\discretionary{-}{}{}

defines _ to be \_ then inserts the discretionary at the point of definition You intended

\def~{\_\discretionary{-}{}{}}

That fixes your original definition, an alternative mechanism, which doesn't work in the original OT1 encoding, is just to make _ a normal character then you will get some automatic hyphenation (more if you used special patterns) and can specify hyphenation points in _ words using \hyphenation

enter image description here

\documentclass{article}

\usepackage[T1]{fontenc}
\textwidth3cm

\catcode`\_=12
\lccode`\_`\_

\hyphenation{four_-fifty-five_-six one_-two_-three}

\begin{document}


one two thee four one_two_three four_fiftyfive_six
one two thee four one_two_three four_fiftyfive_six


\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.