0

I have been struggling to find a way to wrap text content in LaTeX.

For example, if I have a piece of text which is something like

dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd

Of course, this is not something you would normally do in a document but in some cases like long URLs the content can be long like this. Yes, you could use \url etc.. but I want it as plain text with no other markup applied to the content.

So when there is no spacing between the start of the text and the end of the margin then the text just continues where I would expect the content to wrap onto a new line when reaching the margin.

Is there a way I can get LaTeX to wrap the text and handle this sort of problem?

root92
  • 125

1 Answers1

1

For example, you can define \enablehyph macro:

\def\enablehyph#1{\enablehyphA #1\end}
\def\enablehyphA#1{\ifx\end#1\unskip\unpenalty
   \else#1\penalty0\hskip0pt plus1pt\relax
   \expandafter\enablehyphA\fi}

\enablehyph{dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd}

This macro inserts \penalty0 \hskip0pt plus1pt between each letter of the word. It means that the kerning between letters is lost.

wipet
  • 74,238
  • Thank you, this works. However, is there away to apply this across all the content without having to include it each time? – root92 Jun 30 '21 at 13:14
  • @DanMaia I am going to take a stab and say the short answer is "no". The problem would be on not knowing whether a sequence of characters is plain text for which to apply \penalty0 or some argument to a command, for example 15pt, in which the application of extra interleaved tokens would break the code. – Steven B. Segletes Jul 29 '21 at 09:10
  • @DanMaia What do you mean with “all the content”? Do you really want that any word, short or long, is split at random places? – egreg Jul 29 '21 at 12:51