

# Make a .tex file (first argument) suitable for emailing by adding a space
# at the beginning of lines starting with "From" and inserting "%" characters
# to break long lines down to lines of at most 78 characters (or length
# specified by environment variable LINELIM).
# Actually just breaks any given line at most once, then calls longlines
# to see if any long lines remain.  This program could then be run again.

lim=${LINELIM-78}

tempfile=/tmp/tex2email.$USER.$$

sed -e 's+^From+ From+' -e 's+^\(.\{77\}\)\([^ ].*\)+\1%\
\2+' -e 's+^\(.\{77\}\)\([ ].*\)+\1%\
\\ \2+' $1 > $tempfile

mv $tempfile $1

longlines $1
