I have a sentence that contains a number of long dataset names. I would like to allow LaTeX to break these names at certain positions that I would like to specify somehow just like I can use \- to allow a word break with hyphenation. But: I would like LaTeX not to insert a dash (which could be mistaken as belonging to the dataset name). How can I do this?

(Something similar is realized in the url package so I guess I could just read that code :) I would not like to use the url package here to be able to make a syntactical (and typographic) difference between urls and datset names.)


You could insert \allowbreak whereever a break without hyphen shall be allowed, such as

long\allowbreak word
  • Is there a way to allow line breaks only at the specified positions? Otherwise LaTeX will often prefer to still add hyphens and break at other positions. (This happens When using e.g. hyphenat for automatic hyphenation.) – fuenfundachtzig Aug 23 '11 at 17:36
  • You can use \usepackage[none]{hyphenat} together with \allowbreak. – Stefan Kottwitz Aug 23 '11 at 17:44

In addition to Stefan’s answer:

You can also write long""word, but this is a babel-shortcut (as most of the following). As Herbert pointed out these shortcuts are language specific. The list is taken form a german home page and are in the german section of babels manual.

- hyphen sign, no others in this word (hy-phenation > hy-|phenation)
"= hypen sign that allows other breaks (h"=yphenation > h-|y|phen|a|tion)
"~ hyphen sign without line break (hy"~phenation > hy-phenation)
\- possible hyphenation with sign (h\-yphenation > h|y|phen|a|tion)
"" possible hyphenation without sign ((super"~)""hyphenation > (super-)*hy|pen|a|tion)
"| break ligature and allow hyphenation

[( code > output); the pipe indicates possible line break with hyphen sign; asterisk indicates possible line break without sign.]

Source: This german homepage.

  • 1
    Seems to be babel specific, yes. – fuenfundachtzig Aug 21 '11 at 12:23
  • @Tobi: not only babel specific, also language specific – Herbert Aug 22 '11 at 8:51
  • @Herbert: Oh you’re right. I added this to my post. – Tobi Aug 22 '11 at 9:08
  • 1
    As far as I can tell. "~ forbids hyphenation in the rest of the word. – Raphael Oct 8 '13 at 16:18
  • 1
    @koppor: see tex.stackexchange.com/a/321066/4918 ;-) – Tobi Feb 1 '17 at 18:47

it is also possible to allow hyphenation on Characters

\textwidth=10cm% only for demo
some very long text before the hyphenated code

some very long text before the hyphenated code
  • Very nice, because it's automatic and does not add hyphens. But what if I have e.g. longtextthatdoesnothavecharactersurlbreaksatatanypositionbutneedstobebroken -- I'd need to indicate how (where) to break this, but the \Code enviroment will print any commands in verbatim mode... – fuenfundachtzig Aug 21 '11 at 12:40
  • see edited answer – Herbert Aug 21 '11 at 13:31
  • OK, that's certainly one solution. Although I had hoped for something more along the lines of \allowbreak or \-... Because like this it's still not possible to specify where exactly LaTeX should break the line. – fuenfundachtzig Aug 23 '11 at 12:31

I've had good results with


Where X can be anything from 0 to 4. Zero means "if you really want, you can break the line here", while four means "break the line here, always".

To allow for long word breaking, you can insert it like this:


I'm not sure if it does not require specific packages though.


From The TeXbook:

\discretionary{<pre-break text>}{<post-break text>}{<no-break text>}

You could try something like:

\newcommand{\datasetname}{My\sep long\sep data\sep set\sep name}

A possibly “gentle” solution is to input your long words with spaces where the line breaks are allowed. The separator is customizable, here I added an optional argument for changing it at will.

I also disabled hyphenation by setting a language with no patterns; this is not necessary if a monospaced font is uses, as usually monospaced fonts disable hyphenation.

\NewDocumentCommand{\Code}{ O{~} m }
  \tl_set:Nn \l_tmpa_tl { #2 }
  \tl_replace_all:Nnn \l_tmpa_tl { #1 } { \allowbreak }
  \language\csname l@nohyphenation\endcsname % or \language255
  \tl_use:N \l_tmpa_tl

some very long text before the hyphenated code
\Code{some very long text before thehyphenated code}

some very long text before the hyphenated code


\Code{some very long text before thehyphenated code}

enter image description here


@fuenfundachzig: Since you're familiar with the url package, you may want to try the following: Include the instructions \usepackage{url} and \urlstyle={same} in the preamble (instructing the url package to use the main text font for URLs), and then enclose the words that you'd like to be allow broken up inside \url{...} commands. In my experience, this works very well most of the time, but it's not 100% foolproof (narrensicher?), naturally.

  • Oops, just noticed that this answer is a near-perfect duplicate of the one posted by Herbert! Sorry. – Mico Aug 20 '11 at 17:00
  • 2
    You don't need to write @fuenfundachtzig here, as the question asker, he or she will automatically be notified of your answer, just like you as the answerer ("post owner") will be notified of this comment of mine without me using the @.... I don't think it's a problem that your answer is very similar to Herbert's. You could edit your answer to highlight what's different (and maybe better) about your solution. If the differences are really tiny, you could delete your answer and add a comment to Herbert's answer. And finally, foolproof is a good translation of narrensicher :). – doncherry Aug 20 '11 at 18:03

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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