summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/doc/latex/calctab/calctab_manual.tex
blob: 2a816b9ff3f32468fe4f48287cda69cd61e5fd4f (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
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
\documentclass[a4paper]{article}

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[left=32mm,
	right=45mm,
	top=32mm,
	bottom=28mm]{geometry}

\usepackage[english]{babel}

\usepackage{fancyhdr}
\usepackage{calctab}
\usepackage{microtype}
\usepackage{url}
\usepackage{fancyvrb}

% set the Verbatim environment
\fvset{numbers=left,numbersep=7pt}

% set page layout
\pagestyle{fancy}

% new command definition section
\newcommand{\ct}{\textsc{calctab}}
\newcommand{\pkg}[1]{\textsf{#1}}
\newcommand{\env}[1]{\textsf{#1}}
\newcommand{\cmd}[1]{\texttt{\char`\\#1}}
\newcommand{\meta}[1]{\ensuremath{\langle}\emph{#1}\ensuremath{\rangle}}
\newcommand{\graffe}[1]{\texttt{\{}\meta{#1}\texttt{\}}}
\newcommand{\quadre}[1]{\texttt{[}\meta{#1}\texttt{]}}

\author{Roberto Giacomelli\\e-mail: \texttt{giaconet at tin dot it}}
\date{2009/02/20}
\title{\ct{} package\\Experimental version\\0.5}

\begin{document}
\maketitle

\bigskip
\hspace*{238pt}\begin{minipage}{125pt}
\em
``The table compute the sum\\
not because is useful,\\
but because the result\\
is not an user essential data.''
\end{minipage}

\bigskip
\begin{center}
\begin{minipage}{96mm}%.8\textwidth
\tableofcontents
\end{minipage}
\end{center}


\bigskip
\section{Introduction}
The \pkg{calctab} package help the user to typeset a kind of economic table such as invoices, expense notes and liquidation, or other tabular material with a values column.

A normal \env{tabular} environment works well but force the user to write in a generic \LaTeX{} language without a conceptual relation among the economic items. In addition a lot of formatting command takes the same relevance of the document main data.

So, the priority is to add a new language element.

Economics items may be are independent values or not like sums and percentage on previous values. The language must be expressive concerning together data and its relations.

\section{ToDo}
I don't know if in the future this package will merge into another or became under further development. I hope in user discussion on the language issues and implementation too.

The code have a good level of stability, nevertheless the package is considered experimental because some essential tasks are in \emph{ToDo} status as result in the following list:

\begin{itemize}	
    \item write in good english the package documentation;
    \item internationalization of the table fixed description string;
    \item internationalization of the currency unit;
    \item inner commands language development;
    \item language development to manage the table view;
    \item \dots
\end{itemize}

The enthusiasm raised during GuITmeeting2008 in Pisa (Italy)\footnote{For information please visit the site \url{www.guit.sssup.it/guitmeeting/2008/2008.it.php}} by the talk \emph{``Una tabella che fa calcoli''} and the tip by Norbert Preining (Vienna University of Technology) to upload on CTAN the code in experimental section, finally persuade me to publish it.

Thanks GuITmeeting2008 people, thanks Norbert.

\section{User manual}
In this section will be explain the use of the environment \pkg{calctab}, first through several examples and later showing its formal syntax.

\subsection{\pkg{calctab} by examples}
\subsubsection{Simple table}
Well, starting with a simple case, consider a list of three entries with a final sum as showed in the next table:

\begin{calctab}
    \amount{First cost}{12500,9}
    \amount{Second cost}{8560,03}
    \amount{Third cost}{9200,45}
    \add{Final sum}
\end{calctab}

\bigskip

To mark items as independent value we can use the \verb=\amount= command, which needs two mandatory arguments: an item description text and its economic consistency.

In the last row, the \verb=\add= command have care to execute the sum of the previous amount, thus only a description text needs as input.

So, the user can typesetting the table with the \LaTeX{} source code show next. Obviously, the directive \verb=\usepackage{calctab}= must be present in the document preamble.

\begin{Verbatim}
\begin{calctab}
    \amount{First cost}{12500,9}
    \amount{Second cost}{8560,03}
    \amount{Third cost}{9200,45}
    \add{Final sum}
\end{calctab}
\end{Verbatim}

The behaviour of the inner commands is based on these rules:

\begin{itemize}
    \item Each command typeset one table row;
    \item the sequence of commands produce the sequence of the table row;
    \item \verb=\add= command sum all previous values (with exception to \verb=\add= values so).
\end{itemize}

The environment manages all the formatting elements of table as colored rows, rules, description entry row. The command execute calculation in floating point algorithm and adds description text (a list of uppercase letter to explicate the rows computed).
Also commands execute formatting task as numeric values printing, font family selection and more.

Potentially all of these \emph{visual} property could be adjust by the \pkg{calctab} user.

\subsubsection{Percentage}

Now we discuss the last inner command of the environment \pkg{calctab} named \verb=\perc= to compute a percentage.

In this second example we have only three items: an independent value, an its percentage, and the sum of all.

\begin{calctab}
    \amount{Building costruction}{560000}
    \perc{Tax}{10}
    \add{Total}
\end{calctab}

The \LaTeX{} code to produce the table is show here:

\begin{Verbatim}
\begin{calctab}
    \amount{Building costruction}{560000}
    \perc{Tax}{10}
    \add{Total}
\end{calctab}
\end{Verbatim}

The number of the second argument of \verb=\perc= command is interpreted as percentage value so not in absolute mode. This number may be negative with a max of two decimal digit (currently number are truncated at this point).


\subsubsection{Items relations}
If more complex tables require \emph{relational} information between rows is necessary to assign to it a names and recall these identifier in a list. This simply way can be achieved with the command optional argument.

A name can be assign to a table row by using the \texttt{id} key (a significance name improve code clarity).
The syntax is based to \meta{key} $=$ \meta{value} assignment, where key is fixed \texttt{id} string.
Later on, compute sum or percentage only on a subset of previous \pkg{calctab} items, can get recall in a comma separated list, the user row name.

The next example show the command optional argument at work.
For example, we want to apply a different discount on each expense or on each group of expense.

\begin{calctab}
    \amount[id=dinner]{Five dinner}{146}
    \amount[id=breakfast]{Five breakfast}{35}
    \perc[dinner]{Discount}{-8}
    \perc[breakfast]{Discount}{-4}
    \add{Grand total}
\end{calctab}

The next \LaTeX{} code show rows relation by name:

\begin{Verbatim}
\begin{calctab}
    \amount[id=dinner]{Five dinner}{146}
    \amount[id=breakfast]{Five breakfast}{35}
    \perc[dinner]{Discount}{-8}
    \perc[breakfast]{Discount}{-4}
    \add{Grand total}
\end{calctab}
\end{Verbatim}

\subsubsection{Sums in table}
In the table of the last example we will add a subtotal as the sum of discounts (and a short table description paragraph too):

\begin{calctab}[Hotel bill:\\
Period from 12 october 2008 to 18 october 2008 (room 456)]
    \amount[id=dinner]      {Five dinner}   {146}
    \amount[id=breakfast]   {Five breakfast}{35}
    \perc[id=dis8,dinner]   {Discount}      {-8}
    \perc[id=dis4,breakfast]{Discount}      {-4}
    \add[dis8,dis4]{Total of discount}
    \add{Grand total}
\end{calctab}

\bigskip
The table's \LaTeX{} code is this:

\begin{Verbatim}
\begin{calctab}[Hotel bill:\\
    Period from 12 october 2008 to 18 october 2008 (room 456)]
    \amount[id=dinner]      {Five dinner}   {146}
    \amount[id=breakfast]   {Five breakfast}{35}
    \perc[id=dis8,dinner]   {Discount}      {-8}
    \perc[id=dis4,breakfast]{Discount}      {-4}
    \add[dis8,dis4]{Total of discount}
    \add{Grand total}
\end{calctab}
\end{Verbatim}

As the reader can be notice, \emph{table description} is typeset as a paragraph having the same (variable) table width.

\subsubsection{Sum of the sum}

\begin{calctab}[Plant project Fee Note:\\
		Italian restaurant and pizzeria ``La Margherita'']
	\amount{Design of the air conditioned plant}{5400}
	\amount{Design of the electric plant and video surveillance}{8000}
	\perc{General expense}{8,55}
	\add[id=total]{Total amount of the design task}
	\perc{Tax}{2}
	\perc{VAT}{20}
	\perc[total]{Deduction}{-20}
	\add{Total}
\end{calctab}

In this table a 20\% deduction amount must be apply on the total of the first three values. A solution is to assign a name for each rows and write its list in optional argument of \cmd{perc} command. Nevertheless, this sum is just computed in previus row, thus we can assign a name only to this table row \texttt{\cmd{add}[id=total]\{Total amount of the design task\}}, and later recall the result and then apply percentage on it with the line \texttt{\cmd{perc}[total]\{Deduction\}\{-20\}}.
The complete code is show next:

\begin{Verbatim}
\begin{calctab}[Plant project Fee Note:\\
	Italian restaurant and pizzeria ``La Margherita'']
   \amount{Design of the air conditioned plant}{5400}
   \amount{Design of the electric plant and video surveillance}{8000}
   \perc{General expense}{8,55}
   \add[id=total]{Total amount of design task}
   \perc{Tax}{2}
   \perc{TVA}{20}
   \perc[total]{Deduction}{-20}
   \add{Total}
\end{calctab}
\end{Verbatim}

\subsubsection{Interval rows selection}
In some particular list of independent values the idea of interval selection is simply a consecutive group selection. So we only need to specify the first and the last element of the series.
If the first element is no explicit information its default is the element one, and similary, the last element of whole dataset became the default if a limit is no available.

The \ct{} commands \cmd{perc} and \cmd{add} support an interval selection with \texttt{from} and \texttt{until} keys that referenced row name. 

For example in this follow table the first five items and the last four are two separated group. 

\begin{calctab}[The interval selection table]
    \amount{One}  	  {100000000}
    \amount{Two}  	  {20000000}
    \amount{Three}	  {3000000}
    \amount{Four} 	  {400000}
    \amount[id=five]{Five}{50000}
    \amount[id=six]{Six}  {6000}
    \amount{Seven}        {700}
    \amount{Eight}        {80}
    \amount{Nine}         {9}
    \add[until=five]{From one to five}
    \add[from=six]{From six to nine}
    \add{As well as total}
\end{calctab}

The code needs to render this demo table is explain here:

\begin{Verbatim}
\begin{calctab}[The interval selection table]
    \amount          {One}{100000000}
    \amount          {Two}{20000000}
    \amount        {Three}{3000000}
    \amount         {Four}{400000}
    \amount[id=five]{Five}{50000}
    \amount[id=six]  {Six}{6000}
    \amount        {Seven}{700}
    \amount        {Eight}{80}
    \amount         {Nine}{9}
    \add[until=five]{From one to five}
    \add[from=six]{From six to nine}
    \add{As well as total}
\end{calctab}
\end{Verbatim}

Is possible to combine the keys \texttt{until} and \texttt{from} in the same optional argument to select a whole inner interval, and a row name list too.
In case of selection overlap, a package warning will be throws at compile time.

\subsection{Environment formal syntax}

The environment syntax will be described follow:

\medskip
\noindent\fbox{
	\parbox{220pt}{
		\noindent\cmd{begin}\texttt{\{calctab\}}\quadre{description paragraph}\smallskip

		\hspace*{5mm}\meta{calctab commands list}\smallskip

		\noindent\cmd{end}\texttt{\{calctab\}}
	}
}
\medskip

where \meta{calctab commands list} is a sequence of the internal commands:\medskip


\noindent\fbox{\cmd{amount}\texttt{[id=}\meta{rowID}\texttt{]}\graffe{descr}\graffe{value}}\medskip

\noindent\fbox{\cmd{perc}\texttt{[id=}\meta{rowID}\texttt{,from=}\meta{rowID}\texttt{,until=}\meta{rowID}\texttt{,}\meta{rowID~list}\texttt{]}\graffe{descr}\graffe{percentage}}\medskip

\noindent\fbox{\cmd{add}\texttt{[id=}\meta{rowID}\texttt{,from=}\meta{rowID}\texttt{,until=}\meta{rowID}\texttt{,}\meta{rowID~list}\texttt{]}\graffe{descr}}

\medskip
Please note that the \pkg{calctab} environment is based on the standard \LaTeX{} \env{tabular} environment, so you can manage \pkg{calctab} as a float object all-surrounding it with a \pkg{table} environment.

\subsection{Appearance commands (at the moment)}
The first row of the table typeset by \pkg{calctab} environment contains a pair of texts. The title of description column, that can be modify by the user with the command \cmd{ctdescription}, and the title of economic column that describe currency, set by the command \cmd{ctcurrency}. Default values are ``\texttt{Items description}'' and \cmd{euro}.

These command save the argument in defined internal macro, in the same way of the common \cmd{title} and \cmd{author} command of the \pkg{article} class. Insert these commands before the \pkg{calctab} environment to change it.

\bigskip
\noindent\fbox{\cmd{ctcurrency}\graffe{user text}}

\smallskip

\noindent\fbox{\cmd{ctdescription}\graffe{user text}}


\bigskip
An example show explicit assignment of the description text and currency unit:

\ctdescription{Your bill, thanks a lot.}
\ctcurrency{USD}

\begin{calctab}
    \amount[id=dinner]{Five dinner}{146}
    \amount[id=breakfast]{Five breakfast}{35}
    \perc[dinner]{Discount}{-8}
    \perc[breakfast]{Discount}{-4}
    \add{Grand total}
\end{calctab}

\begin{Verbatim}
\ctdescription{Your bill, thanks a lot.}
\ctcurrency{USD}

\begin{calctab}
    \amount[id=dinner]{Five dinner}{146}
    \amount[id=breakfast]{Five breakfast}{35}
    \perc[dinner]{Discount}{-8}
    \perc[breakfast]{Discount}{-4}
    \add{Grand total}
\end{calctab}
\end{Verbatim}

The default english text in percentage row can be change in the same way with the command \cmd{ctontranslation}.

\bigskip
\noindent\fbox{\cmd{ctontranslation}\graffe{on traslation}}

\subsection{Table width}
The width of the \ct{} table can be adjust via a standard \LaTeX{} length called \cmd{ctsep} (default value is 8mm). The horizontal space will be add to the central column of the table. The next line is an example:

\medskip
\texttt{\cmd{setlength}\{\cmd{ctsep}\}\{28pt\}}

\section{\ct{} idea}
The language efficacy is particularly important for the \LaTeX{} user. The \ct{} underline concept is to build an expressive language for the model -- view paradigm.

So one \emph{model} of structured data, can have more and more presentation \emph{view}. For example, a text with tabular structure can became a report or a graphic plot image.

\section{Package License}
This work may be distributed and/or modified under the
conditions of the \LaTeX{} Project Public License, either version 1.3
of this license or any later version.
The latest version of this license is in
\url{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.

\section{Thanks}
Thanks a lot to Professor Enrico Gregorio for help me to resolve some code problem: balance the table description paragraph width to the table variable width, save in a tokens registry the material of table so as over the implicit group barrier of tabular cell, and solve consequent \verb=\expandafter= \emph{jungle}.

Thanks a lot to the authors of packages used by \pkg{calctab}.

And finally, thanks to my family.

Every comment are welcome as well as any language discussion, so don't esitate to send to the author an e-mail message with your opinion, suggestion or desiderata. Thank you.
\end{document}