| 1 |
%%% |
| 2 |
%%% Macros to typeset Discourse Representation Structures (DRSs). |
| 3 |
%%% Based on DRS macros in covingtn.sty |
| 4 |
%%% |
| 5 |
%%% Written by Alexis Dimitriadis (a.dimitriadis at uu.nl) |
| 6 |
%%% |
| 7 |
%%% This package may be used, distributed and modified unter the terms of the |
| 8 |
%%% LaTeX Project Public License, either version 1.3 of this license or (at your |
| 9 |
%%% option) any later version. |
| 10 |
%%% |
| 11 |
%%% The latest version of the LaTeX Project Public License can be found at this URL: |
| 12 |
%%% http://www.latex-project.org/lppl.txt |
| 13 |
|
| 14 |
\ProvidesPackage {drs} |
| 15 |
[2010/06/10 typeset Discourse Representation Structures v. 1.1b] |
| 16 |
|
| 17 |
|
| 18 |
% REVISION HISTORY |
| 19 |
% |
| 20 |
% 2010/06/10 v. 1.1 Small modifications for compatibility with memoir and array.sty. |
| 21 |
% Thanks to Alan Munn and Antonio Fortin for reporting the problem. |
| 22 |
% Added robustness enhancements, pict2e support, and LPPL license. |
| 23 |
% |
| 24 |
% 2004/02/17 Corrected some typos in documentation |
| 25 |
% |
| 26 |
% 2000/06/15 v. 1.0 Original stable version |
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
%% This package draws Discourse Representation Structures (DRSs). It can draw |
| 31 |
%% embedded DRSs, if-then conditions and quantificational ``duplex |
| 32 |
%% conditions'' (with a properly scaled connecting diamond). Formatting |
| 33 |
%% parameters allow the user to control the appearance and placement of DRSs, |
| 34 |
%% and of DRS variables and conditions. |
| 35 |
|
| 36 |
% \drs typesets a DRS in box notation a la Kamp. |
| 37 |
% \drs* Same, but typeset as a ``partial'' drs (centered on the |
| 38 |
% baseline, and with no extra spacing above or below) |
| 39 |
% |
| 40 |
% Arguments: |
| 41 |
% 1. List of discourse variables |
| 42 |
% 2. List of conditions separated by \\ |
| 43 |
% |
| 44 |
% Example: \drs{X}{donkey(X)\\green(X)} |
| 45 |
% |
| 46 |
% Example: \drs{}{purple(X,Y)} (no variables line) |
| 47 |
% |
| 48 |
% Example: \drs{X} |
| 49 |
% {named(X,`Pedro') \\ |
| 50 |
% \drs{Y}{donkey(Y)\\owns(X,Y)}~~ |
| 51 |
% {\large $\Rightarrow$}~ |
| 52 |
% \drs{~}{feeds(X,Y)} |
| 53 |
% } |
| 54 |
|
| 55 |
% \ifdrs forms 2 DRSes joined with a big arrow. |
| 56 |
% Usually used for DRSes nested within another. |
| 57 |
% |
| 58 |
% Example: \ifdrs{X}{donkey(X)\\hungry(X)} |
| 59 |
% {~}{feeds(Pedro,X)} |
| 60 |
|
| 61 |
% \qdrs Form a ``duplex condition'' representing a quantifier. |
| 62 |
% |
| 63 |
% Example: \qdrs{}{man(x)}{every}{x}{y}{mother-of(x, y)\\ |
| 64 |
% loves(x, y)} |
| 65 |
|
| 66 |
% \negdrs forms a DRS preceded by the negation symbol. |
| 67 |
% |
| 68 |
% Example: \negdrs{X}{donkey(X)\\green(X)} |
| 69 |
|
| 70 |
% \sdrs like \drs but first argument is a sentence |
| 71 |
% to be displayed above the drs. |
| 72 |
% |
| 73 |
% Example: \sdrs{A donkey is green.}{X}{donkey(X)\\green(X)} |
| 74 |
|
| 75 |
% \alifdrs is like \ifdrs but shifted to the left so that an |
| 76 |
% embedded `if' structure will line up with ordinary |
| 77 |
% DRS conditions. |
| 78 |
|
| 79 |
% memoir-compatible definitions; if you use article.cls, \it and \rm also work |
| 80 |
\def\drsvarfont{\normalfont\itshape} % Font for variables |
| 81 |
\def\drscondfont{\normalfont\rmfamily} % Font for conditions |
| 82 |
|
| 83 |
\let\drsseparator=\hline % Separator between variables and conditions |
| 84 |
|
| 85 |
\let\drsalignment=c % Alignment of material in boxes (l/c/r) |
| 86 |
|
| 87 |
\let\drsboxalignh=c % Horizontal alignment of top-level DRS box in page |
| 88 |
\let\drsboxalignv=c % Vertical alignment (with the baseline: t/c/b) |
| 89 |
|
| 90 |
% \def\drsarraystretch{1} % undefined by default: value for \arraystretch |
| 91 |
|
| 92 |
\edef\drslinewidth{\the\arrayrulewidth} % Line thickness: Start with default for tabular |
| 93 |
|
| 94 |
\newcount\@drslevel \@drslevel=0 |
| 95 |
|
| 96 |
\def\drs@strut{{\large\strut}} |
| 97 |
|
| 98 |
|
| 99 |
% \drs* gives a ``partial DRS'' (treated as if it appears inside another DRS) |
| 100 |
% \drs begins a group that's ended by \@drs |
| 101 |
\newcommand{\drs}{\bgroup |
| 102 |
\@drs@set@align |
| 103 |
\@ifstar{\advance\@drslevel by 1 \relax} \relax |
| 104 |
\expandafter\@drs\@drs@cleanalign } |
| 105 |
|
| 106 |
% These contortions are required because memoir and array will not accept a macro |
| 107 |
% as a column alignment specifier. Simpler solutions would be possible if we KNEW whether |
| 108 |
% \drsalignment has been set with \def/renewcommand or with \let. Restricting the user is |
| 109 |
% ugly, so we \def a macro from what we're given. |
| 110 |
% |
| 111 |
\def\@drs@set@align{% |
| 112 |
\def\@drs@cleanalign{c}% a default, in case of bad values |
| 113 |
% \expandafter is needed in case \drsalignment was \def'ed; with \let, it's harmless |
| 114 |
\expandafter\ifx \drsalignment c\def\@drs@cleanalign{c}\fi |
| 115 |
\expandafter\ifx \drsalignment l\def\@drs@cleanalign{l}\fi |
| 116 |
\expandafter\ifx \drsalignment r\def\@drs@cleanalign{r}\fi } |
| 117 |
|
| 118 |
\newcommand{\@drs}[3] |
| 119 |
{\advance\@drslevel by 1 \relax |
| 120 |
\leavevmode |
| 121 |
\ifnum\@drslevel>1 |
| 122 |
\let\drsboxalignv=c% Embedded boxes should be centered on the baseline |
| 123 |
\else % Alignment options for top-level boxes only: |
| 124 |
\expandafter\ifx \drsboxalignh c\hbox{}\hfil \fi \fi |
| 125 |
% \expandafter is needed if \drsboxalignh was \def'ed; with \let, it's harmless |
| 126 |
\arrayrulewidth=\drslinewidth |
| 127 |
\@ifundefined{drsarraystretch} {} {\edef\arraystretch{\drsarraystretch}}% |
| 128 |
\begin{tabular}[\drsboxalignv]{|@{}r@{}|} |
| 129 |
\ifnum\@drslevel>1\noalign{\vskip 0.7ex}\fi %% ?? |
| 130 |
\hline |
| 131 |
\drscondfont |
| 132 |
{\begin{tabular}[b]{#1} |
| 133 |
% Do not allocate space for variables if none are given |
| 134 |
\def\@tempa{#2}\ifx\@tempa\empty \else |
| 135 |
\drs@strut |
| 136 |
\drsvarfont {\ignorespaces #2\strut\relax }\\ |
| 137 |
\drsseparator % Spacing is the same whether this is \hline or \relax |
| 138 |
\fi |
| 139 |
\drs@strut % extra space above and below (text) condition |
| 140 |
\strut % A failsafe, in case the user selected a large font |
| 141 |
\ignorespaces #3 % do not place \relax here! It confuses the next test |
| 142 |
% End line unless the user already did |
| 143 |
\ifvmode \else \\ \fi |
| 144 |
% (can't vspace here or the line will come out wrong) |
| 145 |
\end{tabular}}% |
| 146 |
\vrule height 0pt width 0pt depth \baselinestretch\dp\strutbox |
| 147 |
\drs@strut % extra space above and below (text) conditions |
| 148 |
\\[2pt] \hline |
| 149 |
\ifnum\@drslevel>1\noalign{\vskip 0.7ex}\fi % extra for embedded DRSs |
| 150 |
\end{tabular}\egroup} % close the \bgroup in \drs |
| 151 |
|
| 152 |
|
| 153 |
% Connect two DRSs with the middle argument (presumably a logical connective). |
| 154 |
% This is worth providing because centering would separate DRSs from the |
| 155 |
% connectives, unless everything is enclosed in an mbox as we do here. |
| 156 |
\newcommand\condrs[5] |
| 157 |
{\mbox{\let\drsboxalignv=c\drs{#1}{#2}{\large\ \ {#3}\ \ }\drs{#4}{#5}}} |
| 158 |
|
| 159 |
\newcommand{\ifdrs}[4]{\condrs{#1}{#2}{$\Rightarrow\!\,$}{#3}{#4}} |
| 160 |
|
| 161 |
\newcommand{\qdrs}[6] |
| 162 |
{\mbox{\let\drsboxalignv=c\drs{#1}{#2}\drsdiamond{#3}{#4}\drs{#5}{#6}}} |
| 163 |
|
| 164 |
\newcommand{\negdrs}[2] |
| 165 |
{\mbox{{\large $\neg$ }\drs{#1}{#2}~}} % offset by a ~ for better centering |
| 166 |
|
| 167 |
% like \ifdrs but shifted to the left so that an embedded `if' structure will |
| 168 |
% line up with ordinary DRS conditions. (Useful for left-aligned DRSs only). |
| 169 |
\newcommand{\alifdrs}[4] |
| 170 |
{\mbox{$\!\!\!$\ifdrs{#1}{#2}{#3}{#4}}} |
| 171 |
|
| 172 |
% A DRS with the associated sentence. |
| 173 |
\newcommand{\sdrs}[3] |
| 174 |
{\begin{tabular}{l} |
| 175 |
\mbox{\it #1} \\ |
| 176 |
~ \\ |
| 177 |
\drs{#2}{#3} |
| 178 |
\end{tabular}} |
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
\newbox\@drsbox |
| 183 |
|
| 184 |
% Draw a diagonal square (diamond) containing a quantifier and variable. |
| 185 |
% |
| 186 |
% Ridiculously complicated diamond algorithm: fit the smallest diamond around |
| 187 |
% the _trapezoid_ enclosing a longer top line and a short variable at the |
| 188 |
% bottom. Special-case boxes with really, really wide top part. |
| 189 |
% |
| 190 |
% Syntax: \drsdiamond{quantifier}{variable} |
| 191 |
\newcommand{\drsdiamond}[2]{{% |
| 192 |
\setbox\@drsbox\hbox{\def\baselinestretch{1}\@currsize |
| 193 |
\begin{tabular}{@{}c@{}} |
| 194 |
\drscondfont {#1}\\\drsvarfont {~#2~\null}\end{tabular}}% |
| 195 |
% Compute the necessary dimensions |
| 196 |
\@tempcnta=\ht\@drsbox \relax |
| 197 |
\advance\@tempcnta by \dp\@drsbox \relax |
| 198 |
\edef\@H{\the\@tempcnta}% % height |
| 199 |
% |
| 200 |
\@tempcnta=\wd\@drsbox |
| 201 |
\edef\@boxdims{(\the\@tempcnta,\@H)}% % box dimensions |
| 202 |
\divide\@tempcnta by 2 |
| 203 |
\edef\@A{\the\@tempcnta}% % 1/2 top width |
| 204 |
% |
| 205 |
% Measure the bottom line separately so we can pretend we're a trapezoid |
| 206 |
\setbox\@tempboxa\hbox{ \drsvarfont{#2 }}% |
| 207 |
\@tempcnta=\wd\@tempboxa |
| 208 |
\divide\@tempcnta by 2 |
| 209 |
\edef\@B{\the\@tempcnta}% % 1/2 bottom row width |
| 210 |
% |
| 211 |
\@tempcnta=\@H |
| 212 |
\advance\@tempcnta by \@B |
| 213 |
\ifnum \@A > \@tempcnta % Angle is less than 45 degrees: center on top part |
| 214 |
% start over: measure just the top part |
| 215 |
\setbox\@tempboxa\hbox{\def\baselinestretch{1}\@currsize |
| 216 |
\begin{tabular}{@{}c@{}}\drscondfont{#1}\end{tabular}}% |
| 217 |
\@tempcnta=\ht\@tempboxa |
| 218 |
\advance\@tempcnta by \dp\@tempboxa |
| 219 |
\divide\@tempcnta by 2 |
| 220 |
\edef\@topH{\the\@tempcnta}% % HALF the height of the top part |
| 221 |
\advance\@tempcnta by \@A |
| 222 |
\edef\@D{\the\@tempcnta}% |
| 223 |
\advance\@tempcnta by -\@H |
| 224 |
\advance\@tempcnta by \@topH |
| 225 |
\edef\@boxcoords{(\@topH,\the\@tempcnta)}% |
| 226 |
\else % Angle over 45: diamond goes across all corners |
| 227 |
\advance \@tempcnta by \@A\relax \divide \@tempcnta by 2 |
| 228 |
\edef\@D{\the\@tempcnta}% |
| 229 |
\advance\@tempcnta by -\@A |
| 230 |
\edef\@boxcoords{(\the\@tempcnta,\@B)}% |
| 231 |
\fi |
| 232 |
% |
| 233 |
\@tempcnta=\@D |
| 234 |
\multiply\@tempcnta by 2 |
| 235 |
\edef\@twoD{\the\@tempcnta}% |
| 236 |
% |
| 237 |
\unitlength=1sp % ``scaled points,'' like the counter values |
| 238 |
\linethickness{\drslinewidth}% only effective if pict2e.sty is loaded |
| 239 |
% If eepic is loaded, match our lines to the DRS borders |
| 240 |
\@ifundefined{allinethickness}\relax{\allinethickness{\the\arrayrulewidth}}% |
| 241 |
\parbox[c]{\@twoD sp}{{\vskip 2pt% |
| 242 |
\begin{picture}(\@twoD,\@twoD) |
| 243 |
\put(0,\@D){\line(1,-1)\@D} |
| 244 |
\put(0,\@D){\line(1,1)\@D} |
| 245 |
\put(\@twoD,\@D){\line(-1,1)\@D} |
| 246 |
\put(\@twoD,\@D){\line(-1,-1)\@D} |
| 247 |
% change \makebox to \framebox to see the placement |
| 248 |
\expandafter\put\@boxcoords{\expandafter\makebox\@boxdims{\box\@drsbox}} |
| 249 |
\end{picture}\vskip 2pt}}}} |
| 250 |
|
| 251 |
|
| 252 |
% BETTER DOUBLE SPACING: by default, tall material can come arbitrarily close |
| 253 |
% to the previous line. Calling \drshacksetspace redefines setspace.sty |
| 254 |
% internals, causing it to adjust TeX formatting parameters that force a |
| 255 |
% portion of each line to stay empty. This really should be part of |
| 256 |
% setspace.sty. |
| 257 |
|
| 258 |
% setspace.sty redefines the footnotes, but they do not call setstretch, alas. |
| 259 |
% So the spacing will still be incorrect in footnotes. |
| 260 |
|
| 261 |
\def\drshacksetspace{\@ifundefined{setstretch}\relax {% |
| 262 |
% Ensure that HALF of the lineskip above the normal (singlespacing) value |
| 263 |
% will stay empty |
| 264 |
\def\adj@lineskip{% |
| 265 |
\@tempdima=\baselinestretch\baselineskip |
| 266 |
\advance\@tempdima by -\setspace@singlespace\baselineskip |
| 267 |
\divide\@tempdima by 2 |
| 268 |
\lineskiplimit=\@tempdima |
| 269 |
\lineskip=\lineskiplimit |
| 270 |
\ifdim\@tempdima=0pt \lineskip=1pt\fi}% |
| 271 |
% Arrange to recompute lineskip whenever spacing changes |
| 272 |
\renewcommand{\setstretch}[1] |
| 273 |
{\def\baselinestretch{##1}\@currsize\adj@lineskip}% |
| 274 |
% Now run setstretch in case it's already been invoked (at the preamble) |
| 275 |
\expandafter\expandafter |
| 276 |
\expandafter\setstretch\expandafter{\baselinestretch}}} |
| 277 |
|
| 278 |
\endinput |