% \iffalse meta-comment
%<*internal>
\def\nameofplainTeX{plain}
\ifx\fmtname\nameofplainTeX\else
  \expandafter\begingroup
\fi
%</internal>
%<*install>
\input docstrip.tex
\keepsilent
\askforoverwritefalse
\preamble
Copyright (C) 2011 by Clemens Koppensteiner
-------------------------------------------

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 2005/12/01 or later.
\endpreamble
\generate{\file{tikzlibrarydecorations.tex-sx.code.tex} {\from{pgflibrarydecorations.tex-sx.dtx}{tikzlibrarydecorations.tex-sx}}}
\generate{\file{pgflibrarydecorations.tex-sx.code.tex}  {\from{pgflibrarydecorations.tex-sx.dtx}{pgflibrarydecorations}}}
%</install>
%<install>\endbatchfile
%<*internal>
\generate{
  \file{\jobname.ins}{\from{\jobname.dtx}{install}}
}
\ifx\fmtname\nameofplainTeX
  \expandafter\endbatchfile
\else
  \expandafter\endgroup
\fi
%</internal>
%<*driver>
\documentclass{ltxdoc}
\usepackage[T1]{fontenc}
\usepackage{csquotes}
\usepackage{lmodern}
\usepackage{tikz}
\usetikzlibrary{decorations.tex-sx}
\usepackage[margin=3cm]{geometry}
\usepackage[numbered]{hypdoc}
\EnableCrossrefs
\CodelineIndex
\RecordChanges
\begin{document}
  \DocInput{\jobname.dtx}
\end{document}
%</driver>
% \fi
%
% \title{TikZ/PGF decorations form TeX.SX --- version 0.1}
% \author{TeX.SX}
% \maketitle
% 
% \changes{v0.1}{2011/06/26}{The \texttt{middle} decoration}
%
% \section{Usage}
%
% The package is provided in form of a PGF library.
% It can be loaded with
%\begin{verbatim}
%\usetikzlibrary{decorations.tex-sx}
%\end{verbatim}
% or
%\begin{verbatim}
%\usepgflibrary{decorations.tex-sx}
%\end{verbatim}
% or the equivalent ConTeXt commands.
%
% \section{The \texttt{middle} decoration}
%
% Sometimes it is useful to be able to only display some part of the middle of
% a path. While it is possible with \texttt{shorten >} and \texttt{shorten <} to
% shorten a path, there is no direct way to specify the length of the 
% \emph{remaining} path. This was the content of the question
% \enquote{\href{http://tex.stackexchange.com/questions/18617/tikz-draw-only-a-certain-central-length-of-a-given-path}{draw only a certain central length of a given path}}.
% \DescribeMacro{middle}^^A
% In response, Clemens Koppensteiner wrote the \texttt{middle} decoration.
% This decoration only draws the middle part of a path with length given by
% \texttt{segment length}.
% \DescribeMacro{middle segment}^^A
% To set the \texttt{middle} decoration and the \texttt{segment length} value at
% the same time, one can use the \texttt{middle length} option, which takes the
% desired segment length as parameter.
%
% The decoration should correctly take TikZ drawing options into account.
% Unfortunately, arrows only work at the end of the segment, but not at the 
% start.
%\begin{verbatim}
%\begin{tikzpicture}[radius=2pt]   
%    \fill (0,0) circle;
%    \fill (4,0) circle;
%    \draw[middle segment=2cm,double,red,->] (0,0) to[out=30,in=150] (4,0);
%\end{tikzpicture}
%\end{verbatim}
%\begin{center}^^A
%\begin{tikzpicture}[radius=2pt]   
%    \fill (0,0) circle;
%    \fill (4,0) circle;
%    \draw[middle segment=2cm,double,red,->] (0,0) to[out=30,in=150] (4,0);
%\end{tikzpicture}^^A
%\end{center}
%
% \StopEventually{\PrintChanges}
% \section{Implementation}
%
% \subsection{\texttt{pgflibrary.decorations.tex-sx}}
%
% \iffalse
%<*pgflibrarydecorations>
% \fi
% 
%    \begin{macrocode}
\usepgfmodule{decorations}

%    \end{macrocode}
% \subsubsection{The \texttt{ignore} decoration}
% 
% \begin{macro}{ignore}
% The \texttt{ignore} decoration simply does nothing. In particular, it does
% \emph{not} contain a \texttt{move to} in the \texttt{final} part. This is 
% useful for meta decorations where the resulting path should be shorter than
% the input path.
%    \begin{macrocode}
\pgfdeclaredecoration{ignore}{final}
{
\state{final}{}
}

%    \end{macrocode}
% \end{macro}
%
% \subsubsection{The \texttt{middle} decoration}
%
% \begin{macro}{middle}
% The \texttt{middle} decoration only draws the \cs{pgfdecorationsegmentlength}
% of the path, centered in the middle. The \texttt{ignore} decoration is used
% in the \texttt{final} part, so that end arrow tips are placed correctly.
%    \begin{macrocode}
\pgfdeclaremetadecoration{middle}{initial}{
    \state{initial}[
        width={(\pgfmetadecoratedpathlength - \the\pgfdecorationsegmentlength)/2},
        next state=middle
    ]
    {\decoration{moveto}}

    \state{middle}[
        width={\the\pgfdecorationsegmentlength},
        next state=final
    ]
    {\decoration{curveto}}

    \state{final}
    {\decoration{ignore}}
}

%    \end{macrocode}
% \end{macro}
% \begin{macro}{middle segment}
% This ease-of-use option was suggested by Jake.
%    \begin{macrocode}
\tikzset{middle segment/.style={decoration={middle},decorate, segment length=#1}}
%    \end{macrocode}
% \end{macro}
% \iffalse
%</pgflibrarydecorations>
% \fi
%
% \subsection{\texttt{pgflibrary.decorations.tex-sx}}
%
% \iffalse
%<*tikzlibrarydecorations.tex-sx>
% \fi
% A simple wrapper so that \verb|\tikzlibrary{}| can be used.
%    \begin{macrocode}
\usetikzlibrary{decorations}
\usepgflibrary{decorations.tex-sx}

\endinput
%    \end{macrocode}
% \iffalse
%</tikzlibrarydecorations.tex-sx>
% \fi
% \Finale
