%
% a first attempt at defining LaTeX macros for MRS typesetting
%
% Copyright (c) 2007 -- 2009 Stephan Oepen (oe@ifi.uio.no)
%

\iffalse

\sblock{\sh{0}}{%
  \sep{\svar{h}{1}{}}{\_sleep\_v}{%
    \srv{ARG0}{e}{0}{\svp{TENSE}{past}}, \srv{ARG1}{x}{0}{}},\\
  \slep{2}{proper\_q}{%
    \srv{ARG0}{x}{0}{}, \srv{RSTR}{h}{3}{}, \srv{BODY}{h}{4}{}},\\
  \slep{5}{named}{%
    \srv{ARG0}{x}{0}{}, \src{CARG}{Browne}}}%
  {\sqeq{0}{1}, \sqeq{3}{5}}

\fi


%
% two global switches, to control whether role labels and variable properties
% are included in the output or not.
%
\newif\ifroles\rolestrue
\newif\ifproperties\propertiestrue
\newif\iflnk\lnktrue

\newcommand{\rolenewline}{%
  \ifroles\\\fi}

%
% used to foreground select MRS elements, e.g. predicates or variables
%
\newif\iffocuscontext\focuscontextfalse
\newcommand{\sfocus}[1]{%
  \iffalse
    {\focuscontexttrue #1}%
  \else
    \fboxsep 0.8pt\psset{linewidth=1pt,boxsep=false}%
    \psovalbox{#1}%
  \fi}

%
% a variable, e.g. \svar{e}{2}{\svp{TENSE}{past}} or \svar{h}{0}{}
%
\newcommand{\svar}[3]{%
  {\fboxsep 0pt
   \def\testa{}\def\testb{\_}\def\testc{#1}\def\testd{#2}\def\teste{#3}%
   \ensuremath{%
     \mbox{\textsf{\textit{%
       \ifmetacontext\uppercase{#1}\else%
         \ifx\testb\testc\raisebox{-0.15ex}{\rule{1ex}{0.05ex}}%
         \else#1\fi\fi}}}%
     \ifx\testa\testd\else_{#2}\fi%
     \ifproperties\ifx\testa\teste\else\svps{#3}\fi\fi}}}

\newcommand{\svps}[1]{%
  \ensuremath{\lbrace\hspace{0.00ex}#1\hspace{0.00ex}\rbrace}}

%
% shorthands for frequent variable types (no variable properties), e.g. \sh{0}
%
\newcommand{\sh}[1]{%
  \svar{h}{#1}{}}
\newcommand{\se}[1]{%
  \svar{e}{#1}{}}
\newcommand{\sx}[1]{%
  \svar{x}{#1}{}}

%
% used in the presentation of transfer rules, flagging meta-variables
%
\newif\ifmetacontext\metacontextfalse
\newcommand{\stag}[1]{%
  \iffalse
    {\metacontexttrue #1}%
  \else
    {\fboxsep 1pt
     \raisebox{0.1ex}{\fbox{#1}}}%
  \fi}
  

%
% also mostly in transfer rules, a `wildcard' value
%
\newcommand{\srule}{%
  \raisebox{-0.15ex}{\rule{1.5ex}{0.05ex}}}

%
% a property label, e.g. \spl{TENSE}
%
\newcommand{\spl}[1]{%
  \mbox{\smaller\sffamily #1}}

%
% a property value, e.g. \spv{past}
%
\newcommand{\spv}[1]{%
  \mbox{\smaller\sffamily\textit{#1}}}


%
% a variable property, e.g. \svp{TENSE}{past}
%
\newcommand{\svp}[2]{%
  \mbox{\spl{#1}~\spv{#2}}}

%
% a constant (or parameter), e.g. \sconst{Browne} (note, sans double quotes)
%
\newcommand{\sconst}[1]{%
  \mbox{\textsf{\textit{#1}}}}

%
% a role label, e.g. \srl{ARG0}
%
\newcommand{\srl}[1]{%
  \mbox{\textsf{\smaller #1}}}

%
% a role (i.e. role -- value) pair in an EP, e.g. \srole{ARG0}{\svar{e}{2}}
%
\newcommand{\srole}[2]{%
  \mbox{\textsf{\ifroles\srl{#1}~\fi#2}}}

%
% as a matter of convenience, these are shorthand macros for role -- variable
% and role -- constant pairs, essentially wrapping \srole{} et al.
%
\newcommand{\srv}[4]{%
  \srole{#1}{\svar{#2}{#3}{#4}}}
\newcommand{\src}[2]{%
  \srole{#1}{\sconst{#2}}}


%
% a predicate symbol, e.g. \spred{\_sleep\_v}
%
\newcommand{\spred}[1]{%
  \mbox{\textsf{#1}}}

%
% various forms of surface LNKs, anchoring a predicate in the parser input
%
\newcommand{\slnkc}[2]{%
  \iflnk%
    {\def\testa{}\def\testb{#1}\def\testc{#2}%
     \ensuremath{%
      \left\langle%
      \ifx\testa\testb\else#1\fi\!:\!\ifx\testa\testc\else#2\fi
      \right\rangle}}\fi}

%
% one elementary predication, see above for examples
%
\newcommand{\sep}[3]{%
  {\def\testa{}\def\testb{#1}\def\testc{#3}%
   \textsf{\ifx\testa\testb\else#1:\fi\spred{#2}%
     \ifx\testa\testc\else\hspace{0.05ex}(\hspace{0.05ex}%
       \begin{tabular}[t]{@{}l@{}}#3\hspace{0.05ex})\end{tabular}\fi}}}

%
% another shorthand: a _labeled_ elementary predication
%
\newcommand{\slep}[3]{%
  \sep{\svar{h}{#1}{}}{#2}{#3}}

%
% a QEQ handle constraint, e.g. \sqeq{0}{1}
%
\newcommand{\sqeq}[2]{%
  {\def\testa{}\def\testb{#1}\def\testc{#2}%
   \ensuremath{%
    \ifx\testa\testb\else\sh{#1}\fi=_q\ifx\testa\testc\else\sh{#2}\fi}}}

%
% a `raw' QEQ handle constraint, for use in transfer rules
%
\newcommand{\srqeq}[2]{%
  \ensuremath{#1=_q#2}}

%
% a bag of EPs, sometimes used to abbreviate the gist of an MRS
%
\newcommand{\seps}[1]{%
  $\lbrace\,$#1$\,\rbrace$}

%
% a bag of handle constraints, e.g. \shcons{\sqeq{47}{11}}
%
\newcommand{\shcons}[1]{%
  {\def\testa{}\def\testb{#1}%
   $\lbrace\,$#1$\ifx\testa\testb\else\,\fi\rbrace$}}

%
% one MRS, typeset in paragraph mode (just like regular text)
%
\newcommand{\stext}[3]{%
  $\langle\,$#1, \seps{#2}, \shcons{#3}$\,\rangle$}

%
% one MRS, typeset in boxed mode; use `\\' to force line breaks among EPs
%
\newcommand{\sblock}[3]{%
  \fboxsep 0pt
  \ensuremath{%
    \vcenter{%
      \def\testa{}\def\testb{#1}%
      \hbox{\vbox{%
        \hbox{$\langle\,$#1\ifx\testa\testb\else,\fi}%
        \hbox{\phantom{$\langle\,$}%
          \hskip -0.0ex%
          \ensuremath{%
            \begin{array}{@{}|l|@{}}%
              #2\\
            \end{array}}}%
        \hbox{\phantom{$\langle\,$}\hskip -0.1ex\shcons{#3}$\,\rangle$}}}}}}

\newcommand{\eds}[2]{%
  \fboxsep 0pt
  \ensuremath{%
    \vcenter{%
      \hbox{\vbox{%
        \hbox{$\lbrace\,$#1}%
        \hbox{\phantom{$\lbrace\,$}%
          \hskip -0.0ex%
          \ensuremath{%
            \begin{array}{@{}l@{}}%
              #2\\
            \end{array}}}%
        \hbox{$\rbrace$}}}}}}

