3

I want a text box (or something like it) that I can put a long string of text not separated by spaces into. It's something like a license key (so it consists of characters A-Z, a-z, 0-9, underscores, and dashes).

I've looked into using tabular, minipage, fbox, parbox, mdframed, and I just can't seem to find the behavior I'm looking for (the text extends off the page because their text wrap is looking for spaces and dashes). It's frustrating and disappointing to have done so much research for a task that can be done in Word with a copy/paste...

Is there something I overlooked? Does anyone know a way I can accomplish this?

5

1 Answer 1

2

Here I set up a loop to spit out token by token with a \penalty0 following it (which allows breaks). I do it in \ttfamily, but that can be excised.

EDITED to support underscores.

\documentclass{article}
\usepackage[nopar]{lipsum}
%%%%%%%%%%%
\newcommand\autobreak[1]{\bgroup\ttfamily\autobreakhelp#1\relax\relax\egroup}
\def\autobreakhelp#1#2\relax{%
  {\detokenize{#1}}\penalty0\ifx\relax#2\relax\else\autobreakhelp#2\relax\fi}
%%%%%%%%%%%
\begin{document}
\lipsum[1]
\autobreak{%
http://tex.stackexchange.com/questions/224354/how-to_allowbreaks-at-any-character%
}
\lipsum[2]
\end{document}

enter image description here

This will work if the inputs are limited to "A-Z, a-z, 0-9, underscores, and dashes", as requested by the OP. In fact the prohibited characters in the input stream will be {, } and %.

1
  • Thank you for the excellent answer, this is amazing. I also appreciate the note on prohibited characters.
    – user132925
    May 5, 2017 at 16:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy