summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/signchart/signchart.sty
blob: 684abdf6fc4f15f495f217f6c6a7dea1f6b693fd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
%%
%% This is file `signchart.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% signchart.dtx  (with options: `package')
%% ----------------------------------------------------------------
%% 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
%% ----------------------------------------------------------------
%% 
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{signchart}[2016/02/12 v1.01]
\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}
}
%% 
%% 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.
%% 
%%
%% End of file `signchart.sty'.