%This is a small package with additions to Wolfgang Sternefeld's linguex package (adapted to version 4.3). It provides extended functions for cross-referencing and repeating numbered and named sentences, additional formatting options and hyperref support.
%Author: Peter Pagin (with a contribution by Robin Fairbairns).
%email: peter.pagin@philosophy.su.se
%Date: 2014.08.20
%Version: 1.3
%License type: lppl


\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{philex}


\RequirePackage{xspace,calc,cgloss4e,linguex,ifthen,suffix}
\newif\ifhyperref 
\hyperreffalse

\newif\ifoldpunct
\oldpunctfalse

\newif\ifphildraft
\phildraftfalse

\DeclareOption{oldpunct}{\oldpuncttrue}
\DeclareOption{hyper}{\hyperreftrue}
\DeclareOption{draft}{\phildrafttrue}
\ProcessOptions

\newcounter{altsub}
\newcounter{altsubsub}
\renewcommand{\thealtsub}{\subettan{altsub}}
\renewcommand{\Exroman}{\roman}
\AtBeginDocument{\settowidth{\Exlabelwidth}{(110)}}
\newlength{\seba}
\newlength{\sebatemp}
\newlength{\bpasize}
\newlength{\bpbsize}
\newlength{\bpcsize}
\newlength{\bpdsize}


\ifphildraft
\setlength{\marginparwidth}{7em}
\setlength{\marginparpush}{4pt}
\newcommand{\philmarginfactor}{1.2}
\else \fi

