% \iffalse meta-comment	
%<*internal>
\iffalse
%</internal>
%<*readme>
----------------------------------------------------------------
signchart --- v1.01 2016/02/12
E-mail: anthonywmottaz@gmail.com
Released under the LaTeX Project Public License v1.3c or later
See http://www.latex-project.org/lppl.txt
----------------------------------------------------------------

The signchart package provides you with the ability to create
beautifully typeset sign charts.

Refer to the documentation for usage instructions. Suggestions
for improvement can be sent to the email address above.

------------------ INSTALLATION INSTRUCTIONS -------------------
Copy the 'signchart.dtx' file to a temporary location, then
from a terminal run the following command twice:
	pdflatex signchart.dtx
Then we need to create the index. Run the command:
	makeindex -s gind.ist signchart
and then run pdflatex twice more.

Finally, you need to move the 'signchart.sty' to folders that
are searched by your TeX distribution.
----------------------------------------------------------------
%</readme>
%<*internal>
\fi
\def\nameofplainTeX{plain}
\ifx\fmtname\nameofplainTeX\else
  \expandafter\begingroup
\fi
%</internal>
%<*install>
\input docstrip.tex
\keepsilent
\askforoverwritefalse
\preamble
----------------------------------------------------------------
signchart --- Create beautiful sign charts.
E-mail: anthonywmottaz@gmail.com
Released under the LaTeX Project Public License v1.3c or later
See http://www.latex-project.org/lppl.txt
----------------------------------------------------------------

\endpreamble
\postamble

Copyright (C) 2016 by Anthony Mottaz <anthonywmottaz@gmail.com>

This work may be distributed and/or modified under the
conditions of the LaTeX Project Public License (LPPL), either
version 1.3c of this license or (at your option) any later
version. The latest version of this license is in the file:

http://www.latex-project.org/lppl.txt

This work is "maintained" (as per LPPL maintenance status) by
You.

This work consists of the file  signchart.dtx
and the derived files           signchart.ins,
                                signchart.pdf and
                                signchart.sty.

\endpostamble
\usedir{tex/latex/signchart}
\generate{
  \file{\jobname.sty}{\from{\jobname.dtx}{package}}
}
%</install>
%<install>\endbatchfile
%<*internal>
\usedir{source/latex/signchart}
\generate{
  \file{\jobname.ins}{\from{\jobname.dtx}{install}}
}
\nopreamble\nopostamble
\usedir{doc/latex/signchart}
\generate{
  \file{README.txt}{\from{\jobname.dtx}{readme}}
}
\ifx\fmtname\nameofplainTeX
  \expandafter\endbatchfile
\else
  \expandafter\endgroup
