% Ceci est tabularcalc_doc_fr.tex, le manuel en français de tabularcalc % This is tabularcalc_doc_fr.tex, the french manual of tabularcalc % % Christian Tellechea 2009 % % email : unbonpetit@gmail.com %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % 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 (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. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \documentclass[a4paper,10pt]{article} \usepackage[utf8]{inputenc} \usepackage[T1]{fontenc} \usepackage[a4paper,dvips,colorlinks=true,hyperfootnotes=false,filecolor=black,linkcolor=blue,urlcolor=magenta,bookmarks=false,pdfauthor={Christian TELLECHEA},pdftitle={tabularcalc},pdfsubject={package for tables of values},pdfkeywords={tabularcalc},pdfcreator={LaTeX}]{hyperref} \usepackage[a4paper,dvips,margin=2.75cm]{geometry} \usepackage{amsmath} \usepackage[autolanguage]{numprint} \usepackage{colortbl} \usepackage{xcolor} \usepackage{lmodern} \usepackage{xspace} \usepackage{listings} \usepackage{fp} \usepackage{pgfmath} \usepackage{tabularcalc} \usepackage[frenchb,english]{babel} \makeatletter \definecolor{tc@bckgcolor}{rgb}{1,1,0.875} \definecolor{tc@keywordstc}{rgb}{0.7,0,0} \definecolor{tc@keywordslatex}{rgb}{0,0,1} \definecolor{tc@arguments}{rgb}{0,0,0} \definecolor{tc@comments}{rgb}{0.5,0.5,0.5} \lstset{% language=[AlLaTeX]TeX,% morekeywords={numexpr},% float=hbp,% basicstyle=\small\ttfamily,% identifierstyle=\color{tc@arguments},% keywordstyle=\color{tc@keywordslatex},% commentstyle=\itshape\color{tc@comments},% columns=fixed,% tabsize=4,% frame=single,% extendedchars=true,% showspaces=false,% showstringspaces=false,% numbers=left,% numberstyle=\tiny\ttfamily,% breaklines=true,% breakindent=3em,% backgroundcolor=\color{tc@bckgcolor},% breakautoindent=true,% captionpos=t,% xleftmargin=1em,% xrightmargin=1em,% lineskip=0pt,% numbersep=1em, classoffset=1,% morekeywords={% les macros et commandes de tabularcalc tccol,tclin,% htablecalc,vtablecalc,% noshowmark,startline,resetcellcode,edefcellcode,defcellcode,% sethrule,resethrule,setcoltype,resetcoltype,% printvalue,printresult,numberletter,listsep,% tc@evalexpr,tc@currentresult},% keywordstyle=\color{tc@keywordstc},% classoffset=0} \makeatother \newcommand\guill[1]{\og{}#1\fg{}} \newcommand\argu[1]{$\langle$\textit{#1}$\rangle$} \newcommand\ARGU[1]{\texttt{\color{black}\{}\argu{#1}\texttt{\color{black}\}}} \newcommand\arguC[1]{\texttt{\color{black}[}\argu{#1}\texttt{\color{black}]}} \newcommand\tbcalc{\textsf{tabularcalc}\xspace} \newcommand\verbinline{\lstinline[breaklines=false,basicstyle=\normalsize\ttfamily]} \newcommand\mywidth{0.75\linewidth} \begin{document} \selectlanguage{english} \npthousandthpartsep{\;} \setlength{\parindent}{0pt} \begin{titlepage} \null\par\vfill \begin{center} \begin{minipage}{0.75\linewidth} \begin{center} \Huge\bfseries \tbcalc\par\vspace{5pt} \small v\tabularcalcversion\par\vspace{25pt} \normalsize User's manual \end{center} \end{minipage} \end{center} \vspace{1cm} \begin{center} Christian {\sc Tellechea}\par\small \href{mailto:unbonpetit@gmail.com}{\texttt{\textbf{unbonpetit@gmail.com}}}\par\vspace{5pt} \tabularcalcenglishdate \end{center} \vfill\hrulefill \begin{center} \begin{minipage}{0.85\linewidth} \noindent \hfill\textbf{\textit{Abstract}}\hfill{}\medskip\par Given a list of numbers and one (or more) formulas, this package allows with an easy syntax to build a table of values, i.e a tables in which the first row contains the list of numbers, and the other rows contain the \emph{calculated} values of the formulas for each number of the list: \begin{center} \sethrule{\hline}{\hline\hline}{\hline} \def\printvalue#1{\IfInteger{#1}{\nprounddigits{0}}{}\numprint{#1}} \def\printresult#1#2{\IfInteger{#1}{\nprounddigits{0}}{}\numprint{#1}} \setcoltype{|c|}{>{\centering\arraybackslash}m{1.25cm}|} \htablecalc[3]{$x$}{-4,-2,0,2.25,7}{$f(x)=2x-3$}{2*x-3}{$x^2$}{x*x}{$h(x)=\sqrt{x^2+1}$}{sqrt(x*x+1)} \end{center} The table can be built either horizontally or vertically, and it is fully customizable (height of rows, columns and lines types). Moreover, the content of any cell can be easily hidden.\smallskip Other local effects are possible since a command allows to execute any code in any particular cell. \end{minipage} \end{center} \hrulefill\vfill{} \end{titlepage} \tableofcontents \bigskip \textbf{Attention}: this manual is the laboured\footnote{Indeed, I \textbf{do not speak english}, and I did my best to achieve this translation. Please, be indulgent, and try to take my place and imagine what it would be for you if you had to translate a manual into french, with some old poor school knowledge!} translation of the french manual. \section{Introduction} This package needs \LaTeX$2\varepsilon$, and if it has not been done before, loads the following packages: \href{http://www.ctan.org/tex-archive/graphics/pgf/base/latex/pgf/math/}{\texttt{\textbf{pgfmath}}}, \href{http://www.ctan.org/tex-archive/macros/latex/contrib/xstring/}{\texttt{\textbf{xstring}}} and \href{http://www.ctan.org/tex-archive/macros/latex/contrib/numprint/}{\texttt{\textbf{numprint}}}. It makes easily possible to build tables of calculated results coming from formulas for a given list of values. Tables are displayed using the standard \verb|tabular|\footnote{For the moment, the \texttt{tabular} environment is hard coded, but it will probably be possible in the next version to let the user choose another table environment: \texttt{tabularx}, \texttt{tabulary}, \texttt{supertabular}, etc.} environment. The package is called with the usual command \verbinline|\usepackage{tabularcalc}|\smallskip This package is not intended to compete with the excellent \href{http://www.ctan.org/tex-archive/graphics/pgf/contrib/pgfplots/}{\texttt{\textbf{pgfplotstable}}} package of Christian \textsc{Feuers\"anger} which has much more extended features, but in compensation, has a difficult to learn syntax. \tbcalc is meant to be more modest and gives priority to customization and easy syntax.\medskip For calculation, the computation of an arithmetic expression such as \verb|2*x*x-5*x+7| when \hbox{\verb|x = 2.7|} is with \TeX{}, a very complex thing that \tbcalc does not make. It leaves this task to a computation engine: "pgfmath" by default. This is why \href{http://www.ctan.org/tex-archive/graphics/pgf/base/latex/pgf/math/}{\texttt{\textbf{pgfmath}}} is loaded. It is possible to choose an other computation engine, see page~\pageref{changemoteurcalcul}.\smallskip To display decimal numbers, in my view, nothing is better than the \href{http://www.ctan.org/tex-archive/macros/latex/contrib/numprint/}{\texttt{\textbf{numprint}}} package. This is why it is loaded. The engine used to display decimal numbers can be changed or customized, see page~\pageref{persoaffichage}.\medskip To define vocabulary for later use, in the simple tables below, red numbers are the "{\color{red}values}", blue numbers are the "{\color{blue}results}" and brown texts are the "{\color{brown}labels}". The cell on the up-left corner is the "cell(0,0)": \begin{minipage}{0.5\linewidth} \begin{center} {\scriptsize Horizontal table}\par\nobreak\smallskip \def\printvalue#1{\color{red}$#1$} \def\printresult#1#2{\color{blue}\IfInteger{#1}{$\number\integerpart$}{$#1$}} \htablecalc[3]{cell (0,0)}{-5,-1,0,3,10}{\color{brown}$x$}{x}{\color{brown}$2x$}{2*x}{\color{brown}$3x$}{3*x} \end{center} \end{minipage}% \begin{minipage}{0.5\linewidth} \begin{center} {\scriptsize Vertical table}\par\nobreak\smallskip \def\printvalue#1{\color{red}$#1$} \def\printresult#1#2{\color{blue}\IfInteger{#1}{$\number\integerpart$}{$#1$}} \vtablecalc[3]{cell (0,0)}{-5,-1,0,3,10}{\color{brown}$x$}{x}{\color{brown}$2x$}{2*x}{\color{brown}$3x$}{3*x} \end{center} \end{minipage} \section{Basic features} \subsection{Horizontal tables} The macro \verbinline|\htablecalc| builds horizontal table whose first row contains the "values" and the other rows the "results". The syntax is:\smallskip \setbox0=\hbox{\verbinline|\htablecalc|\arguC{number}} \verbinline|\htablecalc|\arguC{number}\ARGU{cell (0,0)}\ARGU{value list}\par \hskip\wd0\ARGU{label 1}\ARGU{formula 1}\par \hskip\wd0\ARGU{label 2}\ARGU{formula 2}\par \hskip\wd0\ldots\par \hskip\wd0\ARGU{label n}\ARGU{formula n}\medskip where :\parindent1.5em \begin{itemize} \item \argu{number} is the number of formulas (1 by default); \item \argu{cell (0,0)} is the content of the cell (0,0); \item \argu{value list} is the list of values, separated with a comma. Two consecutive commas make an empty column; \item \argu{label i} is the i${}^\text{th}$ label; \item \argu{formula i} is the $i^\text{th}$ formula, used to calculate the reults of the $i^\text{th}$ row. In formulas, \verb|x| is the variable. \end{itemize}\parindent0em \medskip The variable "\verb|x|" is the expansion of \verbinline|\numberletter|, and at any moment, it is possible to redefine it to another letter, "\verb|y|" for example with a \verbinline|\def\numberletter{y}|.\smallskip In the list of values, a comma separate values by default. This comma is the expansion of \verbinline|\listsep|, and can be changed to "|" for example with \verbinline=\def\listsep{|}=\medskip For a first example, here is a try to obtain the table of the first page: \begin{center} \begin{minipage}{\mywidth} \begin{lstlisting} \htablecalc[3]{$x$}{-4,-2,0,2.25,7} {$f(x)=2x-3$}{2*x-3} {$x^2$}{x*x} {$h(x)=\sqrt{x^2+1}$}{sqrt(x*x+1)} \end{lstlisting} \smallskip \end{minipage} \htablecalc[3]{$x$}{-4,-2,0,2.25,7} {$f(x)=2x-3$}{2*x-3} {$x^2$}{x*x} {$h(x)=\sqrt{x^2+1}$}{sqrt(x*x+1)} \end{center} This table is not strictly the same than the table of the first page: integer results have a "0" as decimal part, columns containing results do not have the same width and the line at the bottom of the first row is different. \subsection{Vertical tables} The macro \verbinline|\vtablecalc| builds vertical table whose first column contains the "values" and the other rows the "results". The syntax is:\smallskip \setbox0=\hbox{\verbinline|\vtablecalc|\arguC{number}} \verbinline|\vtablecalc|\arguC{number}\ARGU{cell (0,0)}\ARGU{value list}\par \hskip\wd0\ARGU{label 1}\ARGU{formula 1}\par \hskip\wd0\ARGU{label 2}\ARGU{formula 2}\par \hskip\wd0\ldots\par \hskip\wd0\ARGU{label n}\ARGU{formula n}\medskip where :\parindent1.5em \begin{itemize} \item \argu{number} is the number of formulas (1 by default); \item \argu{value list} is the list of values, separated with a comma; \item \argu{label i} is the $i^\text{th}$ label; \item \argu{formula i} is the $i^\text{th}$ formula, used to calculate the reults of the $i^\text{th}$ column. \end{itemize}\parindent0em \medskip Here is the previous table, but vertically built:\par\nobreak \begin{center} \begin{minipage}{\mywidth} \begin{lstlisting} \vtablecalc[3]{$x$}{-4,-2,0,2.25,7} {$f(x)=2x-3$}{2*x-3} {$x^2$}{x*x} {$h(x)=\sqrt{x^2+1}$}{sqrt(x*x+1)} \end{lstlisting} \end{minipage} \smallskip \vtablecalc[3]{$x$}{-4,-2,0,2.25,7} {$f(x)=2x-3$}{2*x-3} {$x^2$}{x*x} {$h(x)=\sqrt{x^2+1}$}{sqrt(x*x+1)} \end{center} \subsection{How to hide numbers} The content of any cell can be hidden, as well as in a horizontal or vertical table. \subsubsection{Hide a value} In the list of values, a "\verb|@|" before a value hides it. In the following example, the second and fifth values are hidden:\smallskip \begin{center} \begin{minipage}{\mywidth} \begin{lstlisting} \htablecalc[3]{$x$}{-4,@-2,0,2.25,@7} {$f(x)=2x-3$}{2*x-3} {$x^2$}{x*x} {$h(x)=\sqrt{x^2+1}$}{sqrt(x*x+1)} \end{lstlisting} \end{minipage} \smallskip \htablecalc[3]{$x$}{-4,@-2,0,2.25,@7} {$f(x)=2x-3$}{2*x-3} {$x^2$}{x*x} {$h(x)=\sqrt{x^2+1}$}{sqrt(x*x+1)} \end{center} \medskip Behind the scene, the "\verb|@|" token is the expansion of \verbinline|\noshowmark|. To change this token to "=", this simple code does the job: \verbinline|\def\noshowmark{=}| \subsubsection{Hide a result} If a value is followed by $[a_1][a_2]\ldots[a_n]$ where the numbers $a_i$ are increasing, the results number $a_1,a_2,\ldots,a_n$ will be hidden. If a number $a_j=0$, all the others $a_k$ where $k>j$ will be ignored and the results following the previous hidden result will be hidden.\medskip In the example, with the list of values "\verb|-4[2],-2,0[1][3],2.25[0],7[2][0]|", we are going to:\parindent1.5em \begin{itemize} \item hide the second result of the first value with "\verb|-4[2]|" \item let all the results visible for the second value with "\verb|-2|" \item hide the results number 1 and 3 of the third value with "\verb|0[1][3]|" \item hide all the results of the fourth value with "\verb|2.25[0]|" \item for the fifth value, hide all the results from the second with "\verb|7[2][0]|" \end{itemize}\parindent0em \begin{center} \begin{minipage}{\mywidth} \begin{lstlisting} \htablecalc[3]{$x$}{-4[2],-2,0[1][3],2.25[0],7[2][0]} {$f(x)=2x-3$}{2*x-3} {$x^2$}{x*x} {$h(x)=\sqrt{x^2+1}$}{sqrt(x*x+1)} \end{lstlisting} \end{minipage} \smallskip \htablecalc[3]{$x$}{-4[2],-2,0[1][3],2.25[0],7[2][0]} {$f(x)=2x-3$}{2*x-3} {$x^2$}{x*x} {$h(x)=\sqrt{x^2+1}$}{sqrt(x*x+1)} \end{center} This feature can be mixed with "\verb|@|" to hide a value and results. \subsection{Height of rows} At the begining of a row, when it is displayed, the macro \verbinline|\startline| runs. By default, this command is defined by: \verbinline|\def\startline{\rule[-1.2ex]{0pt}{4ex}}|. Its expansion is a "strut" which adjusts the height of the row. Here is this strut, made visible before the lettre "a": \rule[-1.2ex]{2pt}{4ex}a\medskip Any other action, or another strut can be defined: \begin{center} \begin{minipage}{\mywidth} \begin{lstlisting} \def\startline{% {\bfseries\number\tclin)\ }% } \htablecalc[3]{$x$}{-4,-2,0,2.25,7} {$f(x)=2x-3$}{2*x-3} {$x^2$}{x*x} {$h(x)=\sqrt{x^2+1}$}{sqrt(x*x+1)} \end{lstlisting} \end{minipage} \smallskip \def\startline{% {\bfseries\number\tclin)\ }% } \htablecalc[3]{$x$}{-4,-2,0,2.25,7} {$f(x)=2x-3$}{2*x-3} {$x^2$}{x*x} {$h(x)=\sqrt{x^2+1}$}{sqrt(x*x+1)} \end{center} Here, no strut is defined (the lines recover their natural height), and at line 2 of the code, the number of the row (contained in the counter \verbinline|\tclin|) is displayed with bold chars. \subsection{Horizontal lines} \tbcalc allows to define 3 types of horizontal lines. The macro \verbinline|\sethrule| has 3 arguments: \parindent1.5em \begin{itemize} \item the first that we call "line 0" is displayed on the top and bottom of the table; \item the second, "line 1", is displayed at the bottom of the first row; \item the third, "other lines", is displayed at the bottom of the other rows, excepted the last one which is the bottom of the table. \end{itemize}\parindent0em Here is the syntax: \verbinline|\sethrule|\ARGU{line 0}\ARGU{line 1}\ARGU{other lines} \medskip By default, the three arguments contain \verbinline|\hline|.\medskip This is an example in which the "line 1" is a double line, and the "other lines" are not drawn: \begin{center} \begin{minipage}{\mywidth} \begin{lstlisting} \sethrule{\hline}{\hline\hline}{} \htablecalc[3]{$x$}{-2,-1,0,1,2,3} {$2x$}{2*x} {$3x$}{3*x} {$4x$}{4*x} \end{lstlisting} \end{minipage} \smallskip \sethrule{\hline}{\hline\hline}{} \htablecalc[3]{$x$}{-2,-1,0,1,2,3} {$2x$}{2*x} {$3x$}{3*x} {$4x$}{4*x} \end{center} The command \verbinline|\resethrule| resets the defined lines and restores the default lines. \subsection{Customizing columns} \subsubsection{Vertical lines} 2 types of column can be defined: the type of the left one and the type of others columns. The command \verbinline|\setcoltype| has an optionnal argument and 2 mandatory arguments: \begin{itemize} \item the optional argument, empty by default, defines the vertical lines at the right of the table; \item the "type 1" of the first column, set to "\verb-|c|-" by default; \item the "type 2" of the other colunms, set to "\verb-c|-" by default. \end{itemize}\medskip The syntax of the command is:\par\nobreak \verbinline|\setcoltype|\arguC{right lines}\ARGU{type 1}\ARGU{type 2}\medskip In this example, a double line is displayed at the right of the table (\verb=[||]=), and on the edges of the first column (\verb=||c||=). The other columns do not have vertical lines (\verb|c|): \begin{center} \begin{minipage}{\mywidth} \begin{lstlisting} \setcoltype[||]{||c||}{c} \htablecalc[3]{$x$}{-2,-1,0,1,2,3} {$2x$}{2*x} {$3x$}{3*x} {$4x$}{4*x} \end{lstlisting} \end{minipage} \smallskip \setcoltype[||]{||c||}{c} \htablecalc[3]{$x$}{-2,-1,0,1,2,3} {$2x$}{2*x} {$3x$}{3*x} {$4x$}{4*x} \end{center} \verbinline|\resetcoltype| restores the default vertical lines. \subsubsection{Width of columns} Instead of the usual column type "\verb|c|" used until now, other types of column can be specified: for example, the "\verb|m|" type of the \href{http://www.ctan.org/tex-archive/graphics/pgf/base/latex/pgf/basiclayer/}{\texttt{\textbf{array}}} package allows to set the width of columns this way: \verb|m{1.5cm}|.\medskip In this example, the first column is right aligned, and the other columns are centered and \numprint[cm]{1.5} width: \begin{center} \begin{minipage}{\mywidth} \begin{lstlisting} \usepackage{array} \setcoltype{|r|}{>{\centering\arraybackslash}m{1.5cm}|} \htablecalc[3]{$x$}{-4,-2,0,2.25,7} {$f(x)=2x-3$}{2*x-3} {$x^2$}{x*x} {$h(x)=\sqrt{x^2+1}$}{sqrt(x*x+1)} \end{lstlisting} \end{minipage} \smallskip \setcoltype{|r|}{>{\centering\arraybackslash}m{1.5cm}|} \htablecalc[3]{$x$}{-4,-2,0,2.25,7} {$f(x)=2x-3$}{2*x-3} {$x^2$}{x*x} {$h(x)=\sqrt{x^2+1}$}{sqrt(x*x+1)} \end{center} \section{Advanced customization} \subsection{How to execute a code in a cell} The command \verbinline|\defcellcode| allows to execute any code in a unique cell, or in every cells of a row or in every cells of a column. Cells have the following coordinates: \begin{center} \def\printvalue#1{}\def\printresult#1#2{} \edefcellcode{}{}{(\number\tclin,\number\tccol)} \htablecalc[3]{}{1,2,3,4,5}{}{}{}{}{}{} \end{center} \medskip Here is the syntax: \verbinline|\defcellcode|\ARGU{number 1}\ARGU{number 2}\ARGU{code} \smallskip where :\parindent1.5em \begin{itemize} \item \argu{number 1} is the first coordinate (row number); \item \argu{nombre 2} is the second coordinate (column number); \item \argu{code} is the code executed \emph{when the specified cell is displayed}; \item if \argu{number 1} is empty, all the rows are concerned; \item if \argu{nombre 2} is empty, all the columns are concerned; \end{itemize}\parindent0em \smallskip Behind the scene, the first coordinate --~the row number~-- is the counter \verbinline{\tclin}, and the number of the column is the counter \verbinline{\tccol}.\smallskip Notice that the code is expanded when the cell is displayed, and at that moment, the counter \verbinline|\tccol| does not contain anymore the column number of the cell: you should \textbf{not} use \verbinline|\tccol| in the code definied with the macro \verbinline|\defcellcode|. On the other hand, the counter \verbinline|\tclin| does contain the reliable number of the current line. If codes are defined with \verbinline|\defcellcode| and several of them are runned in the same cell, they will be executed in the same order of their definition.\medskip In this example, with the package \verb|xcolor|, the cell (2~,~3) is colored in blue, the row 1 in red and the column 4 in brown: \begin{center} \begin{minipage}{\mywidth} \begin{lstlisting} \usepackage{color} \defcellcode{2}{3}{\color{blue}} \defcellcode{1}{}{\color{red}} \defcellcode{}{4}{\color{brown}} \htablecalc[3]{$x$}{-2,-1,0,1,2,3} {$2x$}{2*x} {$3x$}{3*x} {$4x$}{4*x} \end{lstlisting} \end{minipage} \smallskip \defcellcode{2}{3}{\color{blue}} \defcellcode{1}{}{\color{red}} \defcellcode{}{4}{\color{brown}} \htablecalc[3]{$x$}{-2,-1,0,1,2,3} {$2x$}{2*x} {$3x$}{3*x} {$4x$}{4*x} \end{center} Notice that the cell (1~,~4) whose content is {\color{brown}\numprint{2.0}} has been colored in red (line 3 of the code) \emph{and then} in brown (line 4 of the code).\bigskip Another similar command is provided to execute code in a cell: \verbinline|\edefcellcode|. With this command, the code is expanded a first time with an \verbinline|\edef|\footnote{If a command must not be expanded at this time, a \texttt{\string\noexpand} must be put before it.} when cell is built: at this time, the counter \verbinline|\tccol| does contain the number of the column. Then, the expansion obtained is runned a second time when cell is displayed.\medskip In this example, text is blue if the column number is greater than 2: \begin{center} \begin{minipage}{\mywidth} \begin{lstlisting} \usepackage{color} \edefcellcode{}{}{% \ifnum\tccol>2 \noexpand\color{blue}\fi} \htablecalc[3]{$x$}{-2,-1,0,1,2,3} {$2x$}{2*x} {$3x$}{3*x} {$4x$}{4*x} \end{lstlisting} \end{minipage} \smallskip \edefcellcode{}{}{% \ifnum\tccol>2 \noexpand\color{blue}\fi} \htablecalc[3]{$x$}{-2,-1,0,1,2,3} {$2x$}{2*x} {$3x$}{3*x} {$4x$}{4*x} \end{center} \subsection{Customizing the number display} \subsubsection{Macros {\ttfamily\textbackslash printvalue} and {\ttfamily\textbackslash printresult}}\label{persoaffichage} To display a value, the macro \verbinline|\printvalue| is called. It requires one argument: the number to display which comes from \verb|pgfcalc|. This argument has a raw format: \verb|12345.6789| for "\numprint{12345.6789}". By default, \verbinline|\printvalue| is defined with this code:\par\nobreak\smallskip \hfill\verbinline|\def\printvalue#1{\numprint{#1}}|\hfill{} \smallskip Notice that the macro \verb|\numprint| is called to print the number.\bigskip To display a result, the macro \verbinline|\printresult| is called. It requires \textbf{two} arguments: the first is the number to display in raw format coming from \verb|pgfcalc| and the second is the value used to compute the result. By default, \verbinline|\printresult| is defined with this code:\par\nobreak\smallskip \hfill\verbinline|\def\printresult#1#2{\numprint{#1}}|\hfill{} \smallskip Notice that the argument \verb|#2| (the value) is ignored by \verbinline|\printresult|. But it is easy to imagine an example in which it would not be. In this example, a red "\verb|X|" is printed if the lenght of the square (which is argument \verb|#2|) is negative. If not, the result with the unit is printed. For the pleasure of customization, any result less than 10 is printed in blue:\par\nobreak \begin{center} \begin{minipage}{\mywidth} \begin{lstlisting} \usepackage{color} \def\printresult#1#2{% \ifdim#1pt<10pt\color{blue}\fi \ifdim#2pt<0pt \color{red}\texttt{X}% \else \numprint[cm^2]{#1}% \fi} \htablecalc{length}{0.7,-10,3,-2,5,12} {Area of square}{x*x} \end{lstlisting} \end{minipage} \smallskip \def\printresult#1#2{% \ifdim#1pt<10pt\color{blue}\fi \ifdim#2pt<0pt \color{red}\texttt{X}% \else \numprint[cm^2]{#1}% \fi} \htablecalc{length}{0.7,-10,3,-2,5,12}{Area of square}{x*x} \end{center} A remark: when the length is \numprint[cm]{0.7}, the result is slightly wrong. It should be \numprint[cm^2]{0.49} instead of \numprint[cm^2]{0.48999}! The \verb|pgfmath| package is not suitable for scientific computation as it is inteded to compute coordinates for drawing purposes. This is why its precision is $\frac{1}{\numprint{100000}}$ and sometimes leads to results including rounding errors such as this one. \subsubsection{How to control the rounding of numbers} With integer results, the \verb|pgfmath| package, though excellent, has a annoying drawback: when the result of the computation is an integer, the returned number has a decimal part "\verb|0|" (see table above). To avoid this, the result can be tested with \verb|\IfInteger| of \verb|xstring| package, and if it is an integer, give to \verb|\numprint| the value of the \verb|\integerpart| counter (see xtring donumentation): \begin{center} \begin{minipage}{\mywidth} \begin{lstlisting} \def\printresult#1#2{% \IfInteger{#1}% {\numprint{\number\integerpart}}% {\numprint{#1}}% } \htablecalc{$x$}{-3,1.56,2.5,3.608}{$2x$}{2*x} \end{lstlisting} \end{minipage} \smallskip \def\printresult#1#2{% \IfInteger{#1}% {\numprint{\number\integerpart}}% {\numprint{#1}}% } \htablecalc{$x$}{-3,1.56,2.5,3.608}{$2x$}{2*x} \end{center} It is also possible to force \verb|numprint| to round its argument with the command \verb|\nprounddigits| whose argument is the number of figures of the decimal part. Unfortunately, if needed, unnecessary \verb|0| are added to fill the decimal part to match the number of figures. \subsubsection{For the fun} Other uses of this package can be designed, such as the drawing of a chess board which squares are \numprint[cm]{0.5} long:\par\nobreak\parindent1.5em \begin{itemize} \item on line 2, the separators of the table are initialzes at \verb|0pt| to obtain the length of \numprint[cm]{0.5}; \item the display of values and results is cancelled at line 3; \item horizontal lines of the top and bottom of the table are drawn (line 4), and vertical lines of the left and right (line 5); \item a strut \numprint[cm]{0.5} height is defined to be displayed at the begining of every row (line 6); \item finally, if the sum of the row number and the column number is odd, the square is filled of gray (line 8 and 9). \end{itemize}\parindent0em \begin{center} \begin{minipage}{\mywidth} \begin{lstlisting} \usepackage{colortbl,xcolor} \arraycolsep=0pt\tabcolsep=0pt \def\printvalue#1{}\def\printresult#1#2{} \sethrule{\hline}{}{} \setcoltype[|]{|m{0.5cm}}{m{0.5cm}} \def\startline{\rule[-0.2cm]{0pt}{0.3cm}} \edefcellcode{}{}{% \ifodd\numexpr\tccol+\tclin\relax \noexpand\cellcolor{lightgray}\fi } \htablecalc[7]{}{ , , , , , , } {}{}{}{}{}{}{}{}{}{}{}{}{}{} \end{lstlisting} \end{minipage} \smallskip \arraycolsep=0pt\tabcolsep=0pt \def\printvalue#1{}\def\printresult#1#2{} \sethrule{\hline}{}{} \setcoltype[|]{|m{0.5cm}}{m{0.5cm}} \def\startline{\rule[-0.2cm]{0pt}{0.3cm}} \edefcellcode{}{}{% \ifodd\numexpr\tccol+\tclin\relax \noexpand\cellcolor{lightgray}\fi } \htablecalc[7]{}{ , , , , , , } {}{}{}{}{}{}{}{}{}{}{}{}{}{} \end{center} \section{How to change the computation engine}\label{changemoteurcalcul} \verb|pgfmath| is the computation engine used by default, but it can be changed though there is not many other choices: as far as I know, \href{http://www.ctan.org/tex-archive/macros/latex/contrib/fp/}{\texttt{\textbf{fp}}} and \href{http://www.ctan.org/tex-archive/macros/generic/xlop/}{\texttt{\textbf{xlop}}} are able to compute math expression under \LaTeX. Both have drawbacks, this is why they are not used by default:\par\nobreak\parindent1.5em \begin{itemize} \item "\verb|fp|" uses the Reverse Polish Notation (RPN). It is possible to use the infix notation but the opposite sign "${}-{}$" before a number is not accepted: very annoying for negative values! \item "\verb|xlop|" is not really a computation package as it also prints its results. And unfortunately, only arithmetic calculation is possible. \end{itemize}\parindent0em \medskip The macro \verbinline|\tc@evalexpr| is in charge of computation. It has no argument and it works like this: it expands \verbinline|\tc@currentresult| whose expansion is the math expression to compute (for example "\verb|4*2.5*2.5-3*2.5-7|"). It calls the computation engine to achieve the calculation (in this example, it would be \verb|10.5|), and finally it assigns this result to \verbinline|\tc@currentresult|. By default, the macro \verbinline|\tc@evalexpr| is defined with this code:\par\nobreak \begin{center} \begin{minipage}{\mywidth} \begin{lstlisting} \def\tc@evalexpr{% \expandafter\pgfmathparse \expandafter{\tc@currentresult}% \let\tc@currentresult\pgfmathresult} \end{lstlisting} \end{minipage} \end{center} Let us suppose we want to to use the \verb|fp| package for the computation. Let us redefine \verbinline|\tc@evalexpr|:\par\nobreak \begin{center} \begin{minipage}{\mywidth} \begin{lstlisting} \makeatletter \def\tc@evalexpr{% \expandafter\FPeval\expandafter \tc@currentresult\expandafter{\tc@currentresult}% \FPclip\tc@currentresult\tc@currentresult } \makeatother \end{lstlisting} \end{minipage} \end{center} The command \verb|\FPclip| removes unnecessary \verb|0| from the result (see \verb|fp| documentation). We have done it: the computation engine of \tbcalc is now \verb|fp|:\par\nobreak \begin{center} \begin{minipage}{\mywidth} \begin{lstlisting} \usepackage{fp} \htablecalc{$x$}{0.5,1,2.5,10} {$2x^2-\frac{1}{2}$}{2*x*x-0.5} \end{lstlisting} \end{minipage} \smallskip \makeatletter \def\tc@evalexpr{% \expandafter\FPeval\expandafter \tc@currentresult\expandafter{\tc@currentresult}% \FPclip\tc@currentresult\tc@currentresult } \makeatother \htablecalc{$x$}{0.5,1,2.5,10} {$2x^2-\frac{1}{2}$}{2*x*x-0.5} \end{center} An issue remains: as \verb|fp| does not understand the opposite "${}-{}$" sign before numbers, and a value like "\verb|-3|" would have provoked an error! To circumvent this, the RPN can be used, but \verbinline|\tc@evalexpr| must be modified to tell it that the computation has to be done using the RPN (this is why \verb|\FPupn| is used). Also, \verbinline|\printvalue| must be modified to make it compute with \verb|\FPupn| the values also written in RPN (\verb|3 neg| in the list of values instead of \verb|-3|):\par\nobreak \begin{center} \begin{minipage}{\mywidth} \begin{lstlisting} \usepackage{fp} \makeatletter \def\tc@evalexpr{% \expandafter\FPupn\expandafter \tc@currentresult\expandafter{\tc@currentresult}% \FPclip\tc@currentresult\tc@currentresult } \makeatother \def\printvalue#1{% \FPupn\tempval{#1}% \FPclip\tempval\tempval \numprint\tempval } \htablecalc{$x$}{3 neg,0.5,1,2.5,10} {$2x^2-\frac{1}{2}$}{x x mul 2 mul 0.5 sub} \end{lstlisting} \end{minipage} \makeatletter \def\tc@evalexpr{% \expandafter\FPupn\expandafter \tc@currentresult\expandafter{\tc@currentresult}% \FPclip\tc@currentresult\tc@currentresult } \makeatother \def\printvalue#1{% \FPupn\tempval{#1}% \FPclip\tempval\tempval \numprint\tempval } \htablecalc{$x$}{3 neg,0.5,1,2.5,10} {$2x^2-\frac{1}{2}$}{x x mul 2 mul 0.5 sub} \end{center} \bigskip\bigskip \begin{center} $\star$\par $\star$\quad$\star$ \end{center} \bigskip\bigskip That's all, I hope you will find this package useful!\par\nobreak Please, send me an \href{mailto:unbonpetit@gmail.com}{\texttt{\textbf{email}}} if you find a bug or if you have any idea of improvement\ldots\par\nobreak\medskip Christian \textsc{Tellechea} \end{document}