graham@max.physics.sunysb.edu (Graham Collins) (07/10/90)
What I want is a macro \un which will take \un{block of text} and produce an underlined version of "block of text" For a block of text which does not run over more than one line, the TeXbook provides a suitable macro using mathmode. However, what I need is one which will still break lines appropriately when the block of text runs on for more than one line. I've made various attempts myself, but they've all failed, demonstrating there's something I don't know about how arguments are passed to other macros. My strategy was to have \un split off the first word and underline it with the TeXbook's macro, and then \un{the remainder} provided the remainder wasn't empty. However, all the variants I tried either didn't correctly parse off each word or else the recursion never successfully terminated. Any suggestions? (The TeXbook advises making a new font with metfont!) The relevance of the query is that most magazines, unlike academic journals, regard italicising in manuscripts as a sign of amateurishness---which will seriously harm a budding writer's chances of publication. Graham P. Collins graham@max.physics.sunysb.edu collins@sbnuc1.sunysb.edu collins@sunysbnp.bitnet
grunwald@foobar.colorado.edu (Dirk Grunwald) (07/10/90)
I asked about this a while ago. Too bad I didn't look in my bag of toys. %% Usage is %% \underl <underlined text> & %% The space before "&" is important. \def\underl#1 {\leavevmode\underli #1 } \def\underli#1 {\ifx\let\next=\relax\unskip \else\let\next=\underli \ulinebox{#1} \fi\next} \def\ulinebox#1{\vtop{\hbox{\strut#1 }\hrule}}%Taken from TexHax v.88, 52
duchier@cs.yale.edu (Denys Duchier) (07/10/90)
I did this once out of curiosity. You need to make underlined fonts using MetaFont because there is no other way to get proper hyphenation to happen otherwise (so you can just forget about making each character active and have it expand into an underlined version of its original self; supposing this idea crossed your mind in the first place). Fortunately making underlined fonts is rather easy if you have MetaFont (henceforth MF). Here is how to proceed: 1. find out where the .mf files for the necessary fonts are kept on your system. usually it is in: /usr/local/lib/mf/inputs 2. depending on who is the bozo who installed MF on your system, you may have to set the following environment variables: setenv MFINPUTS .:/usr/local/lib/mf/inputs setenv MFBASES .:/usr/local/lib/mf/bases setenv MFPOOL .:/usr/local/lib/mf and you should read the man page. 3. create a directory somewhere. let's call it myfonts. in this directory create symbolic links to the .mf files for the fonts you want to create underlined versions of. 4. put the following code in myfonts/underlined.mf extra_endchar:=extra_endchar&"underlineit;"; def underlineit = if (charcode<oct"022") or ((charcode>oct"030") and (charcode<oct"136")) or ((charcode>oct"137") and (charcode<oct"176")): pickup pencircle scaled 0.4pt; draw (0,-2.5pt)--(w,-2.5pt); fi; enddef; Using a pencircle was probably not a very good idea, but nevermind this for the moment. 5. Now in csh do something like this: foreach font (*.mf) cmmf <<ENDOFFILE \mode=imagen; input underlined input $font ENDOFFILE mv mfput.tfm u$font:r.tfm mv mfput.300gf u$font:r.300gf gftopk u$font:r.300gf end Note that I say "\mode=imagen;" but you might have to say something different. 6. Now you have a set of fonts derived from the regular distribution, except their names are all prefixed with the letter `u' and all letters are identically underlined. You should tell TeX about them. Supposing .tfm files are normally kept in: /usr/local/lib/tex/fonts/tfm and assuming myfonts is in your home directory, you could say something like this: setenv TEXFONTS .:$HOME/myfonts:/usr/local/lib/tex/fonts/tfm Apparently (from vague experimental eveidence and a little guessing on my part) you should also define a fontdesc file. Copy /usr/local/lib/tex/fontdesc into myfonts, then add the following lines at the end: # myfonts font pk * 3 /<HOME>/myfonts/%f.%mpk <HOME> should be replaced with the full pathname. This might not be required, but I don't know that and you don't that, so who needs surprises. Quite frankly I don't even know what the 3 is for. I guessed and it worked, and I wasn't inclined to find out, so there! 7. Finally, you need to write some TeX code that will switch to the right fonts AND implement correctly stretching underlined space in between words. I did this (sort of) for LaTeX. I'll simply include the code at the end and you can sort it out. It was originally in file underlined.sty. To write it I simply followed the algorithm given in the TeXbook. Caveat: the file assumes that some fonts have been generated at various magnifications. Underlined text is obtained using \begin{underline} ... \end{underline}. Within the environment \hspace is redefined to produce underlined space. Well, I hope I remembered everything right and didn't leave to much out. It's really not as complicated as it sounds. Resulting output looks ok. I am sure those who really know what they are doing have run out of hair to tear out by now, and I will be informed shortly of all I did wrong, and why it was a perfectly stupid idea to begin with. So i'll learn. Hope this helps anyway. --Denys \newdimen\UL@Fwidth \newdimen\UL@Fstretch \newdimen\UL@Fshrink \newdimen\UL@Fextra \newdimen\UL@width \newdimen\UL@stretch \newdimen\UL@shrink \mathchardef\tw@m=2000 \def\UL@GlueSetup{% \UL@width \UL@Fwidth \UL@stretch \UL@Fstretch \UL@shrink \UL@Fshrink \ifnum \spacefactor > \tw@m \advance\UL@width \UL@Fextra \fi \ifnum \spacefactor = \@m \else \multiply \UL@stretch \spacefactor \divide \UL@stretch \@m \multiply \UL@shrink \@m \divide \UL@shrink \spacefactor \fi} \def\UL@Glue{\hskip \UL@width plus \UL@stretch minus \UL@shrink} \def\UL@Rule{\hrule depth 2.7pt height -2.3pt} \newif\if@ULunskip \@ULunskiptrue \def\UL@Space{\ifhmode \if@ULunskip\unskip\fi \@ULunskiptrue \UL@GlueSetup\leaders\UL@Rule\UL@Glue\fi} \def\UL@Tilde{\penalty\@M\UL@Space} {\catcode`\ =\active\gdef\UL@ActivateSpace{\catcode`\ =\active\let =\UL@Space}} {\catcode`\^^M=\active\gdef\UL@ActivateCR{\catcode`\^^M=\active\let^^M=\UL@Space}} {\catcode`\~=\active\gdef\UL@ActivateTilde{\catcode`=\active\let~=\UL@Tilde}} \def\UL@FontInfoSetup{% \UL@Fwidth = \fontdimen 2 \the\font \UL@Fstretch = \fontdimen 3 \the\font \UL@Fshrink = \fontdimen 4 \the\font \UL@Fextra = \fontdimen 7 \the\font} \def\UL@PRM{\UL@prm\UL@FontInfoSetup} \def\UL@PIT{\UL@pit\UL@FontInfoSetup} \def\UL@PBF{\UL@pbf\UL@FontInfoSetup} \def\UL@PSL{\UL@psl\UL@FontInfoSetup} \def\UL@PSF{\UL@psf\UL@FontInfoSetup} \def\UL@PSC{\UL@psc\UL@FontInfoSetup} \def\UL@PTT{\UL@ptt\UL@FontInfoSetup} \def\UL@FontStyle{% \ifnum \fam=\z@ \rm\else \ifnum \fam=\itfam \it\else \ifnum \fam=\slfam \sl\else \ifnum \fam=\bffam \bf\else \ifnum \fam=\ttfam \tt\else \ifnum \fam=\sffam \sf\else \ifnum \fam=\scfam \sc\else \fi\fi\fi\fi\fi\fi\fi} \def\UL@SpaceRule{\leaders\UL@Rule\hskip} \def\UL@hspace#1{\leavevmode \expandafter\UL@SpaceRule #1\relax \@ULunskipfalse} \def\UL@hspacer#1{\leavevmode \vrule width\z@ \nobreak \expandafter\UL@SpaceRule #1\relax \hskip\z@} \def\underlined{% \UL@ActivateSpace \UL@ActivateCR \UL@ActivateTilde \def\rm{\protect\UL@PRM}% \def\it{\protect\UL@PIT}% \def\bf{\protect\UL@PBF}% \def\sl{\protect\UL@PSL}% \def\sf{\protect\UL@PSF}% \def\sc{\protect\UL@PSC}% \def\tt{\protect\UL@PTT}% \let\@hspace\UL@hspace \let\@hspacer\UL@hspacer \UL@FontStyle } \let\UL@vpt\vpt \def\vpt{% \UL@vpt \def\UL@prm{\@getfont\UL@prm\z@\@vpt{ucmr5}}% \def\UL@pit{\@subfont\it\rm}% \def\UL@psl{\@subfont\sl\rm}% \def\UL@pbf{\@getfont\UL@pbf\bffam\@vpt{ucmbx5}}% \def\UL@ptt{\@subfont\tt\rm}% \def\UL@psf{\@subfont\sf\rm}% \def\UL@psc{\@subfont\sc\rm}% } \let\UL@vipt\vipt \def\vipt{% \UL@vipt \def\UL@prm{\@getfont\UL@prm\z@\@vipt{ucmr6}}% \def\UL@pit{\@subfont\it\rm}% \def\UL@psl{\@subfont\sl\rm}% \def\UL@pbf{\@getfont\UL@pbf\bffam\@vipt{ucmbx6}}% \def\UL@ptt{\@subfont\tt\rm}% \def\UL@psf{\@subfont\sf\rm}% \def\UL@psc{\@subfont\sc\rm}% } \let\UL@viipt\viipt \def\viipt{% \UL@viipt \def\UL@prm{\@getfont\UL@prm\z@\@viipt{ucmr7}}% \def\UL@pit{\@subfont\it\rm}% \def\UL@psl{\@subfont\sl\rm}% \def\UL@pbf{\@getfont\UL@pbf\bffam\@viipt{ucmbx7}}% \def\UL@ptt{\@subfont\tt\rm}% \def\UL@psf{\@subfont\sf\rm}% \def\UL@psc{\@subfont\sc\rm}% } \let\UL@viiipt\viiipt \def\viiipt{% \UL@viiipt \def\UL@prm{\@getfont\UL@prm\z@\@viiipt{ucmr8}}% \def\UL@pit{\@getfont\UL@pit\itfam\@viiipt{ucmti8}}% \def\UL@psl{\@getfont\UL@psl\slfam\@viiipt{ucmsl8}}% \def\UL@pbf{\@getfont\UL@pbf\bffam\@viiipt{ucmbx8}}% \def\UL@ptt{\@getfont\UL@ptt\ttfam\@viiipt{ucmtt8}\@nohyphens\UL@ptt\@viiipt}% \def\UL@psf{\@getfont\UL@psf\sffam\@viiipt{ucmss8}}% \def\UL@psc{\@getfont\UL@psc\scfam\@viiipt{ucmcsc10}}% KLUDGE } \let\UL@ixpt\ixpt \def\ixpt{% \UL@ixpt \def\UL@prm{\@getfont\UL@prm\z@\@ixpt{ucmr9}}% \def\UL@pit{\@getfont\UL@pit\itfam\@ixpt{ucmti9}}% \def\UL@psl{\@getfont\UL@psl\slfam\@ixpt{ucmsl9}}% \def\UL@pbf{\@getfont\UL@pbf\bffam\@ixpt{ucmbx9}}% \def\UL@ptt{\@getfont\UL@ptt\ttfam\@ixpt{ucmtt9}\@nohyphens\UL@ptt\@ixpt}% \def\UL@psf{\@getfont\UL@psf\sffam\@ixpt{ucmss9}}% \def\UL@psc{\@getfont\UL@psc\scfam\@ixpt{ucmcsc10}}% KLUDGE } \let\UL@xpt\xpt \def\xpt{% \UL@xpt \def\UL@prm{\@getfont\UL@prm\z@\@xpt{ucmr10}}% \def\UL@pit{\@getfont\UL@pit\itfam\@xpt{ucmti10}}% \def\UL@psl{\@getfont\UL@psl\slfam\@xpt{ucmsl10}}% \def\UL@pbf{\@getfont\UL@pbf\bffam\@xpt{ucmbx10}}% \def\UL@ptt{\@getfont\UL@ptt\ttfam\@xpt{ucmtt10}\@nohyphens\UL@ptt\@xpt}% \def\UL@psf{\@getfont\UL@psf\sffam\@xpt{ucmss10}}% \def\UL@psc{\@getfont\UL@psc\scfam\@xpt{ucmcsc10}}% } \let\UL@xipt\xipt \def\xipt{% \UL@xipt \def\UL@prm{\@getfont\UL@prm\z@\@xipt{ucmr10 \@halfmag}}% \def\UL@pit{\@getfont\UL@pit\itfam\@xipt{ucmti10 \@halfmag}}% \def\UL@psl{\@getfont\UL@psl\slfam\@xipt{ucmsl10 \@halfmag}}% \def\UL@pbf{\@getfont\UL@pbf\bffam\@xipt{ucmbx10 \@halfmag}}% \def\UL@ptt{\@getfont\UL@ptt\ttfam\@xipt{ucmtt10 \@halfmag}\@nohyphens\UL@ptt\@xipt}% \def\UL@psf{\@getfont\UL@psf\sffam\@xipt{ucmss10 \@halfmag}}% \def\UL@psc{\@getfont\UL@psc\scfam\@xipt{ucmcsc10 \@halfmag}}% } \let\UL@xiipt\xiipt \def\xiipt{% \UL@xiipt \def\UL@prm{\@getfont\UL@prm\z@\@xiipt{ucmr12}}% \def\UL@pit{\@getfont\UL@pit\itfam\@xiipt{ucmti12}}% \def\UL@psl{\@getfont\UL@psl\slfam\@xiipt{ucmsl12}}% \def\UL@pbf{\@getfont\UL@pbf\bffam\@xiipt{ucmbx12}}% \def\UL@ptt{\@getfont\UL@ptt\ttfam\@xiipt{ucmtt12}\@nohyphens\UL@ptt\@xiipt}% \def\UL@psf{\@getfont\UL@psf\sffam\@xiipt{ucmss12}}% \def\UL@psc{\@getfont\UL@psc\scfam\@xiipt{ucmcsc10 \@magscale1}}% } \let\UL@xivpt\xivpt \def\xivpt{% \UL@xivpt \def\UL@prm{\@getfont\UL@prm\z@\@xivpt{ucmr10 \@magscale2}}% \def\UL@pit{\@getfont\UL@pit\itfam\@xivpt{ucmti10 \@magscale2}}% \def\UL@psl{\@getfont\UL@psl\slfam\@xivpt{ucmsl10 \@magscale2}}% \def\UL@pbf{\@getfont\UL@pbf\bffam\@xivpt{ucmbx10 \@magscale2}}% \def\UL@ptt{\@getfont\UL@ptt\ttfam\@xivpt{ucmtt10 \@magscale2}\@nohyphens\UL@ptt\@xivpt}% \def\UL@psf{\@getfont\UL@psf\sffam\@xivpt{ucmss10 \@magscale2}}% \def\UL@psc{\@getfont\UL@psc\scfam\@xivpt{ucmcsc10 \@magscale2}}% } \let\UL@xviipt\xviipt \def\xviipt{% \UL@xviipt \def\UL@prm{\@getfont\UL@prm\z@\@xviipt{ucmr17}}% \def\UL@pit{\@getfont\UL@pit\itfam\@xviipt{ucmti10 \@magscale3}}% \def\UL@psl{\@getfont\UL@psl\slfam\@xviipt{ucmsl10 \@magscale3}}% \def\UL@pbf{\@getfont\UL@pbf\bffam\@xviipt{ucmbx10 \@magscale3}}% \def\UL@ptt{\@getfont\UL@ptt\ttfam\@xviipt{ucmtt10 \@magscale3}\@nohyphens\UL@ptt\@xviipt}% \def\UL@psf{\@getfont\UL@psf\sffam\@xviipt{ucmss10 \@magscale3}}% \def\UL@psc{\@getfont\UL@psc\scfam\@xviipt{ucmcsc10 \@magscale3}}% } \let\UL@xxpt\xxpt \def\xxpt{% \UL@xxpt \def\UL@prm{\@getfont\UL@prm\z@\@xxpt{ucmr10 \@magscale4}}% \def\UL@pit{\@getfont\UL@pit\itfam\@xxpt{ucmti10 \@magscale4}}% \def\UL@psl{\@getfont\UL@psl\slfam\@xxpt{ucmsl10 \@magscale4}}% \def\UL@pbf{\@getfont\UL@pbf\bffam\@xxpt{ucmbx10 \@magscale4}}% \def\UL@ptt{\@getfont\UL@ptt\ttfam\@xxpt{ucmtt10 \@magscale4}\@nohyphens\UL@ptt\@xxpt}% \def\UL@psf{\@getfont\UL@psf\sffam\@xxpt{ucmss10 \@magscale4}}% \def\UL@psc{\@getfont\UL@psc\scfam\@xxpt{ucmcsc10 \@magscale4}}% } \let\UL@xxvpt\xxvpt \def\xxvpt{% \UL@xxvpt \def\UL@prm{\@getfont\UL@prm\z@\@xxvpt{ucmr10 \@magscale5}}% \def\UL@pit{\@subfont\it\rm}% \def\UL@psl{\@subfont\sl\rm}% \def\UL@pbf{\@getfont\UL@pbf\bffam\@xxvpt{ucmbx10 \@magscale5}}% \def\UL@ptt{\@subfont\tt\rm}% \def\UL@psf{\@subfont\sf\rm}% \def\UL@psc{\@subfont\sc\rm}% }