\fi
%</internal>
%<*package>
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{signchart}[2016/02/12 v1.01]
%</package>
%<*driver>
\documentclass{ltxdoc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{\jobname}
\usepackage[numbered]{hypdoc}
\usepackage{fancyvrb}
\usepackage{microtype}
\EnableCrossrefs
\CodelineIndex
\RecordChanges
\begin{document}
  \DocInput{\jobname.dtx}
\end{document}
%</driver>
% \fi
%
% \CheckSum{166}
% 
%\GetFileInfo{\jobname.sty}
%
%\DoNotIndex{\if,\fi,\else,\ifnum}
%\DoNotIndex{\begin,\end,\def,\let,\foreach,\i,\j,\k,\s}
%\DoNotIndex{\pgfmathsetmacro,\pgfmathtruncatemacro}
%\DoNotIndex{\pgfplotsset,\makeatletter,\makeatother}
%\DoNotIndex{\CurrentOption,\DeclareOption,\define@key}
%\DoNotIndex{\newcommand,\relax}
%
%\title{^^A
%   The \textsf{signchart} package\thanks{^^A
%    This file describes version \fileversion, last revised \filedate.^^A
%  }^^A
%}
%\author{^^A
%  Anthony Mottaz\thanks{E-mail: anthonywmottaz@gmail.com}^^A
%}
%\date{Released \filedate}
%
%\maketitle
%
%\abstract{The signchart package provides you with the ability to create
%beautifully typeset sign charts.}
%
%
%
%\section{Introduction}
%
%The \texttt{signchart} package provides the command 
%\begin{center}
%|\signchart|\oarg{options}\marg{values}\marg{signs}
%\end{center}
%for typesetting sign charts. For example,
%|\signchart{1,2,3}{+,-,+,-}| will produce
%\signchart{1,2,3}{+,-,+,-}
%This process is achieved using the \texttt{tikz} and \texttt{xstring}
%packages to extract the \meta{values} and \meta{signs} and place
%them on a number line.
%
%
%
%\section{Usage}
%\subsection{Load the package}
%
%Load the package:
%\begin{Verbatim}[gobble=1]
%    \usepackage\oarg{options}{signchart}
%\end{Verbatim}
%
%Currently, there are two options that can be called when loading the 
%|signchart| package.
%
%\DescribeMacro{signunder}
%Loading the package with this option will cause the signs to be placed below
%the sign chart. This is achieved by changing the default value of
%\texttt{height} to \texttt{$-0.3$}. \emph{(See macro options below)}
%
%\DescribeMacro{valunder}
%Loading the package with this option will cause the values to be placed below
%the sign chart. This is achieved by changing the default anchor position of
%the values from \texttt{south} to \texttt{north}. \emph{(See macro options
%below)}
%
%\subsection{Macros}
%
%\DescribeMacro{signchart}
%|\signchart|\oarg{optons}\marg{values}\marg{signs} \quad The |\signchart|
%command produces a signchart---a number line with evenly spaced ticks,
%with \meta{values} placed over each tick mark and \meta{signs} placed
%between each value.
%
%\DescribeMacro{\meta{values}}
%For the \meta{values} argument, the user should enter the values
%that will be placed above the tick marks in a comma separated list.
%
%\DescribeMacro{\meta{signs}}
%For the \meta{signs} argument, the user should enter the signs that will
%be placed between each of the \meta{values}, also in a comma separated list.
%\textbf{It is important to note} that the number of signs should be at most
%one more than the number of values. Any additional signs will be considered as
%one sign and give undesired results.
%
%\DescribeMacro{\oarg{options}}
%The width, placement of
%\meta{values} and \meta{signs}, and the arrows can be adjusted with
%\meta{options}.
%\DescribeMacro{width}
%The option \meta{width}=\meta{number} can be used to specify the width of
%the sign chart using the default \texttt{tikzpicture} units (cm). If no
%option is given, then \meta{width}\texttt{= 5} is used.
%
%\DescribeMacro{valanchor}
%This macro can change the anchor for placing the \meta{values}. By default,
%this is set to \texttt{south} in order to place the \meta{values} above the
%number line. The other possibility is to set \texttt{valanchor=north}.
%
%\DescribeMacro{valsep}
%This macro controls the separation distance from the \meta{values} to the 
%number line. By default, this is set to \texttt{3pt}. When the option 
%\texttt{valunder} is passed to the package, this is redefined to \texttt{13pt} 
%to achieve a similar distance underneath the number line.
%
%\DescribeMacro{height}
%The option \meta{height}=\meta{number} can be used to specify the distance
%between the number line and the signs using the default \texttt{tikzpicture}
%units (cm). If no option is given, then \meta{height}\texttt{= 0.3} is used.
%
%\DescribeMacro{arrows}
%The option \meta{arrows}=\meta{arrow style} can be used to specify the arrow
%head shape used on the number line. If no option is given, then
%\meta{arrows}\texttt{= <->} is used.
%
%\changes{v1.0}{2016/01/29}{First public release}
%\changes{v1.01}{2016/02/12}{Improved Documentation, addition of package 
%options}
%\StopEventually{^^A
%  \PrintChanges
%  \PrintIndex
%}
%
%\section{Implementation}
%
%    \begin{macrocode}
%<*package>
%    \end{macrocode}
%    
%
%    \begin{macrocode}
\RequirePackage{tikz}
\RequirePackage{pgfplots}
\pgfplotsset{compat = 1.10}
\RequirePackage{xstring}
\RequirePackage{xkeyval}
\def\signHeightKey{0.3}
\def\valNorthSouthKey{south}
\def\valSepKey{3pt}
\DeclareOption{signunder}{\def\signHeightKey{-0.3}}
\DeclareOption{valunder}{%
\def\valNorthSouthKey{north}%
\def\valSepKey{13pt}}
\DeclareOption*{%
\PackageWarning{signchart}{Unknown option ‘\CurrentOption’}%
}
\ProcessOptions\relax
\define@key{signchart}{height}[\signHeightKey]{\def\signHeight{#1}}
\define@key{signchart}{valanchor}[\valNorthSouthKey]{\def\valNorthSouth{#1}}
\define@key{signchart}{valsep}[\valSepKey]{\def\valSep{#1}}
\define@key{signchart}{width}[5]{\def\signChartWidth{#1}}
\define@key{signchart}{arrows}[<->]{\def\theArrow{#1}}
\makeatother
\newcommand{\signchart}[3][]{
\setkeys{signchart}{height, valanchor, valsep, width, arrows, #1}
\begin{center}
\begin{tikzpicture}
\pgfmathsetmacro{\snht}{\signHeight}
\pgfmathsetmacro{\wid}{\signChartWidth}
\def\vals{#2}
\def\signs{#3}
\def\valsarray{{\vals}}
\StrCount{\vals}{,}[\len]
\draw[\theArrow,thick] (0,0) -- (\wid,0);
\def\thisVal{-0}
\foreach \i in {0,...,\len} {
	\pgfmathtruncatemacro{\k}{\i + 1}
	\ifnum \i < \len
		\StrPosition[\k]{\vals}{,}[\pos]
		\StrBefore[\k]{\vals}{,}[\leftParti]
		\ifnum \i = 0
			\def\thisVal{\leftParti}
		\else
			\StrBehind[\i]{\leftParti}{,}[\thisVal]
		\fi
	\else
		\StrBehind[\i]{\vals}{,}[\thisVal]
	\fi
	\pgfmathtruncatemacro{\j}{\i + 1}
	\StrBehind[\j]{\signs}{,}[\rightPart]
	\StrLen{\rightPart}[\aLength]
	\pgfmathtruncatemacro{\cutAmount}{\aLength + 1}
	\StrGobbleRight{\signs}{\cutAmount}[\leftPartii]
	\StrBehind[\j]{,\leftPartii}{,}[\s]
	\pgfmathsetmacro{\valpos}{(\wid/(\len+2))*(\i+1)}
	\pgfmathsetmacro{\signpos}{(\wid/(\len+2))*(\i+0.5)}
	\draw (\valpos,-0.15) -- (\valpos,0.15) node[anchor=\valNorthSouth,
	    inner sep=\valSep] 
	{\thisVal};
	\node at (\signpos,\snht) {$\s$};
	\ifnum \i = \len
		\pgfmathsetmacro{\signpos}{(\wid/(\len+2))*(\len+1.5)}
		\pgfmathtruncatemacro{\j}{\len + 1}
		\StrBehind[\j]{\signs}{,}[\s]
		\node at (\signpos,\snht) {$\s$};
	\fi
	}
\end{tikzpicture}
\end{center}
}
%    \end{macrocode}
%
%
%    \begin{macrocode}
%</package>
%    \end{macrocode}
%\Finale
