% \iffalse meta-comment 
%
% Copyright (C) 2006 by Mathieu Boretti
% 
% This file may be distributed and/or modified under the 
% conditions of the LaTeX Project Public License, either 
% version 1.3 of this license or (at your option) any later 
% version. The latest version of this license is in: 
% 
% http://www.latex-project.org/lppl.txt 
% 
% and version 1.3 or later is part of all distributions of 
% LaTeX version 2003/12/01 or later.
%
% The current Maintainer of this work is Mathieu Boretti
%
% This work consists of the file syntrace.ins and
% syntrace.dtx and the derived file syntrace.sty
% 
% 
% \fi 
% \iffalse
%<package>\NeedsTeXFormat{LaTeX2e}
%<package>\ProvidesPackage{syntrace}[2006/08/17 v1.1 Package for dealing with trace in syntaxic tree]
%<package>\RequirePackage{ifthen}
%<package>\DeclareOption{synttree}{
%<package>\AtEndOfPackage{%
%<package>\IfFileExists{synttree.sty}{%
%<package>\RequirePackage{synttree}\syntraceaddresetmacro{synttree}%
%<package>}{%
%<package>\PackageWarning{syntrace}{Unable to locate synttree package}
%<package>}
%<package>}
%<package>}
%<package>\DeclareOption{qtree}{
%<package>\AtEndOfPackage{%
%<package>\IfFileExists{qtree.sty}{%
%<package>\RequirePackage{qtree}\syntraceaddresetmacro{Tree}%
%<package>}{%
%<package>\PackageWarning{syntrace}{Unable to locate qtree package}
%<package>}
%<package>}
%<package>}
%<package>\DeclareOption{i-start}{
%<package>\AtEndOfPackage{%
%<package>\setcounter{syntrace@startvalue}{8}
%<package>}
%<package>}
%<package>\ExecuteOptions{synttree}
%<package>\ProcessOptions
%
%<*driver>
\documentclass{ltxdoc}
\usepackage[qtree,i-start]{syntrace}
\usepackage{verbatim}
\EnableCrossrefs
\CodelineIndex
\RecordChanges
\begin{document}
    \DocInput{syntrace.dtx}
\end{document}
%</driver>
% \fi
% \GetFileInfo{syntrace.sty}
% \title{The \textsf{syntrace} package\thanks{This document corresponds to \textsf{syntrace}~\fileversion, dated~\filedate.}}
% \author{Mathieu Boretti \\ \texttt{mathieu.boretti@gmail.com}}
%
% \maketitle
%
% \begin{abstract}
% This file describe the \textsf{syntrace} package. This package is intended for \LaTeX\ users who must deal with
% traces in synttree. 
% \end{abstract}
%
% \section{Options}
%
% \DescribeMacro{synttree} The |synttree| option add the synttree command of the synttree package to the auto reset commands. With this option, the |\synttree| command is redefined to auto reset trace counter. A |\synttree*| command is add that work like |\synttree|, but without auto reset. This option is enabled is a default options.
%
% \DescribeMacro{qtree} The |qtree| option add the Tree command of the qtree package to the auto reset command.
%
% \DescribeMacro{i-start} The |i-start| change the first label of trace to i instance of a.
% 
% \section{Usage}
% The \textsf{syntrace} package add a way to deal with trace in tree produce using the \textsf{synttree} package.
%
% \DescribeMacro{\traceLabel} The |\traceLabel{label}| set and draw a end trace. The parameter is the label to use for 
% the reference.
%
% \DescribeMacro{\traceReference} The |\traceReference{ref}| draw a trace linked with the specified reference.
%
% \DescribeMacro{\syntraceresetmacro} The |\syntraceresetmacro{commande name without slash}| add auto-reset to this command.
%
% \section{Examples}
% \subsection{Simply example with synttree}
% \begin{verbatim}
% \synttree[A %
%           [B [C\traceLabel{l1}] [D]] %
%           [E [F] [\traceReference{l1}]]%
%          ]
% \end{verbatim}
% \synttree[A %
%           [B [C\traceLabel{l1}] [D]] %
%           [E [F] [\traceReference{l1}]]%
%          ]
% \subsection{One complex example with synttree}
% \begin{verbatim}
% \synttree*[AgrP
%            [DP\traceLabel{sujet1} [.t Le chat]]
%            [Agr'
%             [Arg [dort\traceLabel{verbe1}]]
%             [TP
%              [T'
%               [T [\traceReference{verbe1}]]
%               [VP
%                [\traceReference{sujet1}]
%                [V' [V [\traceReference{verbe1}]]]
%               ]
%              ]
%             ]
%            ]
%           ]
% \end{verbatim}
% \synttree*[AgrP
%            [DP\traceLabel{sujet1} [.t Le chat]]
%            [Agr'
%             [Arg [dort\traceLabel{verbe1}]]
%             [TP
%              [T'
%               [T [\traceReference{verbe1}]]
%               [VP
%                [\traceReference{sujet1}]
%                [V' [V [\traceReference{verbe1}]]]
%               ]
%              ]
%             ]
%            ]
%           ]
% \subsection{One example with qtree}
% \syntraceaddresetmacro{Tree}
% \begin{verbatim}
% \Tree [.S [.NP subject\traceLabel{s1} ] [.VP [.V verb ] [.NP \traceReference{s1} ]]]
% \end{verbatim}
% \Tree [.S [.NP subject\traceLabel{s1} ] [.VP [.V verb ] [.NP \traceReference{s1} ]]]
% \section{Implementation}
%
% \begin{macro}{syntrace@startvalue}
% This counter define the start value of the trace numbering
%    \begin{macrocode}
\newcounter{syntrace@startvalue}
\setcounter{syntrace@startvalue}{0}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{syntrace@labelcounter}
% This counter count the trace
%    \begin{macrocode}
\newcounter{syntrace@labelcounter}
\setcounter{syntrace@labelcounter}{\arabic{syntrace@startvalue}}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\thesyntrace@labelcounter}
% This macro display the value of the trace counter
%    \begin{macrocode}
\renewcommand*{\thesyntrace@labelcounter}{%
    \alph{syntrace@labelcounter}%
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\syntrace@labelletter}
% This macro display the default letter for the trace
%    \begin{macrocode}
\newcommand*{\syntrace@labelletter}{%
    \ensuremath{t}%
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\syntrace@displaytrace}
% This macro display the value of a trace
%    \begin{macrocode}
\newcommand*{\syntrace@displaytrace}[1]{%
    \raisebox{-.5\height}{\scriptsize\mbox{#1}}%
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\traceLabel}
% This macro add a start trace
%    \begin{macrocode}
\newcommand*{\traceLabel}[1]{%
    \refstepcounter{syntrace@labelcounter}%
    \syntrace@displaytrace{\thesyntrace@labelcounter}%
    \label{syntrace-#1}%
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\traceLabel}
% This macro add a reference to a trace
%    \begin{macrocode}
\newcommand*{\traceReference}[1]{%
    \syntrace@labelletter\syntrace@displaytrace{\ref{syntrace-#1}}%
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\syntrace@reset}
% This macro reset the trace counter
%    \begin{macrocode}
\newcommand*{\syntrace@reset}{%
    \setcounter{syntrace@labelcounter}{\arabic{syntrace@startvalue}}%
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\syntraceaddresetmacro}
% This macro add autoreset to a command and add a starred version to this command that have the default functionnality
%    \begin{macrocode}
\newcommand*{\syntraceaddresetmacro}[1]{%
    \expandafter\ifx%
        \csname syntrace@old@#1\endcsname
        \relax%
        \PackageInfo{syntrace}{Adding auto-reset to #1}%
        \expandafter\let\csname syntrace@old@#1\expandafter\endcsname%
        \csname #1\endcsname%
        \expandafter\def\csname#1\endcsname{\@ifstar{%
                \csname syntrace@old@#1\endcsname%
            }{%
                \syntrace@reset%
                \csname syntrace@old@#1\endcsname%
            }%
        }%
    \else
        \PackageWarning{syntrace}{#1 allready set as auto-reset}%
    \fi
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\syntraceremoveresetmacro}
% This macro remove autoreset to a command
%    \begin{macrocode}
\newcommand*{\syntraceremoveresetmacro}[1]{%
    \expandafter\ifx%
        \csname syntrace@old@#1\endcsname
        \relax%
        \PackageWarning{syntrace}{#1 is not set as auto-reset}%
    \else
        \PackageInfo{syntrace}{Removing auto-reset from #1}%
        \expandafter\let\csname #1\expandafter\endcsname%
        \csname syntrace@old@#1\endcsname%
        \expandafter\let\csname syntrace@old@#1\expandafter\endcsname\relax%
    \fi
}
%    \end{macrocode}
% \end{macro}
% \Finale
\endinput