In my thesis a have a lot of occurences of the word like ABC2011abc and I want them to be hyphenated as ABC2011\-abc.

Is it possible to define a global hyphenation rule, like say with \hyphenation?

Search and replace would be a last measure and feels very un-LaTeX.

  • How about defining a macro for this? \newcommand{\ABC2011abc}{ABC2011\-abc} – ℝaphink Apr 27 '11 at 7:54
  • 1
    @Raphink: Numbers are not allowed in macro names. Nevertheless, your idea to define a macro is good. Just the name must be changed a little. – Martin Scharrer Apr 27 '11 at 8:02
  • @Raphink: You should put your (corrected) suggestion in an answer, so that the community can upvote it. – ipavlic Apr 27 '11 at 8:18

Since \hypenation doesn't take numbers, you could define a macro for it:


and use it everytime you want to typeset this word.

  • 3
    You might want to add \xspace from the xspace package at the end of the replacement text, otherwise you have to add {} after the macro to avoid the removal of following spaces. Also I would use a short macro name, otherwise it's easier to type the \- by hand. – Martin Scharrer Apr 27 '11 at 8:30
  • @Martin: thanks for the suggestion of using xspace. I'm actually used to adding {} after most macros when I call them, since this is how many standard (e.g. frenchb) macros behave. There's still an advantage of using a macro over adding \- manually, which is to modify the macro later on if required. – ℝaphink Apr 27 '11 at 8:35
  • @Tobi: As @Martin said, you can change the macro name (without using digits though) to make it easier to type. – ℝaphink Apr 27 '11 at 8:57
  • I just got bitten by a global search and replace to put the macros i defined in place. I think it's going to be a lot easier to just replace the overflowing occurrences of the words just before printing. – tobi Apr 27 '11 at 9:13
  • How so bitten ? – ℝaphink Apr 27 '11 at 9:14

A variant on Raphink's answer: define a macro like


(i.e. not using \newcommand). This makes a "delimited macro" using a plain TeX construction, where the 2011abc part is not actually in the name of the macro but is required to be present when the macro is expanded. The actual name of the macro is \ABC, so this is prone to unexpected errors if you also define \ABC2011cde, however.

For some reason, this gives bizarre results using \newcommand, probably because of how it internally processes the macro name to check that it was not previously defined.

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.