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


8 Answers 8


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.) Commented Aug 23, 2011 at 17:36
  • 1
    You can use \usepackage[none]{hyphenat} together with \allowbreak.
    – Stefan Kottwitz
    Commented Aug 23, 2011 at 17:44
  • 2
    Also extremely useful if one has a text-segment that goes like WORD/WORD, where the ideal breaking point would be »/«
    – Kubo
    Commented Jan 21, 2022 at 16:07
  • This worked great for my use case: \texttt{sysctl net.\allowbreak ipv6.\allowbreak conf.\allowbreak interface.\allowbreak accept\_dad\allowbreak =\allowbreak 0}. Commented Jan 4 at 17:05

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. Commented Aug 21, 2011 at 12:23
  • @Tobi: not only babel specific, also language specific
    – user2478
    Commented Aug 22, 2011 at 8:51
  • @Herbert: Oh you’re right. I added this to my post.
    – Tobi
    Commented Aug 22, 2011 at 9:08
  • 1
    As far as I can tell. "~ forbids hyphenation in the rest of the word.
    – Raphael
    Commented Oct 8, 2013 at 16:18
  • 1
    @koppor: see tex.stackexchange.com/a/321066/4918 ;-)
    – Tobi
    Commented Feb 1, 2017 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... Commented Aug 21, 2011 at 12:40
  • see edited answer
    – user2478
    Commented Aug 21, 2011 at 13:31
  • 1
    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. Commented Aug 23, 2011 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}

@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
    Commented Aug 20, 2011 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
    Commented Aug 20, 2011 at 18:03

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


Use pakage seqsplit, in main text: \seqsplit{qervnjksnvdjsn}, this means it can linebreak between every singal character, without dash or hyphen sign. Sorry for bad English. :)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .