9

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
ttp://www.ccc.com/ending

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.

6
  • Use the url package. And welcome to TeX.SX!! Oct 9, 2013 at 4:28
  • 2
    @Sean: Please note the OP is using plain-tex.
    – morbusg
    Oct 9, 2013 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, 2013 at 7:01
  • Are the URL's to be clickable?
    – morbusg
    Oct 9, 2013 at 7:40
  • URLs are not to be clickable. This is for printing on paper! :-) Oct 9, 2013 at 16:07

2 Answers 2

1

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

\def\a{a\hskip0pt}
\def\b{\a\a\a\a\a\a\a\a\a\a}
\def\c{\b\b\b\b\b\b\b\b\b\b}
\def\d{\c\c\c\c\c\c\c\c\c\c}

\d
3
  • This could really mess up kerning/typography, but then again it's a URL. (In case you care.) Oct 9, 2013 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. Oct 9, 2013 at 19:30
  • After adding the tolerance and emergencystretch from @Joseph Wright's answer, this works perfectly. Oct 10, 2013 at 4:20
4

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 %
\urlstyle{rm}
\def\UrlBreaks{\do\/\do\a\do\b\do\c\do\d\do\e\do\f\do\g\do\h\do\i\do\j\do\k\do\l\do\m\do\n\do\o\do\p\do\q\do\r\do\s\do\t\do\u\do\v\do\w\do\x\do\y\do\z\do\A\do\B\do\C\do\D\do\E\do\F\do\G\do\H\do\I\do\J\do\K\do\L\do\M\do\N\do\O\do\P\do\Q\do\R\do\S\do\T\do\U\do\V\do\W\do\X\do\Y\do\Z}
\hsize 4.4cm %
\noindent
1.~\url{http://www.aaa.com/remainder}
2.~\url{http://www.bbb.com/remainder_again}
3.~\url{http://www.ccc.com/ending}
\bye

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.

7
  • 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, 2013 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. Oct 9, 2013 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 Oct 9, 2013 at 19:28
  • @IronPillow Do you get that with exactly what I put as an example?
    – Joseph Wright
    Oct 9, 2013 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. Oct 9, 2013 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.