summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/source/latex/signchart/signchart.dtx
blob: a450128960df511e199a5c6c2d5642a92cd8cace (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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
% \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