malouf@acsu.buffalo.edu (Robert Malouf) (11/01/90)
Does anyone know of a macro for formatting glossed examples in TeX? I want to include examples like (1) or (2) in a paper. (1) Mosimane o- bed- its-w- e ke monna. boy SUBJ-beat-PRV-PASS-MOOD by man `The/*a boy was beaten by a/the man.' (2) Mosimane o-bed-its-w-e ke monna. boy SUBJ-beat-PRV-PASS-MOOD by man `The/*a boy was beaten by a/the man.' Thanks in advance for any advice. Rob Malouf malouf@acsu.buffalo.edu
neubauer@bsu-ucs.uucp (Paul Neubauer) (11/01/90)
In article <43647@eerie.acsu.Buffalo.EDU>, malouf@acsu.buffalo.edu (Robert Malouf) asks: > Does anyone know of a macro for formatting glossed examples in TeX? I want to > include examples like (1) or (2) in a paper. Well, now, this is a question that I have been worrying about since I started to get interested in TeX (and LaTeX). Unfortunately, that has not been real long and I'm still not very good. However, I have got something that appears to more or less work. I am posting it rather than mailing it to Robert in the hope that I can get some useful feedback from more competent TeXnicians. Here are some macros that I have cobbled together. (I have put them into a .sty file that I am still working on, but I am by no means committed to sticking with. Any improvements will be gratefully accepted.) (These are for LaTeX, BTW, though I assume that something similar could be arranged for plain TeX, using some other construct instead of "list".) %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % linguistics macros for examples \newcounter{exampleno} \newcounter{subexampleno} \def\theexampleno{\arabic{exampleno}.} \def\thesubexampleno{\theexampleno \alph{subexampleno})} % Note that this last def produces examples labelled: % 1.a) fkdjslfkdsjl;asjldsjh % 1.b) kewjhtrlehjodsfsdfljkhsdf % etc, which is NOT exactly optimal. I haven't got anything better, so this is % one of the places where I am hoping for help. I want: % 1.a) lkjfdslafjd;lkjaslkfjd;s % b) fdjlsjfdlfdjksl;jfl % yet I also would like to have cross-references in the text to (1b) or (1.b) % rather than to 1.b) or, worse, b) % This next environment seems to work more or less reasonably for plain % (English-language) examples. \newenvironment{example}{ \stepcounter{exampleno} \typeout{Example number \theexampleno} \def\*{\strut\kern-\starhang*} \begin{list}{\theexampleno\hfill}{ \leftmargin 3.5em \labelwidth 2.5em }\item }{\end{list}} \newenvironment{abexample}{ \stepcounter{exampleno} \typeout{Example number \theexampleno} \begin{list}{\thesubexampleno\hfill}{ \usecounter{subexampleno} \def\*{\strut\kern-\starhang*} \leftmargin 3.5em \labelwidth 2.5em } }{\catcode\lq*=12 \end{list}} \newenvironment{glossedexample}{ \stepcounter{exampleno} \typeout{Example number \theexampleno} \def\*{\strut\kern-\starhang*} \begin{list}{\raisebox{\arraystretch \ht\strutbox}{\theexampleno}\hfill}{ \leftmargin 3.5em \labelwidth 2.5em \raggedbottom \@itempenalty 10000 \interlinepenalty 10000 } }{\end{list}} \def\@gobblelbracket{\@ifnextchar [{\@gobble}{\ignorespaces}} \def\@gobblerbracket{\@ifnextchar ]{\@gobble}{\ignorespaces}} \def\stacktext#1{\begin{tabular}{l}#1 \end{tabular}} \def\translation{\item[]} \def\gloss{\item\@glossbegin} \def\@glossbegin#1{ \@gobblelbracket#1\@gloss } \def\@gloss#1{ \stacktext{#1}\rule[-3ex]{1ex}{0pt}\@glossend } \def\@glossend{ \@ifnextchar]{\@gobblerbracket}{\@gloss} } \newdimen\starhang \setbox0=\hbox{*} \starhang=\wd0 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Some more notes on the preceding macros: The \typeout line in each macro is just to help me keep track of what LaTeX is doing and has no other significance. I may well delete these lines after I am finished debugging. \begin{example} This is an ordinary linguistic example in English with no gloss or other fancy formatting to worry about. \end{example} Note that each of the example macros contains the line: \def\*{\strut\kern-\starhang*} The function of this local definition of \* is to allow the TEXT of all examples on the page to line up, regardless of a preceding asterisk. Unfortunately, I have been able to do this only with a \* macro, rather than the a priori more desireable alternative of making * active and having it cause a kern to the left. (Note that this is only more desireable IF we assume that there will be no asterisks in the text of the example.) For example, consider a pair of examples like: \begin{abexample} \item\label{ex:thumb} I caught my thumb in the door. \item\label{ex:finger} \*I caught a finger in the door. \end{abexample} We would not use \ref{ex:finger} if what got caught was a thumb; nor \ref{ex:thumb} if what got caught was one of the four non-thumbs. The glossedexample macro is presumably quite opaque (at least it is to me :-). The intended usage is something like: \begin{glossedexample} \gloss[{Mosimane\\boy}{o-\\SUBJ-}{bed-\\beat-}{its-\\PRV}{w-\\PASS}{e\\MOOD} {ke\\by}{monna.\\man}] \translation{`The/*a boy was beaten by a/the man.'} \end{glossedexample} Note that the single quotes around the translation could presumably be added to the macro without much difficulty. I simply have not thought to do so yet as I have not decided for the style I was creating whether I wanted the translation in a different typeface (e.g., italics) or what. Note that the preceding puts a fair amount of space between the glossed elements, so you may well prefer: \begin{glossedexample} \gloss[{Mosimane\\boy}{o-bed-its-w-e\\SUBJ-beat-PRV-PASS-MOOD} {ke\\by}{monna.\\man}] \translation{`The/*a boy was beaten by a/the man.'} \end{glossedexample} The other (another?) real bad hack in the glossedexample environment is the \raisebox business for the example number. LaTeX will otherwise put the example number *between* the lines of the stacked text, and it will look sort of like: Mosimane o-bed-its-w-e ke monna. (2) boy SUBJ-beat-PRV-PASS-MOOD by man `The/*a boy was beaten by a/the man.' Naturally, the actual TeX output is not quite this ugly, but after all, this was done on a terminal, with fixed line spacing. Happy TeXing. I hope to get back to improving this sometime soon, so I really would appreciate any suggestions. ==== Paul Neubauer 00prneubauer@bsu-ucs.uucp or 00PRNEUBAUER@BSUVAX1.BITNET neubauer@bsu-cs.uucp {backbones}!iuvax!bsu-cs!neubauer