I am using plain TeX and want to typeset an appendix that contains several hundred URLs. When a URL goes past the right margin, I would like TeX to stop printing (i.e. not carry into the margin, not print a warning black rectangle) and then pick up the rest of the URL on a new (non-indented) line where it left off.

Something like this, where 1, 2, 3 are akin to footnote numbers:

1: http://www.aaa.com/rem
ainder 2: http://www.bbb.
com/remainder_again  3: h

Is this possible?

I am using a Python script to generate the .tex files, so, if worst comes to worst, I can have Python estimate the content of each line. Unfortunately, I am not using a mono-spaced font, so that could turn pretty ugly.

Thanks in advance.

  • Use the url package. And welcome to TeX.SX!! – Sean Allred Oct 9 '13 at 4:28
  • 2
    @Sean: Please note the OP is using plain-tex. – morbusg Oct 9 '13 at 4:44
  • 1
    @morbusg I wonder if you have a 'true plain' solution: I've taken the easy way out and used url with miniltx :-) – Joseph Wright Oct 9 '13 at 7:01
  • Are the URL's to be clickable? – morbusg Oct 9 '13 at 7:40
  • URLs are not to be clickable. This is for printing on paper! :-) – Iron Pillow Oct 9 '13 at 16:07

Since you're generating the TeX code with Python, one option is to separate every character with \hskip0pt. For example:


  • This could really mess up kerning/typography, but then again it's a URL. (In case you care.) – Sean Allred Oct 9 '13 at 4:31
  • This worked! But there are two caveats: (1) I had escaped characters like & to {\&} in my URLs, but of course I had to unescape and then re-escape them for this solution to work, and (2) Putting \hskip0pt between every character exceeded TeX's memory capacity (I have a LOT of URLs!) but reducing it to every fifth character worked pretty well. There are a few overfull boxes, but I can live with that. – Iron Pillow Oct 9 '13 at 19:30
  • After adding the tolerance and emergencystretch from @Joseph Wright's answer, this works perfectly. – Iron Pillow Oct 10 '13 at 4:20

The LaTeX url package can be used with plain TeX using miniltx (or you could copy the minimal code, of course). For example

\input miniltx %
\input url.sty %
\hsize 4.4cm %

will give you breaking at any character using the method suggested in the url manual and Forcing linebreaks in \url. Things are dependent on line-width: with very few 'normal' spaces in the example above avoiding overfull boxes is hard, and the equivalent of LaTeX's \sloppy may also be required, e.g.

\tolerance 9999 %
\emergencystretch 3em %

I'm assuming we have to allow breaks everywhere: that is normally not such a great plan if it can be avoided.

To understand what is happening, notice that url (ab)uses math mode to allow breaking 'anywhere', making any breakable URL character into a mathbin character inside the URL.

  • One could also use eplain to load url: \input eplain \beginpackages \usepackage{url} \endpackages \enablehyperlinks \url{http://foo/bar} \bye (from the eplain manual). – morbusg Oct 9 '13 at 7:31
  • Yields a "TeX capacity exceeded, sorry" error. I thought the problem might be too many possible breakpoints (see comment to @ChrisS's answer), but even when I reduce the number of "do" macros to three, the error persists. – Iron Pillow Oct 9 '13 at 19:25
  • It appears that something to do with the \url macro could be at fault. This page has lots of examples of that causing the same error: handyfloss.wordpress.com/2006/11/30/tex-capacity-exceeded-error – Iron Pillow Oct 9 '13 at 19:28
  • @IronPillow Do you get that with exactly what I put as an example? – Joseph Wright Oct 9 '13 at 20:41
  • (1) The exact sample above runs error-free. (2) If I add an extra line above the \bye that inputs my file of 8024 \url macros, it runs error-free. (3) If I repeat (2) but delete the line \hsize 4.4cm then it yields a "capacity exceeded" error. (4) If I split the 8024 URLs into 4 paragraphs, then (3) runs without error. – Iron Pillow Oct 9 '13 at 23:48

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.