%Spacing and formatting commands
\setlength{\Exredux}{-\baselineskip}
\renewcommand{\philarge}{3em}
\renewcommand{\philmiddle}{2em}
\renewcommand{\philsmall}{1em}
\renewcommand{\phlabelwidth}[1]{\renewcommand{\philarge}{#1}
\renewcommand{\philmiddle}{#1}
\renewcommand{\philsmall}{#1}}
\renewcommand{\phlabeldefault}{\renewcommand{\philarge}{3em}
\renewcommand{\philmiddle}{2em}
\renewcommand{\philsmall}{1em}}
\newcommand{\phlabelsep}[1]{\setlength{\Exlabelsep}{#1}}
\newcommand{\phlabelsepdefault}{\setlength{\Exlabelsep}{1.3em}}
\newcommand{\firstphildash}{}
\newcommand{\secondphildash}{}
\newcommand{\phildashes}[2]{\renewcommand{\firstphildash}{#1}\renewcommand{\secondphildash}{#2}}
\newcommand{\subettan}{\alph}


%Controlling brackets,lowercase and full stop.
\newcommand{\philpunct}{}
\newcommand{\philempty}{\renewcommand{\philpunct}{}}
\newcommand{\philfullstop}{\renewcommand{\philpunct}{.}}
\newcommand{\philcomma}{\renewcommand{\philpunct}{,}}
\newcommand{\philexclaim}{\renewcommand{\philpunct}{!}}
\newcommand{\philquestion}{\renewcommand{\philpunct}{?}}
\newcommand{\philsubpunct}{}
\newcommand{\philsubempty}{\renewcommand{\philsubpunct}{}}
\newcommand{\philsubstop}{\renewcommand{\philsubpunct}{.}}
\newcommand{\philsubcomma}{\renewcommand{\philsubpunct}{,}}
\newcommand{\philsubexclaim}{\renewcommand{\philsubpunct}{!}}
\newcommand{\philsubquestion}{\renewcommand{\philsubpunct}{?}}
\ifoldpunct%
\newcommand{\p}{\philpunct}%
\newcommand{\q}{\philempty}%
\newcommand{\s}{\philfullstop}%
\newcommand{\km}{\philcomma}%
\newcommand{\pt}{\philsubpunct}%
\newcommand{\qt}{\philsubempty}%
\newcommand{\stp}{\philsubstop}%
\newcommand{\kmt}{\philsubcomma}\fi
\newcommand{\lebrack}{(}
\newcommand{\ribrack}{)}
\def\broff{\def\lebrack{}\def\ribrack{}}
\def\bron{\def\lebrack{(}\def\ribrack{)}}
\newcommand{\philbrackets}[2]{\renewcommand{\lebrack}{#1}\renewcommand{\ribrack}{#2}}
\newcounter{bpa}
\newcounter{bpb}
\newcounter{bpc}
\newcounter{bpd}
\newcounter{bna}
\newcommand{\bn}{\refstepcounter{bna}\thebna.\quad}
\newcommand{\bns}{\setcounter{bna}{0}}

%Removing brackets from ExNo and SubExNo
\renewcommand{\theExNo}{\arabic{ExNo}}
\renewcommand{\theSubExNo}{\theExNo\firstphildash\alph{SubExNo}}
\renewcommand{\theSubSubExNo}{\theSubExNo\roman{SubSubExNo}}
\newcommand{\ncentro}{\columnwidth-(\Exindent+\Exlabelsep+\Exlabelwidth)}
\newcommand{\wcentro}{\columnwidth-(\Exindent*2+\Exlabelsep*2+\Exlabelwidth*2)}
\newcommand{\centro}{\wcentro}
\newcommand{\narrowcenter}{\renewcommand{\centro}{\ncentro}}
\newcommand{\widecenter}{\renewcommand{\centro}{\wcentro}}

%Top-level numbered sentence:
\newcommand{\lb}[3][n]{
\ifdim\lastskip=\Extopsep\vspace{\Exredux}
\ifphildraft
\label{#2knut}
    \vskip 0pt \penalty -400
\label{#2ulla}
\ifthenelse{\pageref{#2knut}=\pageref{#2ulla}}{\marginpar{\hspace{-\philmarginfactor\textwidth}{\raisebox{-1\baselineskip}{\bf #2}}}}{\marginpar{\hspace{-\philmarginfactor\textwidth}{\bf #2}}\vspace{-1\baselineskip}}\fi
\else
\ifphildraft
\label{#2knut}
    \vskip 0pt \penalty -400
\label{#2ulla}
\ifthenelse{\pageref{#2knut}=\pageref{#2ulla}}{\marginpar{\hspace{-\philmarginfactor\textwidth}{\raisebox{-1.6\baselineskip}{\bf #2}}}}{\marginpar{\hspace{-\philmarginfactor\textwidth}{\bf #2}}\vspace{-1.6\baselineskip}}\fi
\fi
\phlabelsepdefault
\phlabeldefault
\immediate\write\@auxout{\unexpanded{\expandafter\gdef\csname#2r\endcsname{#3}\expandafter\gdef\csname#2\endcsname{\ref{#2}}
\expandafter\gdef\csname#2p\endcsname{\MakeLowercase#3}}}
\expandafter\providecommand\expandafter{\csname#2r\endcsname}{#3}
\expandafter\providecommand\expandafter{\csname#2\endcsname}{\ref{#2}}\expandafter\providecommand\expandafter{\csname#2p\endcsname}{\MakeLowercase#3}
\ifhyperref%
\renewcommand{\theFnExNo}{\roman{FnExNo}}
\ex. \label{#2} \if#1c \setlength{\abovedisplayskip}{1ex}
\setlength{\belowdisplayskip}{2ex}%
\parbox{\centro}{\centering \hypertarget{#2}{#3}\philpunct}\else \hypertarget{#2}{#3}\philpunct\fi\par
\else 
\ex. \label{#2} \if#1c \setlength{\abovedisplayskip}{1ex}\setlength{\belowdisplayskip}{2ex}%
\parbox{\centro}{\centering #3\philpunct}\else #3\philpunct\fi\par%
\fi}             




%Top-level named sentence:
\newcommand{\lbp}[4][n]{
\ifdim\lastskip=\Extopsep\vspace{\Exredux}
\ifphildraft
\label{#2knut}
    \vskip\z@ \penalty -400
\label{#2ulla}
\ifthenelse{\pageref{#2knut}=\pageref{#2ulla}}{\marginpar{\hspace{-\philmarginfactor\textwidth}{\raisebox{-1\baselineskip}{\bf #2}}}}{\marginpar{\hspace{-\philmarginfactor\textwidth}{\bf #2}}\vspace{-1\baselineskip}}\fi
\else
\ifphildraft
\label{#2knut}
    \vskip\z@ \penalty -400
\label{#2ulla}
\ifthenelse{\pageref{#2knut}=\pageref{#2ulla}}{\marginpar{\hspace{-\philmarginfactor\textwidth}{\raisebox{-1.6\baselineskip}{\bf #2}}}}{\marginpar{\hspace{-\philmarginfactor\textwidth}{\bf #2}}\vspace{-1.6\baselineskip}}\fi
\fi
\label{#2}
\settowidth{\sebatemp}{#3}
\settowidth{\seba}{\rsep{#2}}
\ifdim \sebatemp>\seba 
\expandafter\gdef\csname #2sep\endcsname{#3}%
\settowidth{\seba}{\rsep{#2}}%
\immediate\write\@auxout{\unexpanded{\expandafter\gdef\csname#2sep\endcsname{#3}}}
\else 
\fi 
\phlabelwidth{10cm}
\ifdim \seba>2.5em \setlength{\Exlabelsep}{\seba-0.5em}%
\else \phlabelsepdefault \fi
\immediate\write\@auxout{\unexpanded{\expandafter\gdef\csname#2p\endcsname{\MakeLowercase#4}\expandafter\gdef\csname#2\endcsname{#3}  \expandafter\gdef\csname#2r\endcsname{#4}}}
\expandafter\providecommand\expandafter{\csname#2p\endcsname}{\MakeLowercase#4}
\expandafter\providecommand\expandafter{\csname #2\endcsname}{#3}  
\expandafter\providecommand\expandafter{\csname#2r\endcsname}{#4}
\ifhyperref 
\ex.[\hypertarget{#2}{\lebrack#3\ribrack}\hspace{-1em}]
\renewcommand{\theExNo}{\csname#2\endcsname}
\renewcommand{\theFnExNo}{\csname#2\endcsname}
\if#1c \setlength{\abovedisplayskip}{1ex}\setlength{\belowdisplayskip}{2ex}\parbox{\centro}{\centering #4\philpunct} \else #4\philpunct\fi\par
\else%
\ex.[\lebrack#3\ribrack\hspace{-1em}]
\renewcommand{\theExNo}{\csname#2\endcsname} 
\if#1c \setlength{\abovedisplayskip}{1ex}\setlength{\belowdisplayskip}{2ex}\parbox{\centro}{\centering #4\philpunct} \else #4\philpunct\fi\par
\fi
}

\WithSuffix\newcommand\lbp*{\lbpStar}
\newcommand{\lbpStar}[4][n]{
\ifdim\lastskip=\Extopsep\vspace{\Exredux}
\ifphildraft
\label{#2knut}
    \vskip 0pt \penalty -400
\label{#2ulla}
\ifthenelse{\pageref{#2knut}=\pageref{#2ulla}}{\marginpar{\hspace{-\philmarginfactor\textwidth}{\raisebox{-1\baselineskip}{\bf #2}}}}{\marginpar{\hspace{-\philmarginfactor\textwidth}{\bf #2}}\vspace{-1\baselineskip}}\fi
\else
\ifphildraft
\label{#2knut}
    \vskip 0pt \penalty -100
\label{#2ulla}
\ifthenelse{\pageref{#2knut}=\pageref{#2ulla}}{\marginpar{\hspace{-\philmarginfactor\textwidth}{\raisebox{-1.6\baselineskip}{\bf #2}}}}{\marginpar{\hspace{-\philmarginfactor\textwidth}{\bf #2}}\vspace{-1.6\baselineskip}}\fi
\fi
\label{#2}
\phlabelsepdefault
\settowidth{\sebatemp}{#3} 
\phlabelwidth{10cm}
\immediate\write\@auxout{\unexpanded{\expandafter\gdef\csname#2p\endcsname{\MakeLowercase#4}\expandafter\gdef\csname#2\endcsname{#3}  \expandafter\gdef\csname#2r\endcsname{#4}}}
\expandafter\providecommand\expandafter{\csname#2p\endcsname}{\MakeLowercase#4}
\expandafter\providecommand\expandafter{\csname #2\endcsname}{#3}  
\expandafter\providecommand\expandafter{\csname#2r\endcsname}{#4}
\ifhyperref 
\ex.[\hypertarget{#2}{\lebrack#3\ribrack}\hspace{-1em}]
\renewcommand{\theExNo}{\csname#2\endcsname}
\renewcommand{\theFnExNo}{\csname#2\endcsname}
\if#1c \setlength{\abovedisplayskip}{1ex}\setlength{\belowdisplayskip}{2ex}\parbox{\centro}{\centering #4\philpunct} \else \hspace{\sebatemp} \hspace{-2em} #4\philpunct\fi\par
\else%
\ex.[\lebrack#3\ribrack\hspace{-1em}]
\renewcommand{\theExNo}{\csname#2\endcsname} 
\if#1c \setlength{\abovedisplayskip}{1ex}\setlength{\belowdisplayskip}{2ex}\parbox{\centro}{\centering #4\philpunct} \else \hspace{\sebatemp} \hspace{-2em}
#4\philpunct\fi\par
\fi
}

%Top-level named sentence, alternative:
\newcommand{\lbpsep}[5][n]{
\ifdim\lastskip=\Extopsep\vspace{\Exredux}
\ifphildraft
\label{#2knut}
    \vskip 0pt \penalty -400
\label{#2ulla}
\ifthenelse{\pageref{#2knut}=\pageref{#2ulla}}{\marginpar{\hspace{-\philmarginfactor\textwidth}{\raisebox{-1.6\baselineskip}{\bf #2}}}}{\marginpar{\hspace{-\philmarginfactor\textwidth}{\bf #2}}\vspace{-1\baselineskip}}\fi
\else
\ifphildraft
\label{#2knut}
    \vskip 0pt \penalty -100
\label{#2ulla}
\ifthenelse{\pageref{#2knut}=\pageref{#2ulla}}{\marginpar{\hspace{-\philmarginfactor\textwidth}{\raisebox{-1.6\baselineskip}{\bf #2}}}}{\marginpar{\hspace{-\philmarginfactor\textwidth}{\bf #2}}\vspace{-1.6\baselineskip}}\fi
\fi
\label{#2}
\phlabelwidth{10cm}
\settowidth{\seba}{\rsep{#3}}
\settowidth{\sebatemp}{#4}
\ifdim \seba>\sebatemp
\relax
\else
\expandafter\gdef\csname #3sep\endcsname{#4}%
\settowidth{\seba}{\rsep{#3}}%
\immediate\write\@auxout{\unexpanded{\expandafter\gdef\csname#3sep\endcsname{#4}}}
\fi
\ifdim \seba>2.5em \setlength{\Exlabelsep}{\seba-0.5em}%
\else \phlabelsepdefault\fi
\immediate\write\@auxout{\unexpanded{\expandafter\gdef\csname#2p\endcsname{\MakeLowercase#5}\expandafter\gdef\csname#2\endcsname{#4}  \expandafter\gdef\csname#2r\endcsname{#5}}}
\expandafter\providecommand\expandafter{\csname#2p\endcsname}{\MakeLowercase#5}
\expandafter\providecommand\expandafter{\csname #2\endcsname}{#4}  
\expandafter\providecommand\expandafter{\csname#2r\endcsname}{#5}
\ifhyperref 
\ex.[\hypertarget{#2}{\lebrack#4\ribrack}\hspace{-1em}]
\renewcommand{\theExNo}{\csname#2\endcsname}
\renewcommand{\theFnExNo}{\csname#2\endcsname}
\if#1c \setlength{\abovedisplayskip}{1ex}\setlength{\belowdisplayskip}{2ex}\parbox{\centro}{\centering #5\philpunct} \else #5\philpunct\fi\par
\else%
\ex.[\lebrack#4\ribrack\hspace{-1em}]
\renewcommand{\theExNo}{\csname#2\endcsname} 
\if#1c \setlength{\abovedisplayskip}{1ex}\setlength{\belowdisplayskip}{2ex}\parbox{\centro}{\centering #5\philpunct} \else #5\philpunct\fi\par
\fi
}



%Stand-alone top-level initial sentence, sequence a:
\newcommand{\lbpa}[3][n]{
\ifdim\lastskip=\Extopsep\vspace{\Exredux}
\ifphildraft
\label{#2knut}
    \vskip 0pt \penalty -400
\label{#2ulla}
\ifthenelse{\pageref{#2knut}=\pageref{#2ulla}}{\marginpar{\hspace{-\philmarginfactor\textwidth}{\raisebox{-1\baselineskip}{\bf #2}}}}{\marginpar{\hspace{-\philmarginfactor\textwidth}{\bf #2}}\vspace{-1\baselineskip}}\fi
\else
\ifphildraft
\label{#2knut}
    \vskip 0pt \penalty -400
\label{#2ulla}
\ifthenelse{\pageref{#2knut}=\pageref{#2ulla}}{\marginpar{\hspace{-\philmarginfactor\textwidth}{\raisebox{-1.6\baselineskip}{\bf #2}}}}{\marginpar{\hspace{-\philmarginfactor\textwidth}{\bf #2}}\vspace{-1.6\baselineskip}}\fi
\fi
\refstepcounter{bpa}\label{#2}
\ifdim \bpasize>2.5em \setlength{\Exlabelsep}{\bpasize-0.5em}%
\else \phlabelsepdefault\fi
\immediate\write\@auxout{\unexpanded{\expandafter\gdef\csname#2p\endcsname{\MakeLowercase#3}
\expandafter\gdef\csname#2\endcsname{\ref{#2}}  
\expandafter\gdef\csname#2r\endcsname{#3}}}
\expandafter\providecommand\expandafter{\csname#2p\endcsname}{\MakeLowercase#3}
\expandafter\providecommand\expandafter{\csname#2\endcsname}{\ref{#2}}  
\expandafter\providecommand\expandafter{\csname#2r\endcsname}{#3}
\ifhyperref 
\ex.[\hypertarget{#2}{\thebpa}\hspace{-1em}]
\renewcommand{\theExNo}{\csname#2\endcsname}
\renewcommand{\theFnExNo}{\csname#2\endcsname}
\if#1c \setlength{\abovedisplayskip}{1ex}\setlength{\belowdisplayskip}{2ex}\parbox{\centro}{\centering #3\philpunct} \else #3\fi\philpunct\par
\else
\ex.[\thebpa\hspace{-1em}]
\renewcommand{\theSubExNo}{\csname#2\endcsname\subettan{SubExNo}} 
\if#1c \setlength{\abovedisplayskip}{1ex}\setlength{\belowdisplayskip}{2ex}\parbox{\centro}{\centering #3\philpunct} \else #3\fi\philpunct\par
\fi
}

\WithSuffix\newcommand\lbpa*{\lbpaStar}
\newcommand{\lbpaStar}[3][n]{
\ifdim\lastskip=\Extopsep\vspace{\Exredux}
\ifphildraft
\label{#2knut}
    \vskip 0pt \penalty -400
\label{#2ulla}
\ifthenelse{\pageref{#2knut}=\pageref{#2ulla}}{\marginpar{\hspace{-\philmarginfactor\textwidth}{\raisebox{-1\baselineskip}{\bf #2}}}}{\marginpar{\hspace{-\philmarginfactor\textwidth}{\bf #2}}\vspace{-1\baselineskip}}\fi
\else
\ifphildraft
\label{#2knut}
    \vskip 0pt \penalty -400
\label{#2ulla}
\ifthenelse{\pageref{#2knut}=\pageref{#2ulla}}{\marginpar{\hspace{-\philmarginfactor\textwidth}{\raisebox{-1.6\baselineskip}{\bf #2}}}}{\marginpar{\hspace{-\philmarginfactor\textwidth}{\bf #2}}\vspace{-1.6\baselineskip}}\fi
\fi
\refstepcounter{bpa}\label{#2}
\setlength{\Exlabelsep}{0pt}
\immediate\write\@auxout{\unexpanded{\expandafter\gdef\csname#2p\endcsname{\MakeLowercase#3}
\expandafter\gdef\csname#2\endcsname{\ref{#2}}  
\expandafter\gdef\csname#2r\endcsname{#3}}}
\expandafter\providecommand\expandafter{\csname#2p\endcsname}{\MakeLowercase#3}
\expandafter\providecommand\expandafter{\csname#2\endcsname}{\ref{#2}}  
\expandafter\providecommand\expandafter{\csname#2r\endcsname}{#3}
\ifhyperref 
\ex.[\hypertarget{#2}{\thebpa}\hspace{-1em}]
\renewcommand{\theExNo}{\csname#2\endcsname}
\renewcommand{\theFnExNo}{\csname#2\endcsname}
\if#1c \setlength{\abovedisplayskip}{1ex}\setlength{\belowdisplayskip}{2ex}\parbox{\centro}{\centering #3\philpunct} \else \hspace{\bpasize} \hspace{-2em}#3\fi\philpunct\par
\else
\ex.[\thebpa\hspace{-1em}]
\renewcommand{\theSubExNo}{\csname#2\endcsname\subettan{SubExNo}} 
\if#1c \setlength{\abovedisplayskip}{1ex}\setlength{\belowdisplayskip}{2ex}\parbox{\centro}{\centering #3\philpunct} \else \hspace{\bpasize} \hspace{-2em}#3\fi\philpunct\par
\fi
}


%Stand-alone top-level initial sentence, sequence b:
\newcommand{\lbpb}[3][n]{
\ifdim\lastskip=\Extopsep\vspace{\Exredux}
\ifphildraft
\label{#2knut}
    \vskip 0pt \penalty -400
\label{#2ulla}
\ifthenelse{\pageref{#2knut}=\pageref{#2ulla}}{\marginpar{\hspace{-\philmarginfactor\textwidth}{\raisebox{-1\baselineskip}{\bf #2}}}}{\marginpar{\hspace{-\philmarginfactor\textwidth}{\bf #2}}\vspace{-1\baselineskip}}\fi
\else
\ifphildraft
\label{#2knut}
    \vskip 0pt \penalty -400
\label{#2ulla}
\ifthenelse{\pageref{#2knut}=\pageref{#2ulla}}{\marginpar{\hspace{-\philmarginfactor\textwidth}{\raisebox{-1.6\baselineskip}{\bf #2}}}}{\marginpar{\hspace{-\philmarginfactor\textwidth}{\bf #2}}\vspace{-1.6\baselineskip}}\fi
\fi
\refstepcounter{bpb}\label{#2}
\ifdim \bpbsize>2.5em \setlength{\Exlabelsep}{\bpbsize-0.5em}%
\else \phlabelsepdefault\fi
\immediate\write\@auxout{\unexpanded{\expandafter\gdef\csname#2p\endcsname{\MakeLowercase#3}\expandafter\gdef\csname#2\endcsname{\ref{#2}}  \expandafter\gdef\csname#2r\endcsname{#3}}}
\expandafter\providecommand\expandafter{\csname#2p\endcsname}{\MakeLowercase#3}
\expandafter\providecommand\expandafter{\csname #2\endcsname}{\ref{#2}}  
\expandafter\providecommand\expandafter{\csname#2r\endcsname}{#3}
\ifhyperref 
\ex.[\hypertarget{#2}{\thebpb}\hspace{-1em}]
\renewcommand{\theExNo}{\csname#2\endcsname}
\renewcommand{\theFnExNo}{\csname#2\endcsname}
\if#1c \setlength{\abovedisplayskip}{1ex}\setlength{\belowdisplayskip}{2ex}\parbox{\centro}{\centering #3\philpunct} \else #3\fi\philpunct\par
\else
\ex.[\thebpb\hspace{-1em}]
\renewcommand{\theSubExNo}{\csname#2\endcsname\subettan{SubExNo}} 
\if#1c \setlength{\abovedisplayskip}{1ex}\setlength{\belowdisplayskip}{2ex}\parbox{\centro}{\centering #3\philpunct} \else #3\fi\philpunct\par
\fi
}


\WithSuffix\newcommand\lbpb*{\lbpaStar}
\newcommand{\lbpbStar}[3][n]{
\ifdim\lastskip=\Extopsep\vspace{\Exredux}
\ifphildraft
\label{#2knut}
    \vskip 0pt \penalty -400
\label{#2ulla}
\ifthenelse{\pageref{#2knut}=\pageref{#2ulla}}{\marginpar{\hspace{-\philmarginfactor\textwidth}{\raisebox{-1\baselineskip}{\bf #2}}}}{\marginpar{\hspace{-\philmarginfactor\textwidth}{\bf #2}}\vspace{-1\baselineskip}}\fi
\else
\ifphildraft
\label{#2knut}
    \vskip 0pt \penalty -400
\label{#2ulla}
\ifthenelse{\pageref{#2knut}=\pageref{#2ulla}}{\marginpar{\hspace{-\philmarginfactor\textwidth}{\raisebox{-1.6\baselineskip}{\bf #2}}}}{\marginpar{\hspace{-\philmarginfactor\textwidth}{\bf #2}}\vspace{-1.6\baselineskip}}\fi
\fi
\refstepcounter{bpb}\label{#2}
\setlength{\Exlabelsep}{0pt}
\immediate\write\@auxout{\unexpanded{\expandafter\gdef\csname#2p\endcsname{\MakeLowercase#3}
\expandafter\gdef\csname#2\endcsname{\ref{#2}}  
\expandafter\gdef\csname#2r\endcsname{#3}}}
\expandafter\providecommand\expandafter{\csname#2p\endcsname}{\MakeLowercase#3}
\expandafter\providecommand\expandafter{\csname#2\endcsname}{\ref{#2}}  
\expandafter\providecommand\expandafter{\csname#2r\endcsname}{#3}
\ifhyperref 
\ex.[\hypertarget{#2}{\thebpb}\hspace{-1em}]
\renewcommand{\theExNo}{\csname#2\endcsname}
\renewcommand{\theFnExNo}{\csname#2\endcsname}
\if#1c \setlength{\abovedisplayskip}{1ex}\setlength{\belowdisplayskip}{2ex}\parbox{\centro}{\centering #3\philpunct} \else \hspace{\bpasize} \hspace{-2em}#3\fi\philpunct\par
\else
\ex.[\thebpb\hspace{-1em}]
\renewcommand{\theSubExNo}{\csname#2\endcsname\subettan{SubExNo}} 
\if#1c \setlength{\abovedisplayskip}{1ex}\setlength{\belowdisplayskip}{2ex}\parbox{\centro}{\centering #3\philpunct} \else \hspace{\bpasize} \hspace{-2em}#3\fi\philpunct\par
\fi
}

%Stand-alone top-level initial sentence, sequence c:
\newcommand{\lbpc}[3][n]{
\ifdim\lastskip=\Extopsep\vspace{\Exredux}
\ifphildraft
\label{#2knut}
    \vskip 0pt \penalty -400
\label{#2ulla}
\ifthenelse{\pageref{#2knut}=\pageref{#2ulla}}{\marginpar{\hspace{-\philmarginfactor\textwidth}{\raisebox{-1\baselineskip}{\bf #2}}}}{\marginpar{\hspace{-\philmarginfactor\textwidth}{\bf #2}}\vspace{-1\baselineskip}}\fi
\else
\ifphildraft
\label{#2knut}
    \vskip 0pt \penalty -400
\label{#2ulla}
\ifthenelse{\pageref{#2knut}=\pageref{#2ulla}}{\marginpar{\hspace{-\philmarginfactor\textwidth}{\raisebox{-1.6\baselineskip}{\bf #2}}}}{\marginpar{\hspace{-\philmarginfactor\textwidth}{\bf #2}}\vspace{-1.6\baselineskip}}\fi
\fi
\refstepcounter{bpc}\label{#2}
\ifdim \bpcsize>2.5em \setlength{\Exlabelsep}{\bpcsize-0.5em}%
\else \phlabelsepdefault\fi
\immediate\write\@auxout{\unexpanded{\expandafter\gdef\csname#2p\endcsname{\MakeLowercase#3}\expandafter\gdef\csname#2\endcsname{\ref{#2}}  \expandafter\gdef\csname#2r\endcsname{#3}}}
\expandafter\providecommand\expandafter{\csname#2p\endcsname}{\MakeLowercase#3}
\expandafter\providecommand\expandafter{\csname #2\endcsname}{\ref{#2}}  
\expandafter\providecommand\expandafter{\csname#2r\endcsname}{#3}
\ifhyperref 
\ex.[\hypertarget{#2}{\thebpc}\hspace{-1em}]
\renewcommand{\theExNo}{\csname#2\endcsname}
\renewcommand{\theFnExNo}{\csname#2\endcsname}
\if#1c \setlength{\abovedisplayskip}{1ex}\setlength{\belowdisplayskip}{2ex}\parbox{\centro}{\centering #3\philpunct} \else #3\fi \philpunct\par
\else
\ex.[\thebpc\hspace{-1em}]
\renewcommand{\theSubExNo}{\csname#2\endcsname\subettan{SubExNo}}
\if#1c \setlength{\abovedisplayskip}{1ex}\setlength{\belowdisplayskip}{2ex}\parbox{\centro}{\centering #3\philpunct} \else #3\fi\philpunct\par
\fi
}


\WithSuffix\newcommand\lbpc*{\lbpaStar}
\newcommand{\lbpcStar}[3][n]{
\ifdim\lastskip=\Extopsep\vspace{\Exredux}
\ifphildraft
\label{#2knut}
    \vskip 0pt \penalty -400
\label{#2ulla}
\ifthenelse{\pageref{#2knut}=\pageref{#2ulla}}{\marginpar{\hspace{-\philmarginfactor\textwidth}{\raisebox{-1\baselineskip}{\bf #2}}}}{\marginpar{\hspace{-\philmarginfactor\textwidth}{\bf #2}}\vspace{-1\baselineskip}}\fi
\else
\ifphildraft
\label{#2knut}
    \vskip 0pt \penalty -400
\label{#2ulla}
\ifthenelse{\pageref{#2knut}=\pageref{#2ulla}}{\marginpar{\hspace{-\philmarginfactor\textwidth}{\raisebox{-1.6\baselineskip}{\bf #2}}}}{\marginpar{\hspace{-\philmarginfactor\textwidth}{\bf #2}}\vspace{-1.6\baselineskip}}\fi
\fi
\refstepcounter{bpc}\label{#2}
\setlength{\Exlabelsep}{0pt}
\immediate\write\@auxout{\unexpanded{\expandafter\gdef\csname#2p\endcsname{\MakeLowercase#3}
\expandafter\gdef\csname#2\endcsname{\ref{#2}}  
\expandafter\gdef\csname#2r\endcsname{#3}}}
\expandafter\providecommand\expandafter{\csname#2p\endcsname}{\MakeLowercase#3}
\expandafter\providecommand\expandafter{\csname#2\endcsname}{\ref{#2}}  
\expandafter\providecommand\expandafter{\csname#2r\endcsname}{#3}
\ifhyperref 
\ex.[\hypertarget{#2}{\thebpc}\hspace{-1em}]
\renewcommand{\theExNo}{\csname#2\endcsname}
\renewcommand{\theFnExNo}{\csname#2\endcsname}
\if#1c \setlength{\abovedisplayskip}{1ex}\setlength{\belowdisplayskip}{2ex}\parbox{\centro}{\centering #3\philpunct} \else \hspace{\bpasize} \hspace{-2em}#3\fi\philpunct\par
\else
\ex.[\thebpc\hspace{-1em}]
\renewcommand{\theSubExNo}{\csname#2\endcsname\subettan{SubExNo}} 
\if#1c \setlength{\abovedisplayskip}{1ex}\setlength{\belowdisplayskip}{2ex}\parbox{\centro}{\centering #3\philpunct} \else \hspace{\bpasize} \hspace{-2em}#3\fi\philpunct\par
\fi
}


%Stand-alone sub-level initial sentence, sequence d:
\newcommand{\lbpd}[3][n]{
\ifdim\lastskip=\Extopsep\vspace{\Exredux}
\ifphildraft
\label{#2knut}
    \vskip 0pt \penalty -400
\label{#2ulla}
\ifthenelse{\pageref{#2knut}=\pageref{#2ulla}}{\marginpar{\hspace{-\philmarginfactor\textwidth}{\raisebox{-1\baselineskip}{\bf #2}}}}{\marginpar{\hspace{-\philmarginfactor\textwidth}{\bf #2}}\vspace{-1\baselineskip}}\fi
\else
\ifphildraft
\label{#2knut}
    \vskip 0pt \penalty -400
\label{#2ulla}
\ifthenelse{\pageref{#2knut}=\pageref{#2ulla}}{\marginpar{\hspace{-\philmarginfactor\textwidth}{\raisebox{-1.6\baselineskip}{\bf #2}}}}{\marginpar{\hspace{-\philmarginfactor\textwidth}{\bf #2}}\vspace{-1.6\baselineskip}}\fi
\fi
\refstepcounter{bpd}\label{#2}
\ifdim \bpdsize>2.5em \setlength{\Exlabelsep}{\bpdsize-0.5em}%
\else \phlabelsepdefault\fi
\immediate\write\@auxout{\unexpanded{\expandafter\gdef\csname#2p\endcsname{\MakeLowercase#3}\expandafter\gdef\csname#2\endcsname{\ref{#2}}  \expandafter\gdef\csname#2r\endcsname{#3}}}
\expandafter\providecommand\expandafter{\csname#2p\endcsname}{\MakeLowercase#3}
\expandafter\providecommand\expandafter{\csname #2\endcsname}{\ref{#2}}  
\expandafter\providecommand\expandafter{\csname#2r\endcsname}{#3}
\else \fi
\ifhyperref 
\ex.[\hypertarget{#2}{\thebpd}\hspace{-1em}]
\renewcommand{\theExNo}{\csname#2\endcsname}
\renewcommand{\theFnExNo}{\csname#2\endcsname} 
\if#1c \setlength{\abovedisplayskip}{1ex}\setlength{\belowdisplayskip}{2ex}\parbox{\centro}{\centering #3\philpunct} \else #3\fi\philpunct\par
\else
\ex.[\thebpd\hspace{-1em}]
\renewcommand{\theSubExNo}{\csname#2\endcsname\subettan{SubExNo}} 
\if#1c \setlength{\abovedisplayskip}{1ex}\setlength{\belowdisplayskip}{2ex}\parbox{\centro}{\centering #3\philpunct} \else #3\fi\philpunct\par
\fi
}


\WithSuffix\newcommand\lbpd*{\lbpdStar}
\newcommand{\lbpdStar}[3][n]{
\ifdim\lastskip=\Extopsep\vspace{\Exredux}
\ifphildraft
\label{#2knut}
    \vskip 0pt \penalty -400
\label{#2ulla}
\ifthenelse{\pageref{#2knut}=\pageref{#2ulla}}{\marginpar{\hspace{-\philmarginfactor\textwidth}{\raisebox{-1\baselineskip}{\bf #2}}}}{\marginpar{\hspace{-\philmarginfactor\textwidth}{\bf #2}}\vspace{-1\baselineskip}}\fi
\else
\ifphildraft
\label{#2knut}
    \vskip 0pt \penalty -400
\label{#2ulla}
\ifthenelse{\pageref{#2knut}=\pageref{#2ulla}}{\marginpar{\hspace{-\philmarginfactor\textwidth}{\raisebox{-1.6\baselineskip}{\bf #2}}}}{\marginpar{\hspace{-\philmarginfactor\textwidth}{\bf #2}}\vspace{-1.6\baselineskip}}\fi
\fi
\refstepcounter{bpd}\label{#2}
\setlength{\Exlabelsep}{0pt}
\immediate\write\@auxout{\unexpanded{\expandafter\gdef\csname#2p\endcsname{\MakeLowercase#3}
\expandafter\gdef\csname#2\endcsname{\ref{#2}}  
\expandafter\gdef\csname#2r\endcsname{#3}}}
\expandafter\providecommand\expandafter{\csname#2p\endcsname}{\MakeLowercase#3}
\expandafter\providecommand\expandafter{\csname#2\endcsname}{\ref{#2}}  
\expandafter\providecommand\expandafter{\csname#2r\endcsname}{#3}
\ifhyperref 
\ex.[\hypertarget{#2}{\thebpd}\hspace{-1em}]
\renewcommand{\theExNo}{\csname#2\endcsname}
\renewcommand{\theFnExNo}{\csname#2\endcsname}
\if#1c \setlength{\abovedisplayskip}{1ex}\setlength{\belowdisplayskip}{2ex}\parbox{\centro}{\centering #3\philpunct} \else \hspace{\bpasize} \hspace{-2em}#3\fi\philpunct\par
\else
\ex.[\thebpd\hspace{-1em}]
\renewcommand{\theSubExNo}{\csname#2\endcsname\subettan{SubExNo}} 
\if#1c \setlength{\abovedisplayskip}{1ex}\setlength{\belowdisplayskip}{2ex}\parbox{\centro}{\centering #3\philpunct} \else \hspace{\bpasize} \hspace{-2em}#3\fi\philpunct\par
\fi
}

%Top-level sentence with repeated and suffixed name or number:
\newcommand{\lbu}[5][n]{
\ifdim\lastskip=\Extopsep\vspace{\Exredux}
\ifphildraft
\label{#2knut}
    \vskip 0pt \penalty -400
\label{#2ulla}
\ifthenelse{\pageref{#2knut}=\pageref{#2ulla}}{\marginpar{\hspace{-\philmarginfactor\textwidth}{\raisebox{-1\baselineskip}{\bf #2}}}}{\marginpar{\hspace{-\philmarginfactor\textwidth}{\bf #2}}\vspace{-1\baselineskip}}\fi
\else
\ifphildraft
\label{#2knut}
    \vskip 0pt \penalty -400
\label{#2ulla}
\ifthenelse{\pageref{#2knut}=\pageref{#2ulla}}{\marginpar{\hspace{-\philmarginfactor\textwidth}{\raisebox{-1.6\baselineskip}{\bf #2}}}}{\marginpar{\hspace{-\philmarginfactor\textwidth}{\bf #2}}\vspace{-1.6\baselineskip}}\fi
\fi
\label{#2}
\phlabelwidth{10cm}
\settowidth{\sebatemp}{\rn{#3}#4}
\settowidth{\seba}{\rsep{#2}}
\ifdim \sebatemp>\seba
\expandafter\gdef\csname #2sep\endcsname{\rn{#3}#4}%
\settowidth{\seba}{\rsep{#2}}%
\immediate\write\@auxout{\unexpanded{\expandafter\gdef\csname#2sep\endcsname{\rn{#3}#4}}}
\else
\fi
\ifdim \seba>2.5em \setlength{\Exlabelsep}{\seba-1em}%
\else \phlabelsepdefault\fi
\immediate\write\@auxout{\unexpanded{\expandafter\gdef\csname#2p\endcsname{\MakeLowercase#5}
\expandafter\gdef\csname #2\endcsname{\csname#3\endcsname#4}
\expandafter\gdef\csname #2r\endcsname{#5}}}
\expandafter\providecommand\expandafter{\csname#2p\endcsname}{\MakeLowercase#5}
\expandafter\providecommand\expandafter{\csname #2\endcsname}{\csname#3\endcsname#4}
\expandafter\providecommand\expandafter{\csname #2r\endcsname}{#5}
\ifhyperref
\ex.[\lebrack\hypertarget{#2}{\csname#3\endcsname#4}\ribrack\hspace{-1em}]
\renewcommand{\theExNo}{\csname#2\endcsname}
\if#1c \setlength{\abovedisplayskip}{1ex}\setlength{\belowdisplayskip}{2ex}\parbox{\centro}{\centering #5\philpunct} \else #5\philpunct\fi\par
\else
\ex.[\lebrack\csname#3\endcsname#4\ribrack\hspace{-1em}]
\renewcommand{\theExNo}{\csname#2\endcsname} 
\if#1c \setlength{\abovedisplayskip}{1ex}\setlength{\belowdisplayskip}{2ex}\parbox{\centro}{\centering #5\philpunct} \else #5\philpunct\fi\par \fi
}

\WithSuffix\newcommand\lbu*{\lbuStar}
\newcommand{\lbuStar}[5][n]{
\ifdim\lastskip=\Extopsep\vspace{\Exredux}
\ifphildraft
\label{#2knut}
    \vskip 0pt \penalty -400
\label{#2ulla}
\ifthenelse{\pageref{#2knut}=\pageref{#2ulla}}{\marginpar{\hspace{-\philmarginfactor\textwidth}{\raisebox{-1\baselineskip}{\bf #2}}}}{\marginpar{\hspace{-\philmarginfactor\textwidth}{\bf #2}}\vspace{-1\baselineskip}}\fi
\else
\ifphildraft
\label{#2knut}
    \vskip 0pt \penalty -400
\label{#2ulla}
\ifthenelse{\pageref{#2knut}=\pageref{#2ulla}}{\marginpar{\hspace{-\philmarginfactor\textwidth}{\raisebox{-1.6\baselineskip}{\bf #2}}}}{\marginpar{\hspace{-\philmarginfactor\textwidth}{\bf #2}}\vspace{-1.6\baselineskip}}\fi
\fi
\label{#2}
\phlabelwidth{10cm}
\phlabelsepdefault
\settowidth{\sebatemp}{\rn{#3}#4}
\immediate\write\@auxout{\unexpanded{\expandafter\gdef\csname#2p\endcsname{\MakeLowercase#5}
\expandafter\gdef\csname #2\endcsname{\csname#3\endcsname#4}
\expandafter\gdef\csname #2r\endcsname{#5}}}
\expandafter\providecommand\expandafter{\csname#2p\endcsname}{\MakeLowercase#5}
\expandafter\providecommand\expandafter{\csname #2\endcsname}{\csname#3\endcsname#4}
\expandafter\providecommand\expandafter{\csname #2r\endcsname}{#5}
\ifhyperref
\ex.[\lebrack\hypertarget{#2}{\csname#3\endcsname#4}\ribrack\hspace{-1em}]
\renewcommand{\theExNo}{\csname#2\endcsname}
\if#1c \setlength{\abovedisplayskip}{1ex}\setlength{\belowdisplayskip}{2ex}\parbox{\centro}{\centering #5\philpunct} \else \hspace{\sebatemp} \hspace{-2em} #5\philpunct\fi\par
\else
\ex.[\lebrack\csname#3\endcsname#4\ribrack\hspace{-1em}]
\renewcommand{\theExNo}{\csname#2\endcsname} 
\if#1c \setlength{\abovedisplayskip}{1ex}\setlength{\belowdisplayskip}{2ex}\parbox{\centro}{\centering #5\philpunct} \else\hspace{\sebatemp} \hspace{-2em}  #5\philpunct\fi\par \fi
}


%Top-level sentence with repeated and suffixed name or number, alternative for alignment:
\newcommand{\lbusep}[6][n]{
\ifdim\lastskip=\Extopsep\vspace{\Exredux}
\ifphildraft
\label{#2knut}
    \vskip 0pt \penalty -400
\label{#2ulla}
\ifthenelse{\pageref{#2knut}=\pageref{#2ulla}}{\marginpar{\hspace{-\philmarginfactor\textwidth}{\raisebox{-1\baselineskip}{\bf #2}}}}{\marginpar{\hspace{-\philmarginfactor\textwidth}{\bf #2}}\vspace{-1\baselineskip}}\fi
\else
\ifphildraft
\label{#2knut}
    \vskip 0pt \penalty -400
\label{#2ulla}
\ifthenelse{\pageref{#2knut}=\pageref{#2ulla}}{\marginpar{\hspace{-\philmarginfactor\textwidth}{\raisebox{-1.6\baselineskip}{\bf #2}}}}{\marginpar{\hspace{-\philmarginfactor\textwidth}{\bf #2}}\vspace{-1.6\baselineskip}}\fi
\fi
\label{#2}
\phlabelwidth{10cm}
\settowidth{\seba}{\rsep{#5}}
\settowidth{\sebatemp}{\rn{#3}#4}
\ifdim \seba>\sebatemp
\relax
\else
\expandafter\gdef\csname #5sep\endcsname{\rn{#3}#4}%
\settowidth{\seba}{\rsep{#5}}%
\immediate\write\@auxout{\unexpanded{\expandafter\gdef\csname#5sep\endcsname{\rn{#3}#4}}}
\fi
\ifdim \seba>2.5em \setlength{\Exlabelsep}{\seba-1em}%
\else \phlabelsepdefault\fi
\immediate\write\@auxout{\unexpanded{\expandafter\gdef\csname#2p\endcsname{\MakeLowercase#6}
\expandafter\gdef\csname #2\endcsname{\csname#3\endcsname#4}
\expandafter\gdef\csname #2r\endcsname{#6}}}
\expandafter\providecommand\expandafter{\csname#2p\endcsname}{\MakeLowercase#6}
\expandafter\providecommand\expandafter{\csname #2\endcsname}{\csname#3\endcsname#4}
\expandafter\providecommand\expandafter{\csname #2r\endcsname}{#6}
\ifhyperref
\ex.[\lebrack\hypertarget{#2}{\csname#3\endcsname#4}\ribrack\hspace{-1em}]
\renewcommand{\theExNo}{\csname#2\endcsname}
\if#1c \setlength{\abovedisplayskip}{1ex}\setlength{\belowdisplayskip}{2ex}\parbox{\centro}{\centering #6\philpunct} \else #6\philpunct\fi\par
\else
\ex.[\lebrack\csname#3\endcsname#4\ribrack\hspace{-1em}]
\renewcommand{\theExNo}{\csname#2\endcsname} 
\if#1c \setlength{\abovedisplayskip}{1ex}\setlength{\belowdisplayskip}{2ex}\parbox{\centro}{\centering #6\philpunct} \else #6\philpunct\fi\par
\fi
}

%Non-printing command for setting of label-separation for alignment:
\newcommand{\sepset}[2]{
\label{#1}
\expandafter\gdef\csname #1sep\endcsname{#2}%
\immediate\write\@auxout{\unexpanded{\expandafter\gdef\csname#1sep\endcsname{#2}}}}

%----------------- Sub-environments -------------------------------

\newcommand{\philsemi}{@}
\newcommand{\lba}[3][@]{\philempty
\def\tempa{#1}
\def\tempb{#1}
\ifnum\theExDepth=0\def\tempc{\tempa}\fi
\ifnum\theExDepth=1\def\tempc{\tempa} 
\setcounter{altsub}{0}
\refstepcounter{altsub}\label{#2q}
\renewcommand{\thealtsubsub}{\thealtsub\secondphildash\Exroman{altsubsub}}
\else \ifnum \theExDepth=2\def\tempc{\tempb}
\setcounter{altsubsub}{0}
\refstepcounter{altsubsub}\label{#2q}
\else\fi\fi
\if \tempc\philsemi
\immediate\write\@auxout{\unexpanded{%
\expandafter\gdef\csname#2p\endcsname{\MakeLowercase#3}
\expandafter\gdef\csname#2r\endcsname{#3}
\expandafter\global\expandafter\def\csname#2\endcsname{\ref{#2}}
\expandafter\global\expandafter\def\csname#2q\endcsname{\ref{#2q}}
}}
\expandafter\providecommand\csname#2p\endcsname{\MakeLowercase#3}
\expandafter\providecommand\csname#2r\endcsname{#3} 
\expandafter\providecommand\csname#2\endcsname{\ref{#2}}
\expandafter\providecommand\csname#2q\endcsname{\ref{#2q}}
\a. \label{#2}#3\philsubpunct
\else

\ifnum\theExDepth=1
\renewcommand{\thealtsub}{#1}
\renewcommand{\theSubExNo}{\theExNo\firstphildash#1}
\refstepcounter{SubExNo}

\immediate\write\@auxout{%
\unexpanded{\expandafter\gdef\csname#2p\endcsname{\MakeLowercase#3}
\expandafter\gdef\csname#2r\endcsname{#3}
\expandafter\gdef\csname#2\endcsname{\ref{#2}}
\expandafter\global\expandafter\def\csname#2q\endcsname{#1}
}}
\else
\ifnum\theExDepth=2
\renewcommand{\thealtsubsub}{\thealtsub\secondphildash#1}
\refstepcounter{altsubsub}\label{#2q}
\renewcommand{\theSubSubExNo}{\theSubExNo\secondphildash#1}
\refstepcounter{SubSubExNo}
\immediate\write\@auxout{%
\unexpanded{\expandafter\gdef\csname#2p\endcsname{\MakeLowercase#3}
\expandafter\gdef\csname#2r\endcsname{#3}
\expandafter\gdef\csname#2\endcsname{\ref{#2}}
\expandafter\global\expandafter\def\csname#2q\endcsname{\ref{#2q}}
}}
 \else \fi\fi
\ifhyperref
\a.[\hypertarget{#2}\lebrack#1\ribrack]\label{#2}#3\philsubpunct 
\else
\a.[\lebrack#1\ribrack]\label{#2}#3\philsubpunct
\fi
\ifnum\theExDepth=2
\renewcommand{\theSubExNo}{\theExNo\firstphildash\subettan{SubExNo}}
\renewcommand{\theSubSubExNo}{\theSubExNo\secondphildash\Exroman{SubSubExNo}}
\setcounter{altsub}{0}
\renewcommand{\thealtsub}{\subettan{altsub}}
\fi
\ifnum\theExDepth=3
\renewcommand{\thealtsubsub}{\thealtsub\secondphildash\Exroman{altsubsub}}
\setcounter{altsubsub}{0}
\setcounter{SubSubExNo}{0}
\fi
\fi
\ifphildraft
\marginpar{\vspace{-0.8\baselineskip}\quad   \bf #2 \hspace{-2cm}}
\else \fi
}


\newcommand{\lbb}[3][@]{\philempty
\def\tempa{#1}
\def\tempb{#1}
\if \tempc\philsemi
\ifnum\theExDepth=1
\def\tempc{\tempa}\fi
\ifnum\theExDepth=2
\def\tempc{\tempb}
\renewcommand{\thealtsub}{\subettan{altsub}}
\renewcommand{\thealtsubsub}{\thealtsub\secondphildash\Exroman{altsubsub}}
\refstepcounter{altsub}\label{#2q}
\else
\refstepcounter{altsubsub}\label{#2q}
\renewcommand{\theSubSubExNo}{\theSubExNo\secondphildash\Exroman{SubSubExNo}}
\def\tempc{\tempb}
\fi
\immediate\write\@auxout{\unexpanded{\expandafter\gdef\csname#2p		\endcsname{\MakeLowercase#3}\expandafter\gdef\csname#2r\endcsname{#3} \expandafter\global\expandafter\def\csname#2\endcsname{\ref{#2}}
\expandafter\global\expandafter\def\csname#2q\endcsname{\ref{#2q}}
}} 
\expandafter\providecommand\csname#2p\endcsname{\MakeLowercase#3}
\expandafter\providecommand\csname#2r\endcsname{#3} 
\expandafter\providecommand\csname#2\endcsname{\ref{#2}}
\expandafter\providecommand\csname#2q\endcsname{\ref{#2q}}
 \b. \label{#2}#3\philsubpunct
 \else 
 \ifnum\theExDepth=1 
\renewcommand{\thealtsub}{#1}
\renewcommand{\theSubExNo}{\theExNo\firstphildash#1}
\refstepcounter{SubExNo}
 \immediate\write\@auxout{%
\unexpanded{\expandafter\gdef\csname#2p\endcsname{\MakeLowercase#3}
\expandafter\gdef\csname#2r\endcsname{#3} 
\expandafter\gdef\csname#2\endcsname{ref{#2}}
\expandafter\global\expandafter\def\csname#2q\endcsname{#1}
}}
\else 
\ifnum\theExDepth=2
\renewcommand{\thealtsubsub}{\thealtsub\secondphildash#1} 
\refstepcounter{altsubsub}\label{#2q}
\renewcommand{\theSubSubExNo}{\theSubExNo\secondphildash#1}
\refstepcounter{SubSubExNo}
\immediate\write\@auxout{%
\unexpanded{\expandafter\gdef\csname#2p\endcsname{\MakeLowercase#3}
\expandafter\gdef\csname#2r\endcsname{#3}
\expandafter\gdef\csname#2\endcsname{\ref{#2}}
\expandafter\global\expandafter\def\csname#2q\endcsname{\ref{#2q}}
}}
\else\fi\fi 
\ifhyperref
\b.[\hypertarget{#2}\lebrack#1\ribrack] \label{#2}#3\philsubpunct 
\else
\b.[\lebrack#1\ribrack] \label{#2}#3\philsubpunct \fi
\fi
\ifphildraft
\marginpar{\vspace{-0.5\baselineskip}\quad  \bf #2}
\else \fi}

\newcommand{\lbz}[3][@]{\philempty
\def\tempa{#1}
\def\tempb{#1}
\if \tempc\philsemi 
\renewcommand{\thealtsub}{\subettan{altsub}}
\renewcommand{\thealtsubsub}{\thealtsub\secondphildash\Exroman{altsubsub}}
\ifnum\theExDepth=1
\def\tempc{\tempa}\fi
\ifnum\theExDepth=2
\def\tempc{\tempb}
\refstepcounter{altsub}\label{#2q} 
\else
\renewcommand{\thealtsub}{\subettan{altsub}}
\renewcommand{\thealtsubsub}{\thealtsub\secondphildash\Exroman{altsubsub}}
\refstepcounter{altsubsub}\label{#2q}
\renewcommand{\theSubSubExNo}{\theSubExNo\secondphildash\Exroman{SubSubExNo}}
\def\tempc{\tempb}\fi
\immediate\write\@auxout{\unexpanded{\expandafter\gdef\csname#2p		\endcsname{\MakeLowercase#3}\expandafter\gdef\csname#2r\endcsname{#3} \expandafter\gdef\csname#2\endcsname{\ref{#2}}
\expandafter\global\expandafter\def\csname#2q\endcsname{\ref{#2q}}}} 
\expandafter\providecommand\csname#2p\endcsname{\MakeLowercase#3}
\expandafter\providecommand\csname#2r\endcsname{#3} 
\expandafter\providecommand\csname#2\endcsname{\ref{#3}}
 \b. \label{#2}#3\philsubpunct
 \else 
\ifnum\theExDepth=1 
\renewcommand{\theSubExNo}{\theExNo\firstphildash#1}
\refstepcounter{SubExNo}
\renewcommand{\thealtsub}{#1}
\renewcommand{\thealtsubsub}{\thealtsub\secondphildash#1}
\else 
\ifnum\theExDepth=2
\renewcommand{\theSubExNo}{\theExNo\firstphildash#1}
\refstepcounter{SubExNo}
\renewcommand{\thealtsub}{#1}
\refstepcounter{altsub}\label{#2q}
\immediate\write\@auxout{\unexpanded{\expandafter\gdef\csname#2p		\endcsname{\MakeLowercase#3}
\expandafter\gdef\csname#2r\endcsname{#3} 
\expandafter\gdef\csname#2\endcsname{\ref{#2}}
\expandafter\global\expandafter\def\csname#2q\endcsname{\ref{#2q}}
}}
\else
\ifnum\theExDepth=3
\renewcommand{\thealtsubsub}{\thealtsub\secondphildash#1} 
\refstepcounter{altsubsub}\label{#2q}
\renewcommand{\theSubSubExNo}{\theSubExNo\secondphildash#1}
\refstepcounter{SubSubExNo}\label{#2}
\immediate\write\@auxout{\unexpanded{\expandafter\gdef\csname#2p		\endcsname{\MakeLowercase#3}
\expandafter\gdef\csname#2r\endcsname{#3} 
\expandafter\gdef\csname#2\endcsname{\ref{#2}}
\expandafter\global\expandafter\def\csname#2q\endcsname{\ref{#2q}}
}}
\fi\fi\fi 
\expandafter\providecommand\csname#2p\endcsname{\MakeLowercase#3}
\expandafter\providecommand\csname#2r\endcsname{#3} 
\expandafter\providecommand\csname#2\endcsname{\ref{#2}}
\expandafter\providecommand\csname#2q\endcsname{\ref{#2q}}
\ifhyperref
\b.[\hypertarget{#2}\lebrack#1\ribrack] \label{#2}#3\philsubpunct 
\else
\b.[\lebrack#1\ribrack] \label{#2}#3\philsubpunct \fi
\fi
\ifphildraft
\marginpar{\vspace{-0.5\baselineskip}\quad  \bf #2}
\else \fi
\end{list}\addtocounter{ExDepth}{-1}\philsubempty}


%Cross-reference
\newcommand{\rf}[2][]{%
\ifhyperref%
(\hyperlink{#2}{\csname#2\endcsname}#1)%
\else%
(\csname#2\endcsname#1)%
\fi}

%Cross-reference to subsentence without main number:
\newcommand{\rfx}[2][]{%
\ifhyperref%
(\hyperlink{#2}{\csname#2q\endcsname}#1)%
\else%
(\csname#2q\endcsname#1)%
\fi}

%Cross-reference without brackets
\newcommand{\rn}[2][]{%
\ifhyperref%
\hyperlink{#2}{\csname#2\endcsname}#1%
\else%
\csname#2\endcsname#1%
\fi}

%Cross-reference to subsentence without brackets and main number:
\newcommand{\rnx}[2][]{%
\ifhyperref%
\hyperlink{#2}{\csname#2q\endcsname}#1%
\else%
\csname#2q\endcsname#1%
\fi}

%Repeating the sentence
\newcommand{\rp}[1]{\csname#1r\endcsname}

%Repeating the sentence with lowercase initial letter
\newcommand{\ml}[1]{\csname#1p\endcsname}

%Repeating the sentence with name or number:
\newcommand{\rff}[2][n]{\ifdim\lastskip=\Extopsep\vspace{\Exredux}\fi
\ifhyperref
\ex.[(\hyperlink{#2}{\csname#2\endcsname})]
\if#1c \setlength{\abovedisplayskip}{1ex}\setlength{\belowdisplayskip}{1ex}\parbox{\centro}{\centering \csname#2r\endcsname\philpunct}
\else \csname#2r\endcsname\philpunct\fi
\else
\ex.[(\csname#2\endcsname)]
\if#1c \setlength{\abovedisplayskip}{1ex}\setlength{\belowdisplayskip}{1ex}\parbox{\centro}{\centering \csname#2r\endcsname\philpunct}
\else \csname#2r\endcsname\philpunct\fi\fi
\par}

%Repeating the sentence with name or number but without footnote:
\newcommand{\rffnot}[2][n]{
\ifdim\lastskip=\Extopsep\vspace{\Exredux}\fi
\ifhyperref
\ex.[(\hyperlink{#2}{\csname#2\endcsname})]
\renewcommand{\footnote}[1]{}
\if#1c \setlength{\abovedisplayskip}{1ex}\setlength{\belowdisplayskip}{1ex}\parbox{\centro}{\centering \csname#2r\endcsname\philpunct}
\else \csname#2r\endcsname\philpunct\fi
\else
\ex.[(\csname#2\endcsname)]
\renewcommand{\footnote}[1]{}
\if#1c \setlength{\abovedisplayskip}{1ex}\setlength{\belowdisplayskip}{1ex}\parbox{\centro}{\centering \csname#2r\endcsname\philpunct}
\else \csname#2r\endcsname\philpunct\fi\fi
\par}

%Repeating the sentence with name or number and bracket control:
\newcommand{\rfp}[1]{\ex.[\lebrack\csname#1\endcsname\ribrack\hspace{-1em}] \csname #1r\endcsname\par}

%Cross-reference for control of label-separation
\newcommand{\rsep}[1]{\csname#1sep\endcsname}

%Controlling numbering, prefix and suffix for SubExNo
\newcommand{\subformat}[3]{\if#1a  \renewcommand{\subettan}{\alph} \else 
\if#1A \renewcommand{\subettan}{\Alph} \else \if#11 \renewcommand{\subettan}{\arabic} \else \if#1r \renewcommand{\subettan}{\roman} \else \if#1R \renewcommand{\subettan}{\Roman} \else \fi \fi \fi \fi \fi \renewcommand{\SubExLBr}{#2} 
\renewcommand{\SubExRBr}{#3}
\renewcommand{\SubExlabel}{\SubExLBr\subettan{SubExNo}\SubExRBr}
\if@noftnote \renewcommand{\theSubExNo}{\theExNo\firstphildash\subettan{SubExNo}}
\else \renewcommand{\theSubExNo}{\theFnExNo\firstphildash\subettan{SubExNo}} \fi
\renewcommand{\theSubSubExNo}{\theSubExNo\secondphildash\Exroman{SubSubExNo}}
}

%Ditto for stand-alone sequences, a-d:
\newcommand{\bota}{\alph}
\newcommand{\bpaformat}[4][0]{\setcounter{bpa}{0}
\settowidth{\sebatemp}{#399#4}
\setlength{\bpasize}{#1em+\sebatemp}
\if#2a  \else 
\if#2A \renewcommand{\bota}{\Alph} \else \if#21 \renewcommand{\bota}{\arabic} \else \if#2r \renewcommand{\bota}{\roman} \else \if#2R \renewcommand{\bota}{\Roman} \else \fi \fi \fi \fi \fi \renewcommand{\thebpa}{#3\bota{bpa}#4}}

\newcommand{\botb}{\alph}
\newcommand{\bpbformat}[4][0]{\setcounter{bpb}{0}
\settowidth{\sebatemp}{#399#4}
\setlength{\bpbsize}{#1em+\sebatemp}
\if#2a  \else 
\if#2A \renewcommand{\botb}{\Alph} \else \if#21 \renewcommand{\botb}{\arabic} \else \if#2r \renewcommand{\botb}{\roman} \else \if#2R \renewcommand{\botb}{\Roman} \else \fi \fi \fi \fi \fi \renewcommand{\thebpb}{#3\botb{bpb}#4}}

\newcommand{\botc}{\alph}
\newcommand{\bpcformat}[4][0]{\setcounter{bpc}{0}
\settowidth{\sebatemp}{#399#4}
\setlength{\bpcsize}{#1em+\sebatemp}
\if#2a  \else 
\if#2A \renewcommand{\botc}{\Alph} \else \if#21 \renewcommand{\botc}{\arabic} \else \if#2r \renewcommand{\botc}{\roman} \else \if#2R \renewcommand{\botc}{\Roman} \else \fi \fi \fi \fi \fi \renewcommand{\thebpc}{#3\botc{bpc}#4}}

\newcommand{\botd}{\alph}
\newcommand{\bpdformat}[4][0]{\setcounter{bpd}{0}
\settowidth{\sebatemp}{#399#4}
\setlength{\bpdsize}{#1em+\sebatemp}
\if#2a  \else 
\if#2A \renewcommand{\botd}{\Alph} \else \if#21 \renewcommand{\botd}{\arabic} \else \if#2r \renewcommand{\botd}{\roman} \else \if#2R \renewcommand{\botd}{\Roman} \else \fi \fi \fi \fi \fi \renewcommand{\thebpd}{#3\botd{bpd}#4}}

%Controlling numbering, prefix and suffix for SubSubExNo
\newcommand{\subsubformat}[3]{\if#1r \renewcommand{\Exroman}{\roman} \else 
\if#1A\renewcommand{\Exroman}{\Alph} \else \if#11 \renewcommand{\Exroman}{\arabic} \else \if#1a \renewcommand{\Exroman}{\alph} \else \if#1R \renewcommand{\Exroman}{\Roman} \else \fi \fi \fi \fi \fi 
\renewcommand{\SubSubExLBr}{#2} 
\renewcommand{\SubSubExRBr}{#3}
\renewcommand{\theSubSubExNo}{\theSubExNo\secondphildash\Exroman{SubSubExNo}}}

%Fast changing between alphabetic, arabic and roman) for SubEx
\newcommand{\sa}{\renewcommand{\SubExRBr}{.}\renewcommand{\SubExlabel}{\SubExLBr\alph{SubExNo}\SubExRBr}\renewcommand{\theSubExNo}{\arabic{ExNo}\alph{SubExNo}}}

\newcommand{\sr}{\renewcommand{\SubExRBr}{)}\renewcommand{\SubExlabel}{\SubExLBr\roman{SubExNo}\SubExRBr}\renewcommand{\theSubExNo}{\arabic{ExNo}\roman{SubExNo}}}

\newcommand{\sab}{\renewcommand{\SubExRBr}{)}\renewcommand{\SubExlabel}{\SubExLBr\alph{SubExNo}\SubExRBr}\renewcommand{\theSubExNo}{\arabic{ExNo}\alph{SubExNo}}}

%Grammaticality and other judgments
\newlength{\grlen}
\newcommand{\oddity}[1]{\settowidth{\grlen}{#1}\hspace{-\grlen}#1}













