From 6558da0729e1c500bec9acbfaa748066b84b02f4 Mon Sep 17 00:00:00 2001 From: Karl Berry Date: Wed, 27 Jan 2010 01:41:58 +0000 Subject: spreadtab 0.2 (25jan10) git-svn-id: svn://tug.org/texlive/trunk@16829 c570f23f-e606-0410-a88d-b1316a301751 --- .../doc/latex/spreadtab/spreadtab_doc_en.pdf | Bin 670143 -> 749468 bytes .../doc/latex/spreadtab/spreadtab_doc_en.tex | 326 ++++++- .../doc/latex/spreadtab/spreadtab_doc_fr.pdf | Bin 700145 -> 782814 bytes .../doc/latex/spreadtab/spreadtab_doc_fr.tex | 370 ++++++- .../doc/latex/spreadtab/spreadtab_doc_vn.pdf | Bin 711085 -> 0 bytes .../doc/latex/spreadtab/spreadtab_doc_vn.tex | 1013 -------------------- .../texmf-dist/tex/latex/spreadtab/spreadtab.sty | 559 +++++++++-- 7 files changed, 1104 insertions(+), 1164 deletions(-) delete mode 100644 Master/texmf-dist/doc/latex/spreadtab/spreadtab_doc_vn.pdf delete mode 100644 Master/texmf-dist/doc/latex/spreadtab/spreadtab_doc_vn.tex (limited to 'Master/texmf-dist') diff --git a/Master/texmf-dist/doc/latex/spreadtab/spreadtab_doc_en.pdf b/Master/texmf-dist/doc/latex/spreadtab/spreadtab_doc_en.pdf index 089f6ab0fe3..68e6187241c 100644 Binary files a/Master/texmf-dist/doc/latex/spreadtab/spreadtab_doc_en.pdf and b/Master/texmf-dist/doc/latex/spreadtab/spreadtab_doc_en.pdf differ diff --git a/Master/texmf-dist/doc/latex/spreadtab/spreadtab_doc_en.tex b/Master/texmf-dist/doc/latex/spreadtab/spreadtab_doc_en.tex index 1419c90311d..b8b47f59285 100644 --- a/Master/texmf-dist/doc/latex/spreadtab/spreadtab_doc_en.tex +++ b/Master/texmf-dist/doc/latex/spreadtab/spreadtab_doc_en.tex @@ -1,9 +1,9 @@ -% ____________________________________________________________________________ + % ____________________________________________________________________________ % | | % | | -% | spreadtab v0.1 | +% | spreadtab v0.2 | % | | -% | November 3 2009 | +% | January 24, 2010 | % | | % |___________________________________________________________________________| % @@ -30,8 +30,10 @@ \usepackage{lmodern} \usepackage[a4paper,margin=2.5cm]{geometry} \usepackage{amsmath,amssymb} +\usepackage{textcomp} \usepackage{array} -\usepackage{colortbl} +\usepackage[table]{xcolor} +\usepackage{arydshln} \usepackage{tabularx} \usepackage{xcolor} \usepackage{listings} @@ -39,15 +41,18 @@ \usepackage{xspace} \usepackage[bottom]{footmisc} \usepackage{spreadtab} +\usepackage[protrusion=true,final,verbose=true,babel=true]{microtype} \usepackage{fancyhdr} \fancyhead[L]{} \fancyhead[C]{\small\bfseries\ST} - \fancyhead[R]{\scriptsize\slshape\leftmark} - \fancyfoot[l]{\tiny\LaTeX'd by Christian \textsc{Tellechea}, \today.} + \fancyhead[R]{\scriptsize\slshape \leftmark} + \fancyfoot[l]{\tiny \LaTeX ed by Christian \textsc{Tellechea}, le \today.} \fancyfoot[c]{} \fancyfoot[r]{\thepage} -\usepackage[english]{babel} +\usepackage[frenchb]{babel} +\frenchbsetup{StandardLists=true} +\usepackage{enumitem} \makeatletter \definecolor{ST@bckgcolor}{rgb}{0.87,0.9,1} \definecolor{ST@codebckgcolor}{rgb}{0.9,0.9,0.9} @@ -64,19 +69,67 @@ captionpos=t,xleftmargin=1em,xrightmargin=1em,lineskip=0pt,% numbersep=1em,classoffset=1,% morekeywords={% les macros et commandes de spreadtab - spreadtab,SThiderow,SThidecol,STsavecell,STautoround,STmessage,% - STnumericfieldmarker,STtextcell,fact,ifeq,ifgt,iflt,numtofrshortdate,% + spreadtab,SThiderow,SThidecol,STsavecell,STautoround,STmessage,STsetdecimalsep,STtransposecar,STdebug,STdisplaytab,% + STnumericfieldmarker,STtextcell,STcopy,fact,ifeq,ifgt,iflt,numtofrshortdate,% numtoengshortdate,numtofrlongdate,numtoenglongdate,numtofrmonth,% numtoengmonth,numtofrday,numtoengday,sum,rand,randint,sumprod,% frshortdatetonum,engshortdatetonum,englongdatetonum,frlongdatetonum},% keywordstyle=\color{ST@keywordstc},classoffset=0} + + +%%%%%%%%%%% environnement OOcalc +\newcount\cntlin +\newcount\cntcol + +\newtoks\t@b +\long\def\ifremain@lines#1\\#2\@nil{% + \csname @\ifx\@empty#2\@empty second\else first\fi oftwo\endcsname} +\long\def\subst@eol#1\\#2\@nil{\addtot@b{#1\\\cline{1-1}\hdashline}% + \ifremain@lines#2\\\@nil{\addtot@b&\subst@eol#2\@nil}{\addtot@b{#2\end{tabular}}}} +\long\def\collect@body#1\end{\subst@eol#1\@nil\end} + +\newcommand\addtot@b[1]{\t@b\expandafter{\the\t@b#1}} +\newcommand\edftot@b[1]{\edef\temp@{#1}\expandafter\addtot@b\expandafter{\temp@}} + +\newenvironment{OOocalc}[2][1.5cm]{% #1=largeur colonnes #2 = nombre de colonnes + \newcolumntype w{>{\centering\arraybackslash}m{#1}}% + \arrayrulewidth0.4pt\dashlinedash0.4pt\relax\dashlinegap3pt + \global\cntlin\m@ne\global\cntcol\z@ + \tabfont + \tabcolsep0pt + \t@b{\begin{tabular}{% + |>{\cellcolor{tabheadcolor}% + \global\cntcol\z@\global\advance\cntlin\@ne + \centering\arraybackslash + \ifnum\cntlin>\z@\tableheadformat\number\cntlin\fi} + m{2em}|*{#2}{w:}}% + \hline + \rowcolor{tabheadcolor}}% + \loop + \ifnum\cntcol<#2 + \advance\cntcol\@ne + \addtot@b{&\multicolumn{1}{>\centering m{#1}|}}% + \edftot@b{{\noexpand\tableheadformat\@Alph\cntcol}}% + \repeat + \addtot@b{\\\hline&}% + \collect@body}{\the\t@b} \makeatother -\newcommand\verbinline{\lstinline[breaklines=false,basicstyle=\normalsize\ttfamily]} +% commandes de personnalisation de OOcalc +\newcommand*\tabfont{\fontfamily{phv}\selectfont\footnotesize}% police du tableau (helvetica ici) +\newcommand*\tableheadformat{\bfseries}% police des en-têtes du tableau (en gras) +\colorlet{tabheadcolor}{gray!40}% couleur de font des en-têtes du tableau +\colorlet{palepink}{pink!80} +\colorlet{lightpink}{pink!30} +\colorlet{palegreen}{green!60} +\colorlet{lightgreen}{green!30} +\newcommand\CC[1]{\cellcolor{#1}} + +\newcommand\verbinline[1][]{\lstinline[breaklines=false,basicstyle=\normalsize\ttfamily,#1]} \newcommand\ST{\textsf{spreadtab}\xspace} \newcommand\falseverb[1]{\texttt{\detokenize{#1}}} -\usepackage[a4paper,bookmarks=true,bookmarksopen=true,colorlinks=true,hyperfootnotes=false,filecolor=black,linkcolor=blue,urlcolor=magenta,pdfauthor={Christian TELLECHEA},pdftitle={spreadtab},pdfsubject={Spreadtab provides spreadsheet features for LaTeX table environments},pdfkeywords={spreadtab},pdfcreator={LaTeX}]{hyperref} +\usepackage[bookmarks=true,bookmarksopen=true,colorlinks=true,hyperfootnotes=false,filecolor=black,linkcolor=blue,urlcolor=magenta,pdfauthor={Christian TELLECHEA},pdftitle={spreadtab},pdfsubject={Spreadtab provides spreadsheet features for LaTeX table environments},pdfkeywords={spreadtab},pdfcreator={LaTeX}]{hyperref} \begin{document} \parindent0pt\pagestyle{fancy} @@ -111,7 +164,7 @@ \end{titlepage} \tableofcontents\newpage -\parskip\medskipamount +\parskip\medskipamount This manual is a translation of the french manual. I apologize for my poor english but I did my best\footnote{Any help to improve this translation is welcome!}, and I hope that the following is comprehensible! \section{Introduction} \subsection{Presentation} This package allows us to construct tables in a manner similar to a spreadsheet. The cells of a table have row and column indices and these can be used in formulas to generate values in other cells. @@ -140,14 +193,12 @@ after the work of \ST, we get a display as if we had written: \end{lstlisting} Although having features resembling those of a spreadsheet with \LaTeX{} is appreciable, the 3 stages described above take time, and above all, \verb-fp- is slow in its calculations. The \ST environment leads to \emph{much slower compilation} than with a classical table. -Moreover, \ST \emph{cannot stand in for a spreadsheet program}. Indeed, it has very few features, and it does not provide visual assistance. This point may cause difficulty\footnote{I certify that, with the use, this discomfort tends to disappear (if you do not work with huge tables, of course).} for big or complex tables. The syntax of \ST is also another difficulty. In fact, the advantage of this package is that it makes possible to write \emph{in the \LaTeX{} code} tables invloving calculation when these tables are usually exported\footnote{I mention the main two exportation programs: \href{http://calc2latex.sourceforge.net/}{\texttt{\textbf{cacl2latex}}} for `calc' (Open Office), and \href{http://www.ctan.org/tex-archive/support/excel2latex/}{\texttt{\textbf{excel2latex}}} for `excel' (Microsoft Office).} from a spreadsheet program to \LaTeX{} code. Consequently, it becomes possible to avoid the disadvantages of the exportation programs: fine tuning often necessary to obtain exactly what you want, exported tables containing the values only (formulas are lost when exportation is done), no compatibility with all types of environments, exportation must be started again if a single number or formulas is modified in the table. +Moreover, \ST \emph{cannot stand in for a spreadsheet program}. Indeed, it has very few features, and it does not provide visual assistance. This point may cause difficulty\footnote{I certify that, with the use, this discomfort tends to disappear (if you do not work with huge tables, of course).} for big or complex tables. The syntax of \ST is also another difficulty. In fact, the advantage of this package is that it makes possible to write \emph{in the \LaTeX{} code} tables invloving calculation when these tables are usually exported\footnote{I mention the two main exportation programs: \href{http://calc2latex.sourceforge.net/}{\texttt{\textbf{cacl2latex}}} for `calc' (Open Office), and \href{http://www.ctan.org/tex-archive/support/excel2latex/}{\texttt{\textbf{excel2latex}}} for `excel' (Microsoft Office).} from a spreadsheet program to \LaTeX{} code. Consequently, it becomes possible to avoid the disadvantages of the exportation programs: fine tuning often necessary to obtain exactly what you want, exported tables containing the values only (formulas are lost when exportation is done), no compatibility with all types of environments, exportation must be started again if a single number or formulas is modified in the table. \subsection{Motivation} A few months before I started to write this package, Derek \textsc{O'Connor} had pointed out that nothing was available in the world of \LaTeX{} packages to imitate --~even a little~-- the behaviour of spreadsheet programs. I found the challenge interesting and I started writing in this package which is only a good programming exercise. -Indeed, the main algorithm contained in \ST that determines the order in which the cells must be calculated is quite general and not specific to \LaTeX. Other \LaTeX{} oriented algorithms analyze cells and formulas to find references to other cells. The exercise is interesting because for programming, \TeX{} does not provide anything resembling a pointer, useful to build linked lists of cells to calculate. Nothing is available either to attach to a `variable' `chils fields' which you can choose the type. - -The road was long before reaching this first version and I especially want to thank Christophe \textsc{Casseau} for his early interest and for the suggestions he made, and more recently Derek \textsc{O'Connor} for his advice and for the constructive discussions we have had. I also thank Huu Dien Khue~\textsc{Le} for the Vietnamese translation of this manual. +The road was long before reaching this version and I especially want to thank Christophe \textsc{Casseau} for his early interest and for the suggestions he made, and more recently Derek \textsc{O'Connor} for his advice and for the constructive discussions we have had. I also thank Huu Dien Khue~\textsc{Le} for the Vietnamese translation of this manual. \section{Basic features} A table is a rectangular array of cells which may be viewed as a set cells arranged in horizontal rows or vertical columns. @@ -158,8 +209,12 @@ A table cell is identified by the pair \falseverb{}\footnote{No \item \verb|| is a letter from \falseverb a to \falseverb z, and \falseverb a is the first column on the left: it is limited to 26 columns, which should be sufficient for the majority of cases; the letter can be upper or lowercase; \item \verb|| is a positive integer representing row number. The row number 1 is the top row. \end{itemize} -Here are examples of absolutes references: \falseverb{b4} or \falseverb{C1} or \falseverb{d13}. - +Here are examples of absolutes references: \falseverb{b4} or \falseverb{C1} or \falseverb{d13}. Locations of cells appear clearly in the spreadsheet-like table below: +\begin{center} +\begin{OOocalc}[6em]{5} +&&&&\\&&&&\\&&&&\\&&&&\\&&&&\\ +\end{OOocalc} +\end{center} This example calculates the sum each row and each column and then calculates the grand total:\par\nobreak \begin{minipage}{0.75\linewidth} \begin{lstlisting} @@ -288,17 +343,128 @@ value 1 : :={50} & value 2 : :={29} & average : \textbf{:={(a1+b1)/2}}\\\hline value 1 : :={50} & value 2 : :={29} & average : \textbf{:={(a1+b1)/2}}\\\hline \end{spreadtab} \end{center} -If '\verb-:=-` has an empty argument like this '\verb-:={}-`, then the cell is understood as a text cell. It is a synonym of '\falseverb{@}`. +If '\verb-:=-` is written in a cell with an empty argument like this '\verb-:={}-`, then the cell is understood as a text cell. In fact, '\verb-:={}-` behaves like '\verb-@-', but they are \emph{not} equivalent: '\verb-:={}-` allows the cell to receive a formula from an other with \verbinline-\STcopy- (see next chapter) while it is impossible with '\verb-@-'. + +\subsection{Copy a formula} +To avoid having to copy formulas into adjacent cells, the \ST package provides the \verbinline-\STcopy- command. + +This command must be written in a cell with this syntax: +\begin{center} +\verbinline-\STcopy{>-$x$\verbinline-,v-$y$\verbinline-}{formula}- +\end{center} +where $x$ and $y$ are positive numbers that represent horizontal and vertical offsets relative to the cell where the command is. With the cell containing the command (the source cell), these offsets define a range of cells which will receive the \verb- -\footnote{The copy can not be done to cells located on the right and below the cell is located in the macro.}. The command \verbinline-\STcopy- must \emph{not} be in a cell where there is a numeric field marker "\verb-:=-". + +Here is how the copy is made: it starts from the cell where the command \verbinline-\STcopy- is. For the other cells, all the coordinates in the formula are modified taking into account the offsets from the source cell. For example, if the source cell contains the formula \verb-a1+b2+c3-, and the taget cell is located 2 columns rightwards and 5 rows below then, this formula becomes: \verb-c6+d7+e8-. The formula can also contain relative references but, since they are relative, they are not modified. + +Preceded by "\verb-!-", a coordinate in a formula is not modified when the formula is copied. For example, if the source cell contains \verb-a!1+!b2+!c!3- and the target cell is located 2 columns rightwards and 5 rows below then, this formula becomes: \verb-c1+b7+c3-. The feature is compatible with relative coordinates. Let's suppose a cell contains this formula: \verb|[-1,!-1]+[!-1,1]+[!1,!2]|. As usualy, let's say that this formula is copied to the cell located 2 columns rightwards and 5 rows below: this formula becomes: \verb|[-1,-6]+[-3,1]+[-1,-3]|. + +The "\verb-!-" char is the expansion of the control sequence \verbinline-\STtransposecar-. It may be changed to any other with \verbinline-\renewcommand\STtransposecar-\verb-{}-. The "\verb-!-" char, used by default, keeps its 13 catcode and remains active if the \verb-babel- package is loaded with the \verb-frenchb- option. + +In "\verbinline-\STcopy{>-$x$\verbinline-,v-$y$\verbinline-}{formula}-", if $x$ is omitted, the copie is made to the cells rightwards, up to the right edge of the table. With $y$, it is the same: if this number is omitted, the copy is done to the cells below until the bottom of the table is reached. If $x$ or $y$ are equal to 0, the copy is limited to the column or row of the source cell. Instead of writing \verb-v0- ou \verb->0-, it is possible to write \verb-v- ou \verb->-. + +Here are some examples: +\begin{tabular}{cl}\hline +\verb-{>3,v1}- & copy to 3 columns rightwards and 1 row below\\ +\verb-{>3}- & copy to 3 cells on the right\\ +\verb-{v1}- & copy to the cell below\\ +\verb-{>}- & copy rightwards up to the right edge\\ +\verb-{v}- & copy below\\ +\verb-{v,>}- & copy to the right and below until the end of the table\\\hline +\end{tabular} + +It is easy to generate the multiplication table from 1 to 10: + +\begin{lstlisting} +\begin{spreadtab}{{tabular}{|c|*{10}{c}|}} +\hline +@$\times$ & 1 & \STcopy{>}{b1+1} & & & & & & & & \\\hline +1 & \STcopy{>,v}{!a2*b!1} & & & & & & & & & \\ +\STcopy{v}{a2+1} & & & & & & & & & & \\ + & & & & & & & & & & \\ + & & & & & & & & & & \\ + & & & & & & & & & & \\ + & & & & & & & & & & \\ + & & & & & & & & & & \\ + & & & & & & & & & & \\ + & & & & & & & & & & \\ + & & & & & & & & & & \\\hline +\end{spreadtab} +\end{lstlisting} +\begin{center} +\begin{spreadtab}{{tabular}{|c|*{10}{c}|}} +\hline +@$\times$ & 1 & \STcopy{>}{b1+1} & & & & & & & & \\\hline +1 & \STcopy{>,v}{!a2*b!1} & & & & & & & & & \\ +\STcopy{v}{a2+1} & & & & & & & & & & \\ + & & & & & & & & & & \\ + & & & & & & & & & & \\ + & & & & & & & & & & \\ + & & & & & & & & & & \\ + & & & & & & & & & & \\ + & & & & & & & & & & \\ + & & & & & & & & & & \\ + & & & & & & & & & & \\\hline +\end{spreadtab} +\end{center} + +If the numeric field of a target cell is not empty, it is not replaced and the copy is not done for this cell. + +If 2 or more \verbinline-\STcopy- command in several source cells have the same taget cell, then, the formula this latter receive is the one contained in the last \verbinline-\STcopy- command when the table is read from top left to botton right. In the spreadsheet-like example below, the \verbinline-\STcopy- in the pink cell \falseverb{B1} has its target range partially covered by the one of the green cell \falseverb{C3}. +\begin{center} +\begin{OOocalc}[2.3cm]{6} +1 &\CC{palepink}\ttfamily\textbackslash STcopy \{v,>\}\{!a1+1\} &\CC{lightpink} &\CC{lightpink} &\CC{lightpink} &\CC{lightpink} \\ +2 &\CC{lightpink} &\CC{lightpink} &\CC{lightpink} &\CC{lightpink} &\CC{lightpink} ~\par~ \\ +3 &\CC{lightpink} &\CC{palegreen}\ttfamily\textbackslash STcopy \{>2,v1\}\{!a3*10\}&\CC{lightgreen} &\CC{lightgreen} &\CC{lightpink} \\ +4 &\CC{lightpink} &\CC{lightgreen} &\CC{lightgreen} &\CC{lightgreen} &\CC{lightpink}~\par~ \\ +5 &\CC{lightpink} &\CC{lightpink} &\CC{lightpink} &\CC{lightpink} &\CC{lightpink}~\par~ \\ +\end{OOocalc} +\end{center} +Here is this example, treated by \ST below. In this table, the cell \verb-b5- (numeric field alone) and the cell \verb-c5- (text field + numeric field) stay un changed since their numeric field are not empty: +\begin{lstlisting} +\begin{spreadtab}{{tabular}{|*6{c|}}}\hline +1 &\STcopy{v,>}{!a1+1} & & & & \\\hline +2 & & & & & \\\hline +3 & & \STcopy{>2,v1}{!a3*10} & & & \\\hline +4 & & & & & \\\hline +5 & -1 & a:={0}b & & & \\\hline +\end{spreadtab} +\end{lstlisting} +\begin{center} +\begin{spreadtab}{{tabular}{|*6{c|}}}\hline +1 &\STcopy{v,>}{!a1+1} & & & & \\\hline +2 & & & & & \\\hline +3 & & \STcopy{>2,v1}{!a3*10} & & & \\\hline +4 & & & & & \\\hline +5 & -1 & a:={0}b & & & \\\hline +\end{spreadtab} +\end{center} +As mentioned in the last chapter, you can also copy a formula in a text cell containing an empty numeric field (that is to say a cell containing ``\verb-:={}-''). In this case, the formula is copied inside the brackets. On the other side, a cell containing text ``\verb-@-'' can not receive a formula when copying is not done and the cell remains purely textual. + +Example : +\begin{lstlisting} +\begin{spreadtab}{{tabular}{|*6{c|}}}\hline +1 & 2 & 3 & 4 & 5 & 6 \\\hline +X\STcopy{>}{a1+1}Y & @XY & X:={}Y & \textbf{:={}} & & \\\hline +\end{spreadtab} +\end{lstlisting} +\begin{center} +\begin{spreadtab}{{tabular}{|*6{c|}}}\hline +1 & 2 & 3 & 4 & 5 & 6 \\\hline +X\STcopy{>}{a1+1}Y & @XY & X:={}Y & \textbf{:={}} & & \\\hline +\end{spreadtab} +\end{center} \section{Features for formatting the table} \subsection{End of lines and horizontal rules} -\ST recognizes the usual line breaks and horizontal rules \verb|\\| and \verb|\hline|. Also, it may use the optional argument in line break: \verb-\\[]-. +\ST recognizes the usual line breaks and horizontal rules \verb|\\| and \verb|\hline|. It is also possible to specify the optional argument in line break: \verb-\\[]-. For horizontal rule, it is possible to use:\par\nobreak \begin{itemize} \item \verb-\hline-; \item \verb=\cline{x-y}= where \falseverb x and \falseverb y define the start and the end of the rule; \item \verb=\hhline{}= where \verb== is the type of rule (read the manual of the \href{http://www.ctan.org/tex-archive/macros/latex/required/tools/}{\texttt{\textbf{hhline}}} package). + \item any command of the \href{http://www.ctan.org/tex-archive/macros/latex/contrib/booktabs/}{\texttt{\textbf{booktabs}}} package: \verb-\toprule-, \verb-\midrule-, \verb-\bottomrule-, \verb-\cmidrule-, \verb-\addlinespace-, \verb-\morecmidrule- and \verb-\specialrule-. All the arguments of these macros, optional or mandatory are taken into account; + \item \verbinline-\noalign- and its mandatory argument can be written after \verb-\\-. \end{itemize} Example: \begin{lstlisting} @@ -465,6 +631,66 @@ In this example, floating point numbers are rounded to 6 digits:\par\nobreak \end{spreadtab} \end{center} +\subsection{Decimal seprarator} +The \verb-fp- return its results with the decimal point separator. After the job of \verb-fp-, \ST can change this decimal separator: everything happens as if the results returned by \verb-fp- were taking this into account. The command \verbinline-\STsetdecimalsep- take a mandatory argument which is the char used as decimal separator: +\begin{center} +\verbinline-\STsetdecimalsep-\verb-{{$}r<{$}}|}}\hline +@x & @y & @\text{Moyenne}\\\hline +5 & -4 & (a2+b2)/2\\ +-6.1 & -8 & (a3+b3)/2\\ +9.85 & 3.7 & (a4+b4)/2\\\hline +\end{spreadtab}\par\smallskip +\STsetdecimalsep{{,}} +\begin{spreadtab}{{tabular}{|*3{>{$}r<{$}}|}}\hline +@x & @y & @\text{Moyenne}\\\hline +5 & -4 & (a2+b2)/2\\ +-6.1 & -8 & (a3+b3)/2\\ +9.85 & 3.7 & (a4+b4)/2\\\hline +\end{spreadtab} +\end{lstlisting} +\end{minipage}% +\begin{minipage}{0.35\linewidth} +\centering +\STsetdecimalsep{,} +\begin{spreadtab}{{tabular}{|*3{>$r<$}|}}\hline +@x & @y & @\text{Moyenne}\\\hline +5 & -4 & (a2+b2)/2\\ +-6.1 & -8 & (a3+b3)/2\\ +9.85 & 3.7 & (a4+b4)/2\\\hline +\end{spreadtab}\par\smallskip +\STsetdecimalsep{{,}} +\begin{spreadtab}{{tabular}{|*3{>$r<$}|}}\hline +@x & @y & @\text{Moyenne}\\\hline +5 & -4 & (a2+b2)/2\\ +-6.1 & -8 & (a3+b3)/2\\ +9.85 & 3.7 & (a4+b4)/2\\\hline +\end{spreadtab} +\end{minipage} + \section{Macro-fonctions} L'extension \falseverb{fp} fournit un nombre conséquent d'opérations et de fonctions. Malgré tout, dans le cadre d'un package comme \ST, celles-ci peuvent être insuffisantes et il est possible au programmeur averti d'écrire des macro-fonctions supplémentaires en utilisant celles fournies par \falseverb{fp}. Cette section présente les macro-fonctions pour l'instant disponibles\footnote{Bien d'autres restent à écrire ! Elles seront disponibles dans des versions futures de \ST.}. Il y aura plus de précisions sur la méthode pour programmer des macro-fonctions dans la prochaine version de ce manuel. @@ -472,12 +698,12 @@ L'extension \falseverb{fp} fournit un nombre conséquent d'opérations et de fon \subsubsection{Sommer des cellules} La fonction \og\verbinline=sum=\fg permet de faire la somme d'une ou plusieurs plages de cellules. -Elle s'utilise ainsi : \verbinline=sum(;;...;)=, où une plage de cellules est :\parindent2em\smallskip +Elle s'utilise ainsi : \verbinline=sum(;;...;)=, où une plage de cellules est : \begin{itemize} \item soit une cellule isolée comme \og\falseverb{a1}\fg{} ou \og\falseverb{[2,1]}\fg{}; \item soit une zone rectangulaire délimitée par la cellule supérieure gauche et inférieure droite de cette façon : \og\verb=:=\fg, à condition que \og\verb==\fg se trouve \emph{avant} \og\verb==\fg{} lorsqu'on parcourt le tableau de haut en bas, de gauche à droite.\par Voici des exemple de plages de cellules : \og\falseverb{a2:d5}\fg{}, \og\falseverb{[-1,-1]:[2,3]}\fg{}, \og\falseverb{b4:[5,1]}\fg{}. -\end{itemize}\parindent0pt\medskip +\end{itemize} Dans les plages de cellules, les cellules vides ou ne contenant que du texte sont considérées comme contenant le nombre 0. Il en est de même pour les cellules masquée car fusionnées par \verbinline-\multicolumn-. Les références relatives et absolues peuvent être utilisées conjointement, comme bon semble à l'utilisateur. Voici un exemple où l'on fait la somme des coefficients du triangle de Pascal :\par\nobreak @@ -579,16 +805,16 @@ La macro fonction \verbinline-rand()- renvoie un nombre aléatoire décimal comp \subsection{Les macro-fonctions de test} Elles sont au nombre de 3 et ont la syntaxe suivante :\par\nobreak \begin{center} -\verbinline=ifeq(nombre1,nombre2,nombre3,nombre4>)=\par +\verbinline=ifeq(nombre1,nombre2,nombre3,nombre4)=\par \verbinline=ifgt(nombre1,nombre2,nombre3,nombre4=\par \verbinline=iflt(nombre1,nombre2,nombre3,nombre4)= \end{center} -La comparaison se fait entre \falseverb{nombre1} et \falseverb{nombre2} :\parindent2em\smallskip +La comparaison se fait entre \falseverb{nombre1} et \falseverb{nombre2} : \begin{itemize} \item test d'égalité pour \verbinline-ifeq- : \falseverb{nombre1} = \falseverb{nombre2} ? \item test de supériorité stricte pour \verbinline-ifgt- : \falseverb{nombre1} > \falseverb{nombre2} ? \item test d'infériorité stricte pour \verbinline-iflt- : \falseverb{nombre1} < \falseverb{nombre2} ? -\end{itemize}\parindent0pt\medskip +\end{itemize} Si le test est vrai, \falseverb{nombre3} est retourné, sinon c'est \falseverb{nombre4}. À titre d'exemple, voici quelques valeurs de la fonction @@ -659,13 +885,13 @@ frlongdatetonum(\today) & frlongdatetonum(25 décembre 2009)\\ \subsubsection{Passer d'un nombre à une date} Plusieurs macro-fonctions permettent de traduire un nombre en une donnée de date. Toutes ces macro-fonctions ont en commun que leur résultat est du \emph{texte}. Par conséquent, \emph{la cellule les contenant deviendra une cellule textuelle} dont le texte sera le résultat de cette fonction : si un texte cohabitait avec la formule dans cette cellule, il sera écrasé par le résultat. Il en résulte que la cellule ne peut plus faire l'objet d'aucun traitement mathématique ensuite. -Voici ces fonctions :\parindent2em\smallskip +Voici ces fonctions : \begin{itemize} \item \verbinline-numtofrshortdate- transforme un nombre en une date courte du type 14/7/1789; \item \verbinline-numtofrlongdate- transforme un nombre en une date longue du type \og 14 juillet 1789\fg; \item \verbinline-numtofrmonth- extrait d'un nombre représentant une date le nom du mois correspondant; \item \verbinline-numtofrday- extrait d'un nombre représentant une date le nom du jour correspondant. -\end{itemize}\parindent0pt\medskip +\end{itemize} Voici un exemple où l'on se place 1000 jours avant puis 1000 jours après le 1/6/2009. Pour chacune de ces 2 dates, on calcule la date courte, la date longue, le mois et le jour de la semaine.\par\nobreak \begin{lstlisting} \begin{spreadtab}{{tabular}{cc}} \hline @@ -724,7 +950,7 @@ La raison est simple, c'est que le \verb-\dline- de la ligne 4, n'est \emph{pas} Comme il n'y a pas de \verb-@- ni de délimiteur de formule \verb-:={...}-, \verb-\FPeval- essaie vaillamment de calculer ce contenu et échoue évidemment ! -Pour pouvoir compiler ce code sans erreur, la cellule \falseverb{a2} \emph{doir} contenir un marqueur de champ numérique :\par\nobreak +Pour pouvoir compiler ce code sans erreur, la cellule \falseverb{a2} \emph{doit} contenir un marqueur de champ numérique :\par\nobreak \begin{lstlisting} \newcommand\dline{\hline\hline} \begin{spreadtab}{{tabular}{*7c}} @@ -760,11 +986,11 @@ Il y a 4 cellules \emph{visibles} fusionnées, on écrira donc \verbinline-\mult Maintenant, on compte 4 lettres à partir de la lettre \falseverb{b} en l'incluant dans le décompte. On arrive à la lettre \falseverb{e} : cela détermine un intervalle de colonnes \og\falseverb{b-e}\fg. Dans cet intervalle, 2 colonnes masquées sont incluses (\falseverb c et \falseverb d) et 1 colonne masquée n'est pas comprise (\falseverb f). Ces 2 nombres sont importants pour comprendre la suite, aussi, notons-les $a$ et $b$ dans le cas général. -La règle est la suivante :\parindent2em\smallskip +La règle est la suivante : \begin{itemize} \item il faut rajouter $b$ signes \og\verb-&-\fg{} après le \verbinline-\multicolumn- (pour l'exemple, il en faudrait 1). \item les références des colonnes des cellules qui suivent le \verbinline-\multicolumn- seront décalées de $a$ lettres vers le début de l'alphabet. Pour l'exemple donnée, si on veut faire référence à la cellule marquée \og \falseverb{i2}\fg{}, il faudra écrire \falseverb{g2} (au lieu de \falseverb{i2}). -\end{itemize}\parindent0pt\medskip +\end{itemize} Voici un vrai exemple dont la structure est similaire au précédent : $a=2$ et $b=1$. Dans le code, remarquer le \og\textcolor{red}{\texttt{\&}}\fg{} qui a été ajouté puisque $b=1$. Par ailleurs, on reste simple avec les formules, on ajoute 1 au nombre du dessus :\par\nobreak \begin{lstlisting}[escapechar=Z] \begin{spreadtab}{{tabular}{|*{7}{c|}}} @@ -801,14 +1027,14 @@ a2+1& b2+1 & & & & & & & h2+1 & i2+1\\\hline \end{center} \subsection{Messages émis par \ST} -Le package émet des messages d'erreur et arrête la compilation dans ces cas :\parindent2em\smallskip +Le package émet des messages d'erreur et arrête la compilation dans ces cas : \begin{itemize} \item Pour calculer une cellule, on calcule de proche en proche des cellules qui par le jeu des références, reviennent sur la cellule d'origine (références circulaires). Dans ce cas, l'arbre des dépendances est affiché dans le message d'erreur; \item une formule nécessitant un nombre fait référence à une cellule vide ou ne contenant que du texte; \item une cellule fait référence à une cellule non définie (hors limite du tableau); \item une cellule fait référence à une cellule fusionnée par un \verbinline-\multicolumn-; \item une référence relative entre crochets ne respecte pas la syntaxe. -\end{itemize}\parindent0pt\medskip +\end{itemize} Le package peut émettre des messages d'information (dans le fichier de log), ce qu'il fait par défaut. La commande \verbinline-\STmessage- permet ou pas l'émission de messages d'information. Pour chacune des ces altenatives, la syntaxe est la suivante : \verbinline-\STmessage{true}- ou \verbinline-\STmessage{false}-. @@ -846,10 +1072,65 @@ Pour la seconde étape, les cellules sont évaluées de haut en bas, de gauche Pour chaque ligne suivante, il n'y a qu'une seule cellule ce qui signifie que lorsque \ST essaie de les évaluer, elles l'ont déjà été et sont des nombres ou alors, elles ne font références qu'à des cellules déjà calculées. +\subsection{Débogage} +Pour faciliter l'utilisation de \ST, un mode de débogage est disponible. Il est activé lorsque la commande \verbinline-\STdebug- est présente dans l'argument optionnel de l'environnement \verb-spreadtab-. Cette commande change le comportement de \ST qui, au lieu d'afficher le tableau final, affiche un (ou plusieurs) tableau de débogage. Cet affichage se fait juste après que \ST ait lu l'ensemble de toutes les cellules ; aucun calcul de formule n'a encore eu lieu. Il y a autant de tableaux affichés que de commande \verbinline-\STdebug- présentes, sous réserve que leur argument soit différent. Seuls 3 arguments sont possibles, et voici ce qu'il permettent : +\begin{itemize} + \item \verbinline-\STdebug{formula}- : affichage des champs numériques de toutes les cellules et les fins de ligne; + \item \verbinline-\STdebug{text}- : affichage des champs textuels de toutes les cellules; + \item \verbinline-\STdebug{code}- : affichage du code interne que \ST affecte à chaque cellule. Ce code interne est assigné à chaque cellule lors de la lecture du tableau. Il vaut : + \begin{enumerate}[label=\small\textbullet] + \item $-1$ s'il s'agit d'une cellule fusionnée par une commande \verbinline-\multicolumn-; + \item 0 si la cellule est vide ou purement textuelle; + \item 1 si le champ numérique de la cellule contient une formule qui sera à évaluer plus tard; + \item 2 si la champ numérique de la cellule contient un nombre. + \end{enumerate} +\end{itemize} + +Lorsque le mode débogage est activé, le tableau final \emph{n'est pas affiché}. Il est cependant possible de forcer cet affichage en mettant la commande \verbinline-\STdisplaytab- dans l'argument optionnel. + +Voici un tableau sur lequel s'appuiera l'exemple suivant : + +\begin{lstlisting} +\begin{spreadtab}{{tabular}{|r|r|r|}}\hline +@$x$ &@$y$ & @$x+y$\\\hline\hline +22 & 54 & \STcopy{v3}{a2+b2} \\ +43 & 65 & \\ +49 & 37 & \\\hline +$Sx=:={a2+a3+a4}$ & $Sy=:={b2+b3+b4}$ & $Sx+Sy=:={}$\\\hline +\multicolumn2{|r|}{$Sy-Sx=:={b5-a5}$} & @\multicolumn1c{}\\\cline{1-2} +\end{spreadtab} +\end{lstlisting} +\begin{center} +\begin{spreadtab}{{tabular}{|r|r|r|}}\hline +@$x$ &@$y$ & @$x+y$\\\hline\hline +22 & 54 & \STcopy{v3}{a2+b2} \\ +43 & 65 & \\ +49 & 37 & \\\hline +$Sx=:={a2+a3+a4}$ & $Sy=:={b2+b3+b4}$ & $Sx+Sy=:={}$\\\hline +\multicolumn2{|r|}{$Sy-Sx=:={b5-a5}$} & @\multicolumn1c{}\\\cline{1-2} +\end{spreadtab} +\end{center} +On va demander à ce que \ST affiche les 3 tableaux de débogage possibles concernant le tableau ci-dessus. Pour cela, il suffit de modifier la ligne 1 du code ci-dessus comme ceci : + +\hfill\verbinline[basicstyle=\ttfamily\small]-\begin{spreadtab}[\STdebug{text}\STdebug{formula}\STdebug{code}]{{tabular}{|rr|r|}}\hline-\hfill\kern0pt +\begin{center} +\begin{spreadtab}[\STdebug{text}\STdebug{formula}\STdebug{code}]{{tabular}{|rr|r|}}\hline +@$x$ &@$y$ & @$x+y$\\\hline\hline +22 & 54 & \STcopy{v3}{a2+b2} \\ +43 & 65 & \\ +49 & 37 & \\\hline +$Sx=:={a2+a3+a4}$ & $Sy=:={b2+b3+b4}$ & $Sx+Sy=:={}$\\\hline +\multicolumn2{|r|}{$Sy-Sx=:={b5-a5}$} & @\multicolumn1c{}\\\cline{1-2} +\end{spreadtab} +\end{center} +Ces 3 tableaux de débogage peuvent aider à comprendre un peu mieux le fonctionnement interne de \ST. On peut observer dans le tableau 2 que toutes les cellules ayant un champ numérique ont un code interne de 1 ou 2 (voir tableau 3) et ont un marqueur de champ numérique "\verb-:=-" qui leur est associé (voir tableau 1). Ce marqueur représente l'endroit où sera inséré ---~par substitution~--- le résultat du calcul du champ numérique. C'est donc à partir des contenus des champs textuels du tableau 1 et par simple substitution, qu'une fois les champs numériques calculés, les cellules sont reconstituées pour donner celles du tableau final. + +Dans les tableaux ci-dessus, les cellules contenant les coordonnées ne sont grisées que si le package \href{http://www.ctan.org/tex-archive/macros/latex/contrib/colortbl/}{\texttt{\textbf{colortbl}}} a été chargé. + \section{Des exemples} Voici quelques tableaux pour finir ! -Afin que l'on sache quels nombres sont calculés, seuls les nombres non calculés sont en \textcolor{red}{rouge}. Dans ces tableaux, beaucoup d'artifices (des struts, des multicolumn) et des packages (notamment numprint et ses colonnes \og N\fg{} qui alignent les séparateurs décimaux) ont été utilisés pour obtenir un résultat satisfaisant. Le code est parfois lourd et peu lisible, mais il ne s'agit pas ici d'exemples basiques mais de tableaux peaufinés ! +Afin que l'on sache quels nombres sont calculés, seuls les nombres non calculés sont en \textcolor{red}{rouge}. Dans ces tableaux, beaucoup d'artifices (des struts, des multicolumn) et des packages (notamment numprint et ses colonnes \og N\fg{} qui alignent les séparateurs décimaux) ont été utilisés pour obtenir un résultat satisfaisant. Le code est parfois lourd et peu lisible, mais il ne s'agit pas ici d'exemples basiques mais de tableaux peaufinés ! Par souci de lisibilité, la commande \verbinline-\STcopy- n'a pas été utilisée. \subsection{Encore un triangle de Pascal} \begin{lstlisting} @@ -983,7 +1264,7 @@ Ce tableau est généré par l'environnement \verb=tabularx= de façon à occupe @Item 2 & 12 & 7 & [-2,0]*[-1,0] & $-:={10}\PC$ & [-2,0]*(1-[-1,0]/100)\\ @Item 3 & 4.50 & 40 & [-2,0]*[-1,0] & $-:={35}\PC$ & [-2,0]*(1-[-1,0]/100)\\ @Item 4 & 650 & 2 & [-2,0]*[-1,0] & $-:={15}\PC$ & [-2,0]*(1-[-1,0]/100)\\\hline -@\multicolumn{6}{c}{\vspace{-1.5ex}}\\\cline{4-6}% ligne vide et on remonte un peu ! +@\multicolumn{6}{c}{}\\[-1.5ex]\cline{4-6}% ligne vide et on remonte un peu ! @\multicolumn{1}{c}{\rule[-1.2ex]{0pt}{4ex}}&@\multicolumn{2}{r|}{\textbf{Total}}& sum(d2:[0,-2]) & \multicolumn{1}{c}{$:={round(([1,0]/[-1,0]-1)*100,0)}\PC$} & {\fontseries{b}\selectfont}:={sum(f2:[0,-2])}\\ \cline{4-6} \end{spreadtab} @@ -998,7 +1279,7 @@ Ce tableau est généré par l'environnement \verb=tabularx= de façon à occupe @Item 2 & 12 & 7 & [-2,0]*[-1,0] & $-:={10}\PC$ & [-2,0]*(1-[-1,0]/100)\\ @Item 3 & 4.50 & 40 & [-2,0]*[-1,0] & $-:={35}\PC$ & [-2,0]*(1-[-1,0]/100)\\ @Item 4 & 650 & 2 & [-2,0]*[-1,0] & $-:={15}\PC$ & [-2,0]*(1-[-1,0]/100)\\\hline -@\multicolumn{6}{c}{\vspace{-1.5ex}}\\\cline{4-6}% ligne vide et on remonte un peu ! +@\multicolumn{6}{c}{}\\[-1.5ex]\cline{4-6}% ligne vide et on remonte un peu ! @\multicolumn{1}{c}{\rule[-1.2ex]{0pt}{4ex}}&@\multicolumn{2}{r|}{\textbf{Total}}& sum(d2:[0,-2]) & \multicolumn{1}{c}{$:={round(([1,0]/[-1,0]-1)*100,0)}\PC$} & {\fontseries{b}\selectfont}:={sum(f2:[0,-2])}\\ \cline{4-6} \end{spreadtab} @@ -1047,7 +1328,8 @@ Chaque nombre est la somme des deux nombres se trouvant au dessous de lui.\par\n &\multicolumn{2}{|K}{:={[-1,1]+[1,1]}}&\multicolumn{2}{|K}{:={[-1,1]+[1,1]}}&\multicolumn{2}{|K|}{:={[-1,1]+[1,1]}}&\\\hline \multicolumn{2}{|K}{\color{red}:={-5}}&\multicolumn{2}{|K}{\color{red}:={3}}&\multicolumn{2}{|K}{\color{red}:={-2}}&\multicolumn{2}{|K|}{\color{red}:={-3}}\\\hline \end{spreadtab} -\end{center}\medskip +\end{center} +\medskip \parskip0pt \begin{center} $\star$\par diff --git a/Master/texmf-dist/doc/latex/spreadtab/spreadtab_doc_vn.pdf b/Master/texmf-dist/doc/latex/spreadtab/spreadtab_doc_vn.pdf deleted file mode 100644 index 5d686f8d740..00000000000 Binary files a/Master/texmf-dist/doc/latex/spreadtab/spreadtab_doc_vn.pdf and /dev/null differ diff --git a/Master/texmf-dist/doc/latex/spreadtab/spreadtab_doc_vn.tex b/Master/texmf-dist/doc/latex/spreadtab/spreadtab_doc_vn.tex deleted file mode 100644 index f2a3f89cfc3..00000000000 --- a/Master/texmf-dist/doc/latex/spreadtab/spreadtab_doc_vn.tex +++ /dev/null @@ -1,1013 +0,0 @@ -% ____________________________________________________________________________ -% | | -% | | -% | spreadtab v0.1 | -% | | -% | November 3 2009 | -% | | -% |___________________________________________________________________________| -% -% This is spreadtab_doc_vn.tex, the source code of the vietnamese manual -% of the spreadtab package. -% -% Copyright Christian Tellechea 2009 -% Email: unbonpetit@gmail.com -% -% Dịch bởi: Lê Hữu Điền Khuê -% Email: huudienkhue.le@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{vntex} -\usepackage{lmodern} -\usepackage[a4paper,margin=2.5cm]{geometry} -\usepackage{amsmath,amssymb} -\usepackage{array} -\usepackage{colortbl} -\usepackage{tabularx} -\usepackage{xcolor} -\usepackage{listings} -\usepackage{numprint} -\usepackage{xspace} -\usepackage[bottom]{footmisc} -\usepackage{spreadtab} -\usepackage{fancyhdr} - \fancyhead[L]{} - \fancyhead[C]{\small\bfseries\ST} - \fancyhead[R]{\scriptsize\slshape \leftmark} - \fancyfoot[l]{\tiny Biên dịch bởi Christian \textsc{Tellechea} \today.} - \fancyfoot[c]{} - \fancyfoot[r]{\thepage} - -\definecolor{ST@bckgcolor}{rgb}{0.87,0.9,1} -\definecolor{ST@codebckgcolor}{rgb}{0.9,0.9,0.9} -\definecolor{ST@keywordstc}{rgb}{0.7,0,0} -\definecolor{ST@keywordslatex}{rgb}{0,0,1} -\definecolor{ST@arguments}{rgb}{0,0,0} -\definecolor{ST@comments}{rgb}{0.5,0.5,0.5} -\lstset{% - language=[AlLaTeX]TeX,float=hbp,basicstyle=\footnotesize\ttfamily,identifierstyle=\color{ST@arguments},% - keywordstyle=\color{ST@keywordslatex},commentstyle=\itshape\color{ST@comments},% - columns=fixed,tabsize=4,frame=single,extendedchars=false,% - showspaces=false,showstringspaces=false,numbers=left,numberstyle=\tiny\ttfamily,% - breaklines=true,breakindent=3em,backgroundcolor=\color{ST@bckgcolor},breakautoindent=true,% - captionpos=t,xleftmargin=1em,xrightmargin=1em,lineskip=0pt,% - numbersep=1em,classoffset=1,% - morekeywords={% les macros et commandes de spreadtab - spreadtab,SThiderow,SThidecol,STsavecell,STautoround,STmessage,% - STnumericfieldmarker,STtextcell,fact,ifeq,ifgt,iflt,numtofrshortdate,% - numtoengshortdate,numtofrlongdate,numtoenglongdate,numtofrmonth,% - numtoengmonth,numtofrday,numtoengday,sum,rand,randint,sumprod,% - frshortdatetonum,engshortdatetonum,englongdatetonum,frlongdatetonum},% - keywordstyle=\color{ST@keywordstc},classoffset=0} -\makeatother - -\newcommand\verbinline{\lstinline[breaklines=false,basicstyle=\normalsize\ttfamily]} -\newcommand\ST{\textsf{spreadtab}\xspace} -\newcommand\falseverb[1]{\texttt{\detokenize{#1}}} - -\usepackage[a4paper,bookmarks=true,bookmarksopen=true,colorlinks=true,hyperfootnotes=false,filecolor=black,linkcolor=blue,urlcolor=magenta,pdfauthor={Christian TELLECHEA},pdftitle={spreadtab},pdfsubject={Spreadtab cho phép sử dụng các chức năng của một bảng tính trong bảng LaTeX},pdfkeywords={spreadtab},pdfcreator={LaTeX},unicode]{hyperref} - -\begin{document} -\parindent0pt\pagestyle{fancy} -\begin{titlepage} - \null\par\vfill - \begin{center} - \begin{minipage}{0.75\linewidth} - \begin{center} - \Huge\bfseries\ST\par\vspace{5pt} - \small v\csname ST@ver\endcsname\par\vspace{35pt} - \normalsize Hướng dẫn sử dụng - \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} - Dịch bởi Lê Hữu Điền Khuê\par - \href{mailto:huudienkhue.le@gmail.com}{\texttt{\textbf{huudienkhue.le@gmail.com}}}\par\vspace{5pt} - Ngày 3 tháng 11 năm 2009 - \end{center} - \vfill - \begin{center} - \begin{minipage}{0.8\linewidth} - \noindent\hrulefill\par - \hfill\textbf{\textit{Tóm tắt}}\hfill{}\medskip\par\footnotesize - Gói này cho phép thực hiện những chức năng của một bảng tính trong mọi môi trường bảng của \LaTeX{}.\par\smallskip - Chức năng chính của nó là "công thức hóa" một ô trong bảng bằng cách tham chiếu đến các ô khác, tính giá trị của các ô chứa công thức và hiển thị kết quả của chúng.\par - \hrulefill - \end{minipage} - \end{center} - \vfill{} -\end{titlepage} - -\tableofcontents\newpage -\parskip\medskipamount -\section{Mở đầu} -\subsection{Giới thiệu} -Mục đích của \ST là cho phép viết các công thức toán học vào một hay nhiều ô của một bảng mà trong các công thức này có chứa giá trị của những ô khác, hoàn toàn giống như khi tiến hành trên một bảng tính. Gói này sẽ tính các công thức theo một thứ tự thích hợp và hiển thị bảng chứa các giá trị được tính. - -Gói này cần đến $\varepsilon$-\TeX, \LaTeXe{} cũng như gói \href{http://www.ctan.org/tex-archive/macros/latex/contrib/fp/}{\texttt{\textbf{fp}}} để thực hiện việc tính toán. Gói \href{http://www.ctan.org/tex-archive/macros/latex/contrib/xstring/}{\texttt{\textbf{xstring}}} cũng được đòi hỏi (bản \falseverb{v1.5c [2009/06/05]} hoặc mới hơn). - -Ngay từ đầu tác giả đã mong muốn rằng \ST sẽ tương thích \emph{với mọi} môi trường bảng mà ở đó các cột được phân chia bởi \verb=&= và việc bắt đầu một hàng mới được thực hiện nhờ \verb=\\=. Điều này bắt buộc tác giả phải lập trình \ST hoàn toàn độc lập với môi trường bảng. Do vậy, \ST sẽ thực hiện việc "đọc" bảng và tính các công thức \emph{trước khi} môi trường bảng làm nhiệm vụ của nó. - -Như vậy, \ST sẽ thực hiện ba bước:\parindent2em\smallskip -\begin{itemize} - \item đầu tiên, \ST đọc nội dung của bảng và chia nó thành hàng rồi thành ô (\ST sẽ tự nhận thấy các ô có công thức); - \item tiếp theo nó sẽ thực hiện việc tính các công thức của các ô (các ô dùng để tính một ô nào khác sẽ được tính trước). Thứ tự của các ô được tính sẽ do \ST xác định. Các phép tính sẽ được thực hiện bởi gói \href{http://www.ctan.org/tex-archive/macros/latex/contrib/fp/}{\texttt{\textbf{fp}}}; - \item cuối cùng, nó sẽ xây dựng lại bảng bằng cách thay các công thức bằng giá trị đã tính của chúng và sau đó nhường việc hiển thị bảng cho môi trường bảng (tùy chọn bởi người sử dụng). -\end{itemize}\parindent0pt\medskip - -Cú pháp: -\begin{lstlisting}[backgroundcolor=\color{ST@codebckgcolor},escapechar=!] -\begin{spreadtab}{{}} -! bảng chứa công thức và số! -\end{spreadtab} -\end{lstlisting} -và sau khi \ST thực hiện công việc của mình, bảng sẽ được hiển thị giống như khi ta thực hiện cú pháp: -\begin{lstlisting}[backgroundcolor=\color{ST@codebckgcolor},escapechar=!] -\begin{} - !bảng chứa số! -\end{} -\end{lstlisting} -Việc thực hiện ba bước trên sẽ mất thời gian, hơn nữa \falseverb{fp} chậm trong việc tính toán, do đó việc biên dịch bảng với \ST sẽ \emph{chậm hơn rất nhiều} so với việc biên dịch một bảng bình thường. - -Cần lưu ý rằng \ST \emph{không thể thay thế một bảng tính}. Một điều hơi khó chịu đó là nó không trực quan, nhất là khi làm việc với những bảng lớn và phức tạp, và cú pháp không mấy đơn giản của \ST cũng sẽ là một trở ngại nữa. Ưu điểm của \ST là có thể thực hiện việc tính toán \emph{ngay trong mã nguồn} nhận được khi chuyển đổi sang mã \LaTeX{} một bảng của một chương trình bảng tính\footnote{Có hai chương trình chính cho phép thực hiện điều này : \href{http://calc2latex.sourceforge.net/}{\texttt{\textbf{cacl2latex}}} đối với calc của Open Office, và \href{http://www.ctan.org/tex-archive/support/excel2latex/}{\texttt{\textbf{excel2latex}}} đối với excel của Microsoft Office.}. Chúng ta cũng nên tránh các khuyết điểm của các chương trình chuyển đổi nói trên như: việc định dạng bảng cần phải chỉnh sửa lại nếu muốn nhận được bảng hoàn toàn giống như trong chương trình bảng tính, không tương thích với mọi môi trường bảng, chỉ nhận được các giá trị hay kết quả (các công thức đều bị mất) sau khi chuyển đổi, cần phải tiến hành chuyển đổi lại nếu thay đổi một giá trị hay một công thức trong bảng. - -\subsection{Động lực chính} -Một vài tháng trước khi viết \ST, Derek \textsc{O'Connor} đã nhận xét với tác giả rằng vào thời điểm đó không có một gói nào của \LaTeX{} cho phép tính toán các công thức trong các bảng, tương tự như một bảng tính. Nhận thấy rằng đây là một thách thức thú vị, tác giả bắt tay vào viết \ST, cũng chỉ như làm một bài tập lập trình vậy. - -Thuật toán chính trong \ST xác định thứ tự mà các ô được tính, nó không phải là "chuyên môn" của lập trình \LaTeX. Những thuật toán khác mang hơi hưởng của \LaTeX{} nhiều hơn như phân tích các ô và các công thức để tìm ra những tham chiếu đến những ô khác. Đây đúng là một bài tập thú vị, bởi vì trên phương diện lập trình, \TeX{} không hề cung cấp cho chúng ta một thứ gì đó tương tự như con trỏ để xây dựng các danh sách liên kết của các ô cần tính. - -Con đường để đi đến phiên bản đầu tiên này của \ST đúng là dài. Tác giả xin cảm ơn Christophe \textsc{Casseau} đã quan tâm ngay từ đầu và cho nhiều góp ý bổ ích, cũng như gần đây là Derek \textsc{O'Connor} đã giúp đỡ và trao đổi với tác giả. Đồng thời cũng xin cảm ơn Lê Hữu Điền Khuê đã dịch tài liệu này sang tiếng Việt. - -\section{Các chức năng thông thường} - -\subsection{Vị trí tuyệt đối} -Trong một bảng, các ô được định vị bởi vị trí tuyệt đối của chúng như sau:\parindent2em\smallskip -\begin{itemize} - \item mỗi cột là một chữ cái từ \falseverb a đến \falseverb z, \falseverb a là cột đầu tiên bên trái: như vậy số cột tối đa là 26 (đối với hầu hết các trường hợp thì như thế là quá đủ); \ST sẽ không phân biệt các chữ cái hoa và chữ cái thường; - \item tiếp ngay sau chữ cái, một số nguyên dương sẽ biểu diễn số thứ tự của hàng, hàng số 1 là hàng đầu tiên trên cùng. -\end{itemize}\parindent0pt\medskip -Một số ví dụ về cách viết vị trí tuyệt đối: "\falseverb{b4}", "\falseverb{C1}" hay "\falseverb{d13}"\footnote{Cách đánh số này tương tự như trong các bảng tính : chữ cái là thứ tự của cột và số là thứ tự của hàng.}. - -Trong ví dụ sau, ta sẽ tính tổng của mỗi hàng và của mỗi cột và sau đó là tổng của tất cả các ô: - -\begin{minipage}{0.75\linewidth} -\begin{lstlisting} -\begin{spreadtab}{{tabular}{rr|r}} -22 & 54 & a1+b1 \\ -43 & 65 & a2+b2 \\ -49 & 37 & a3+b3 \\ -\hline -a1+a2+a3 & b1+b2+b3 & a4+b4 -\end{spreadtab} -\end{lstlisting} -\end{minipage}% -\begin{minipage}{0.25\linewidth} -\centering -\begin{spreadtab}{{tabular}{rr|r}} -22 & 54 & a1+b1 \\ -43 & 65 & a2+b2 \\ -49 & 37 & a3+b3 \\ -\hline -a1+a2+a3 & b1+b2+b3 & a4+b4 -\end{spreadtab} -\end{minipage}% - -Còn ví dụ sau sẽ tính một số hàng của tam giác Pascal: - -\begin{minipage}{0.75\linewidth} -\begin{lstlisting} -\begin{spreadtab}{{tabular}{ccccc}} -1 & & & & \\ -a1 & a1 & & & \\ -a2 & a2+b2 & b2 & & \\ -a3 & a3+b3 & b3+c3 & c3 & \\ -a2 & a4+b4 & b4+c4 & c4+d4 & d4 -\end{spreadtab} -\end{lstlisting} -\end{minipage}% -\begin{minipage}{0.25\linewidth} -\centering -\begin{spreadtab}{{tabular}{ccccc}} -1 & & & & \\ -a1 & a1 & & & \\ -a2 & a2+b2 & b2 & & \\ -a3 & a3+b3 & b3+c3 & c3 & \\ -a2 & a4+b4 & b4+c4 & c4+d4 & d4 -\end{spreadtab} -\end{minipage}% - -\subsection{Vị trí tương đối} -Để tham chiếu đến một ô, sẽ rất thuận tiện nếu ta xác định vị trí của nó so với ô chứa công thức. "Vị trí tương đối" sẽ giúp ta làm điều này. Vị trí tương đối được cho bởi cú pháp \falseverb{[x,y]}, nó sẽ tham chiếu đến ô thứ \falseverb x theo chiều ngang và thứ \falseverb y theo chiều dọc đối với ô chứa vị trí tương đối, tức chứa công thức (tạm gọi là ô hiện tại). Chẳng hạn \falseverb{[-2,3]} sẽ tham chiếu đến ô ở vị trí thứ 2 về \emph{phía trái} và vị trí thứ 3 \emph{phía dưới} của ô hiện tại (nghĩa là nếu xuất phát từ ô hiện tại, để đi đến được ô \falseverb{[-2,3]}, ta phải di chuyển sang trái 2 ô, sau đó di chuyển xuống phía dưới 3 ô). - -Ví dụ dưới đây xây dựng một bảng giống như ví dụ trước nhưng sử dụng vị trí tương đối và môi trường "\verbinline-matrix-" của gói \href{http://www.ctan.org/tex-archive/macros/latex/required/amslatex/math/}{\texttt{\textbf{amsmath}}}: - -\begin{minipage}{0.82\linewidth} -\begin{lstlisting} -$ -\begin{spreadtab}{{matrix}{}} -1\\ -[0,-1] & [-1,-1]\\ -[0,-1] & [-1,-1]+[0,-1] & [-1,-1]\\ -[0,-1] & [-1,-1]+[0,-1] & [-1,-1]+[0,-1] & [-1,-1]\\ -[0,-1] & [-1,-1]+[0,-1] & [-1,-1]+[0,-1] & [-1,-1]+[0,-1] & [-1,-1]\\ -\end{spreadtab} -$ -\end{lstlisting} -\end{minipage}\hfill -\begin{minipage}{0.15\linewidth} -\centering -$ -\begin{spreadtab}{{matrix}{}} -1\\ -[0,-1] & [-1,-1]\\ -[0,-1] & [-1,-1]+[0,-1] & [-1,-1]\\ -[0,-1] & [-1,-1]+[0,-1] & [-1,-1]+[0,-1] & [-1,-1]\\ -[0,-1] & [-1,-1]+[0,-1] & [-1,-1]+[0,-1] & [-1,-1]+[0,-1] & [-1,-1]\\ -\end{spreadtab} -$ -\end{minipage}% - -Chúng ta thấy rằng đối với việc xây dựng bảng này, việc sử dụng vị trí tương đối là thích hợp hơn bởi vì chúng ta chỉ sử dụng đúng hai vị trí tương đối: \falseverb{[0,-1]} tham chiếu đến ô ngay phía trên và \falseverb{[-1,-1]} tham chiếu đến ô gần nhất ở phía trái-trên (hay phía Tây-Bắc trong ngôn ngữ bản đồ) so với ô chứa công thức. - -Chúng ta cũng có thể sử dụng cả vị trí tuyệt đối lẫn tương đối trong cùng một công thức. - -\subsection{Các ô chứa văn bản} -Nếu muốn chèn văn bản vào một ô, chúng ta cần phải cho \ST biết rằng ô này sẽ không được tính. Chỉ cần thêm vào kí tự "\falseverb @" ở một ví trí nào đó trong nội dung của ô, ô này sẽ được \ST bỏ qua và sẽ trở thành một ô "trơ": nó sẽ không thể được tham chiếu đến từ bất kì ô nào trong bảng. - -Sau đây là một ví dụ: -\begin{lstlisting}[escapechar=!] -\begin{spreadtab}{{tabular}{|r|ccc|}} -\hline -@ !giá trị của! $x$ & -5 & -1 & 4 \\ -@ $f(x)=2x$ & 2*[0,-1] & 2*[0,-1] & 2*[0,-1] \\\hline -\end{spreadtab} -\end{lstlisting} -\begin{center} -\begin{spreadtab}{{tabular}{|r|ccc|}} -\hline -@ giá trị của $x$ & -5 & -1 & 4 \\ -@ $f(x)=2x$ & 2*[0,-1] & 2*[0,-1] & 2*[0,-1] \\\hline -\end{spreadtab} -\end{center} -Ta có thể thay "\falseverb @" bằng một kí tự (hoặc một chuỗi các kí tự) khác, chỉ cần định nghĩa lại lệnh \verbinline=\STtextcell= theo cú pháp -\begin{center} -\verbinline-\renewcommand\STtextcell-\verb-{kí tự hoặc chuỗi kí tự}- -\end{center} -Chẳng hạn nếu ta định nghĩa \verbinline-\renewcommand\STtextcell{toto}- thì khi đó, mọi ô chứa "\falseverb{toto}" đều được xem như những ô chứa văn bản. - -Ngoài ra, ô trống cũng được \ST xem như là ô chứa văn bản. - -\subsection{Các ô hỗn hợp} -Trên thực tế, mỗi ô được tạo nên bởi \emph{hai} vùng : \emph{vùng số} chứa công thức và \emph{vùng chữ} chứa văn bản (vùng này sẽ được \falseverb{fp} bỏ qua khi tính toán):\parindent2em\smallskip -\begin{itemize} - \item trong một ô, nếu không có gì đặc biệt, toàn bộ ô sẽ được xem giống như một vùng số, và vùng chữ là rỗng (xem ví dụ về tam giác Pascal ở phần trên của tài liệu); - \item nếu ô có chứa "\falseverb{@}" thì toàn bộ ô sẽ được xem như một vùng chữ, vùng số là rỗng; - \item nếu ô có chứa "\verb-:=-" thì đối số nằm giữa hai giấu ngoặc nhọn theo sau là vùng số, và những thứ còn lại là vùng chữ. Ô này sẽ có cấu trúc như sau:\par\smallskip - \hfil\verb-:={vùng số}-\hfil\null\par\smallskip - - Chúng ta có thể thay "\verb-:=-" bởi một hay một chuỗi các kí tự khác, chẳng hạn "\verb-toto-", bằng cách định nghĩa lại macro \verbinline-\STnumericfieldmarker- như sau:\par\smallskip{\centering - \verbinline-\renewcommand\STnumericfieldmarker{toto}-\par\smallskip} - -\end{itemize}\parindent0pt\bigskip -Một khi vùng số đã được tính, nó sẽ được thay thế bởi giá trị của nó trong bảng. - -Cần lưu ý rằng "\verb-:={vùng số}-" có thể nằm giữa hai dấu ngoặc nhọn. Ví dụ, trong một ô ta có thể viết \verb-\textbf{:={a1+1}}-. Nếu vùng số của ô \falseverb{a1} là 5 thì ô chứa công thức cuối cùng sẽ chứa giá trị là \verb-\textbf{6}-. - -Ví dụ đơn giản sau đây sẽ giúp các bạn hiểu rõ hơn: - -\begin{lstlisting}[escapechar=!] -\begin{spreadtab}{{tabular}{|c|c||c|}}\hline -!giá trị 1! : :={50} & !giá trị 2! : :={29} & !trung bình! : \textbf{:={(a1+b1)/2}}\\\hline -\end{spreadtab} -\end{lstlisting} -\begin{center} -\begin{spreadtab}{{tabular}{|c|c||c|}}\hline -giá trị 1 : :={50} & giá trị 2 : :={29} & trung bình : \textbf{:={(a1+b1)/2}}\\\hline -\end{spreadtab} -\end{center} -Cũng cần lưu ý rằng "\verb-:={}-" định nghĩa một công thức rỗng, nó tương đương với "\verb-@-" trong một ô (ô này là ô chứa văn bản). - -\section{Định dạng bảng} -\subsection{Trở lại với hàng và đường kẻ ngang} -Để xác định điểm kết thúc của một hàng, \ST bắt buộc phải nhận ra sự xuống hàng và các đường kẻ ngang. Gói này cho phép sử dụng thêm một tham số của \verb-\\- như sau: \verb-\\[]-. - -Chúng ta có thể sử dụng một số tùy ý các đường kẻ ngang sau:\parindent2em\smallskip -\begin{itemize} - \item \verb-\hline-; - \item \verb=\cline{x-y}= trong đó \falseverb x và \falseverb y là số thứ tự của cột xuất phát và cột đến của đường kẻ; - \item \verb=\hhline{}= trong đó \verb== là kiểu đường kẻ tùy chọn (xem tài liệu của gói \href{http://www.ctan.org/tex-archive/macros/latex/required/tools/}{\texttt{\textbf{hhline}}}). -\end{itemize}\parindent0pt\medskip - -Dưới đây là một ví dụ về tam giác Pascal "ngược": -\begin{lstlisting} -\begin{spreadtab}{{tabular}{*5c}} -[0,1] & [-1,1]+[0,1] & [-1,1]+[0,1] & [-1,1]+[0,1] & [-1,1]\\[1em] -[0,1] & [-1,1]+[0,1] & [-1,1]+[0,1] & [-1,1] & \\ -[0,1] & [-1,1]+[0,1] & [-1,1] & & \\ \hline\hline -[0,1] & [-1,1] & & & \\ \cline{2-4} -1 & & & & \\ \hline -\end{spreadtab} -\end{lstlisting} -\begin{center} -\begin{spreadtab}{{tabular}{*5c}} -[0,1] & [-1,1]+[0,1] & [-1,1]+[0,1] & [-1,1]+[0,1] & [-1,1]\\[1em] -[0,1] & [-1,1]+[0,1] & [-1,1]+[0,1] & [-1,1] & \\ -[0,1] & [-1,1]+[0,1] & [-1,1] & & \\ \hline\hline -[0,1] & [-1,1] & & & \\ \cline{2-4} -1 & & & & \\ \hline -\end{spreadtab} -\end{center} - -\subsection{Ẩn một hàng hay một cột} -Thỉnh thoảng, nguyên một hàng hay một cột được sử dụng để chứa các phép tính trung gian mà ta muốn chúng không được hiển thị trong bảng. \ST sẽ giúp ta thực hiện điều này nhờ các lệnh \verbinline=\SThiderow= (ẩn hàng) và \verbinline=\SThidecol= (ẩn cột). Nếu chúng được đặt trong một ô nào đó, thì hàng hay cột chứa ô đó sẽ được ẩn đi. - -Sau đây là một ví dụ: -\begin{lstlisting}[escapechar=!] -\begin{spreadtab}{{tabular}{|r|ccc|}} -\hline -@!Giá trị của! $x$ & -1 & 0\SThidecol & 2 & 3 \\\hline -@$f(x)=2x-1$ & 2*[0,-1]-1 & 2*[0,-1]-1 & 2*[0,-1]-1 & 2*[0,-1]-1 \\ -@$g(x)=x-10$\SThiderow & [0,-2]-10 & [0,-2]-10 & [0,-2]-10 & [0,-2]-10 \\ -@$h(x)=1-x$ & 1-[0,-3] & 1-[0,-3] & 1-[0,-3] & 1-[0,-3] \\\hline -\end{spreadtab} -\end{lstlisting} -\begin{center} -\begin{spreadtab}{{tabular}{|r|ccc|}} -\hline -@ Giá trị của $x$ & -1 & 0\SThidecol & 2 & 3 \\\hline -@$f(x)=2x-1$ & 2*[0,-1]-1 & 2*[0,-1]-1 & 2*[0,-1]-1 & 2*[0,-1]-1 \\ -@$g(x)=x-10$\SThiderow & [0,-2]-10 & [0,-2]-10 & [0,-2]-10 & [0,-2]-10 \\ -@$h(x)=1-x$ & 1-[0,-3] & 1-[0,-3] & 1-[0,-3] & 1-[0,-3] \\\hline -\end{spreadtab} -\end{center} -Chúng ta đã ẩn đi hàng chứa $g(x)$ và cột chứa giá trị 0 (cột thứ ba). - -Cần nhớ rằng môi trường bảng (trong ví dụ trên là \verb-tabular-) sẽ không đọc được các hàng và các cột ẩn, điều đó giải thích tại sao trong phần định nghĩa môi trường bảng, chúng ta chỉ có 4 cột (\falseverb{|r|ccc|}), trong khi đó \ST lại làm việc với 5 cột. - -Để thấy sự khác biệt, chúng ta sẽ lấy lại ví dụ trên nhưng không ẩn một hàng hay cột nào: - -\begin{center} -\begin{spreadtab}{{tabular}{|r|cccc|}} -\hline -@ Giá trị của $x$ & -1 & 0 & 2 & 3 \\\hline -@$f(x)=2x-1$ & 2*[0,-1]-1 & 2*[0,-1]-1 & 2*[0,-1]-1 & 2*[0,-1]-1 \\ -@$g(x)=x-10$ & [0,-2]-10 & [0,-2]-10 & [0,-2]-10 & [0,-2]-10 \\ -@$h(x)=1-x$ & 1-[0,-3] & 1-[0,-3] & 1-[0,-3] & 1-[0,-3] \\\hline -\end{spreadtab} -\end{center} - -\subsection{Lưu giá trị của một ô} -Nhiều lúc chúng ta cần giá trị của một ô để sử dụng bên ngoài một công thức hay thậm chí là bên ngoài của bảng. Ta sử dụng cú pháp sau: -\begin{center} -\verbinline-\STsavecell-\verb-{}{}- -\end{center} -Cú pháp này cho phép lưu giá trị của ô có \verb-- trong \verb--. \emph{Chú ý}: \ST sẽ không kiểm tra là \verb-- đã được định nghĩa trước đó hay chưa. - -Chúng ta chỉ có thể sử dụng vị trí \emph{tuyệt đối} bởi vì cú pháp trên được đặt trong phần tùy chọn của môi trường \verbinline-spreadtab-. - -Ta có thể lưu cùng một lúc nhiều ô, chỉ cần đặt trong phần tùy chọn một số tương ứng lệnh \verbinline-\STsavecell-. - -\begin{lstlisting}[escapechar=!] -\begin{spreadtab}[\STsavecell\hhh{b3}\STsavecell\mmm{c3}\STsavecell\sss{d3}]{{tabular}{|rc|}}\hline -@ !Vận tốc! (km/h) &\SThidecol&\SThidecol&\SThidecol& 35 \\ -@ !Khoảng cách! (km) & & & & 180\\\hline -@ !Thời gian! (h min s) & trunc(e2/e1,0) & trunc(60*(e2/e1-b3),0) & trunc(3600*(e2/e1-b3)-60*c3,1) &@\hhh\ h \mmm\ min \sss\ s\\\hline -\end{spreadtab}\par\medskip -!Phải mất ít nhất! \hhh\ !giờ! -\end{lstlisting} -\begin{center} -\begin{spreadtab}[\STsavecell\hhh{b3}\STsavecell\mmm{c3}\STsavecell\sss{d3}]{{tabular}{|rc|}}\hline -@Vận tốc (km/h) &\SThidecol&\SThidecol&\SThidecol& 35 \\ -@Khoảng cách (km) & & & & 180\\\hline -@Thời gian (h min s) & trunc(e2/e1,0) & trunc(60*(e2/e1-b3),0) & trunc(3600*(e2/e1-b3)-60*c3,1) &@\hhh\ h \mmm\ min \sss\ s\\\hline -\end{spreadtab}\par\medskip -Phải mất ít nhất \hhh\ giờ -\end{center} - -\subsection{Sử dụng \ttfamily\textbackslash multicolumn} -Gói \ST tương thích với cú pháp -\begin{center} -\verbinline=\multicolumn{}=\verb={}{}= -\end{center} -Cú pháp này cho phép hợp nhất \falseverb{} ô thành một ô có kiểu và nội dung được xác định trong phần tùy chọn. - -Bảng dưới đây chứa một số ô đã được hợp nhất với nhau, các ô của nó sẽ có vị trí như sau đối với \ST: -\begin{center} -\ttfamily -\begin{tabular}{|*7{c|}}\hline -a1&b1&c1&d1&e1&f1&g1\\\hline -a2&\multicolumn{2}{l|}{b2}&d2&e2&f2&g2\\\hline -\multicolumn{3}{|l|}{a3}&d3&\multicolumn{2}{l|}{e3}&g3\\\hline -\end{tabular} -\end{center} -Như vậy, ô ở ngay sau ô hợp nhất sẽ có số thứ tự phụ thuộc vào số ô đã được hợp nhất. - -Ở hàng cuối cùng, các ô \falseverb{a3}, \falseverb{b3} và \falseverb{c3} được hợp nhất với nhau, và nếu ô \falseverb{a3} chứa công thức thì các ô \falseverb{b3} và \falseverb{c3} sẽ \emph{không tồn tại} đối với \ST: chúng ta không thể tham chiếu đến chúng từ một ô nào khác. - -Trong ví dụ sau đây, mỗi số ở hàng trên sẽ bằng tích của hai số ngay phía dưới của nó: -\begin{lstlisting} -\begin{spreadtab}{{tabular}{*6c}} -\cline{2-5} - & \multicolumn{2}{|c|}{:={a2*c2}} & \multicolumn{2}{c|}{:={c2*e2}} & \\ -\hline -\multicolumn{2}{|c}{:=8} & \multicolumn{2}{|c}{:=7} & \multicolumn{2}{|c|}{:=6}\\ -\hline -&&&&& -\end{spreadtab} -\end{lstlisting} -\begin{center} -\begin{spreadtab}{{tabular}{*6c}} -\cline{2-5} - & \multicolumn{2}{|c|}{:={a2*c2}} & \multicolumn{2}{c|}{:={c2*e2}} & \\ -\hline -\multicolumn{2}{|c}{:=8} & \multicolumn{2}{|c}{:=7} & \multicolumn{2}{|c|}{:=6}\\ -\hline -&&&&& -\end{spreadtab} -\end{center} - -\subsection{Gói \ttfamily fp} -Như đã nói ở trên, tất cả các phép tính đều được thực hiện bởi gói \href{http://www.ctan.org/tex-archive/macros/latex/contrib/fp/}{\texttt{\textbf{fp}}} và macro \falseverb{\FPeval}\footnote{Cả hai khái niệm "trung tố" (infix) và "hậu tố" (postfix) đều được chấp nhận bởi {\ttfamily\string\FPeval}, do đó các công thức trong \ST có thể được viết dưới cả hai dạng trên.} của nó. Gói này cung cấp một khả năng tính toán rất mạnh cho \TeX{} và còn được trang bị tất cả các hàm số thông dụng. Các phép tính được tính với độ chính xác đến $10^{-18}$, do đó kết quả sẽ được hiển thị đến 18 chữ số thập phân nếu nó không tròn ! Tất nhiên trong hầu hết các trường hợp, 18 chữ số là quá nhiều và ta muốn giảm bớt. - -Có nhiều cách để giải quyết vấn đề này:\parindent2em\smallskip -\begin{itemize} - \item có thể dùng gói \href{http://www.ctan.org/tex-archive/macros/latex/contrib/numprint/}{\texttt{\textbf{numprint}}} để quản lí việc hiển thị kết quả; - \item sử dụng hàm \verb-round(kết quả,n)- để làm tròn \verb=kết quả= đến \verb=n= chữ số thập phân; - \item ta cũng có thể sử dụng macro \verbinline-\STautoround- của \ST, tham số của nó là số chữ số thập phân cần hiển thị. Nếu không có tham số (mặc định), nó sẽ không làm tròn kết quả. -\end{itemize}\parindent0pt\medskip - -Ví dụ sau là bảng chứa các số nguyên từ 1 đến 7 và các nghịch đảo của chúng, được làm tròn đến $10^{-6}$: -\begin{lstlisting} -\STautoround{6} -\begin{spreadtab}{{tabular}{|l|*7{>{\centering\arraybackslash}m{1.35cm}|}}} -\hline -@$x$ & 1 & 2 & 3 & 4 & 5 & 6 & 7 \\\hline -@$x^{-1}$& 1/b1 & 1/c1 & 1/d1 & 1/e1 & 1/f1 & 1/g1 & 1/h1\\\hline -\end{spreadtab} -\end{lstlisting} -\begin{center} -\STautoround{6} -\begin{spreadtab}{{tabular}{|l|*7{>{\centering\arraybackslash}m{1.35cm}|}}} -\hline -@$x$ & 1 & 2 & 3 & 4 & 5 & 6 & 7 \\\hline -@$x^{-1}$& 1/b1 & 1/c1 & 1/d1 & 1/e1 & 1/f1 & 1/g1 & 1/h1\\\hline -\end{spreadtab} -\end{center} - -\section{Macro hàm} -Bởi vì tất cả các phép tính đều được thực hiện bởi gói \href{http://www.ctan.org/tex-archive/macros/latex/contrib/fp/}{\texttt{\textbf{fp}}} nên các hàm số trong các công thức phải được "hiểu" bởi \falseverb{fp}. Tuy số lượng các hàm số cung cấp bởi \falseverb{fp} là rất lớn, nó vẫn không đủ để thực hiện các phép tính trong bảng. Đó là lí do tại sao cần phải xây dựng các macro hàm. Các macro này được tạo ra nhờ vào các hàm sẵn có của \falseverb{fp}. - -Nhận xét quan trọng: có thể lấy hàm hợp lẫn nhau của các macro hàm, và các tham số của chúng có thể chứa các phép toán cũng như hàm số của \falseverb{fp}. - -\subsection{Macro hàm toán học} -\subsubsection{Hàm tổng} -Hàm "\verbinline=sum=" cho phép lấy tổng của một hay nhiều mảng ô và có cú pháp: -\begin{center} -\verbinline=sum=\verb=(;;...;)= -\end{center} -trong đó một mảng :\parindent2em\smallskip -\begin{itemize} - \item hoặc là một ô riêng biệt, chẳng hạn "\falseverb{a1}" hay "\falseverb{[2,1]}"; - \item hoặc là một miền chữ nhật giới hạn bởi một ô phía trên bên trái và một ô phía dưới bên phải, nó được nhập vào như sau: "\verb=<ô 1>:<ô 2>=", với điều kiện là "\verb=<ô 1>=" phải ở \emph{trước} "\verb=<ô 2>=" khi chúng ta đi từ trên xuống dưới và từ trái sang phải. - - Ví dụ về mảng ô: "\falseverb{a2:d5}", "\falseverb{[-1,-1]:[2,3]}", "\falseverb{b4:[5,1]}". -\end{itemize}\parindent0pt\medskip - -Trong các mảng, những ô trống hoặc chỉ chứa văn bản được xem như chứa giá trị 0. Các ô bị nhập vào bởi \verbinline-\multicolumn- cũng vậy. - -Vị trí tương đối và tuyệt đối có thể được sử dụng cùng nhau. Ví dụ sau đây tính tổng các hệ số của tam giác Pascal: - -\begin{minipage}{0.75\linewidth} -\begin{lstlisting}[escapechar=!] -\begin{spreadtab}{{tabular}{*5c}} -\multicolumn{5}{c}{!Tổng! = :={sum(a2:e6)}}\\ -[0,1] & [-1,1]+[0,1] & [-1,1]+[0,1] & [-1,1]+[0,1] & [-1,1] \\ -[0,1] & [-1,1]+[0,1] & [-1,1]+[0,1] & [-1,1] & \\ -[0,1] & [-1,1]+[0,1] & [-1,1] & & \\ -[0,1] & [-1,1] & & & \\ -1 & & & & -\end{spreadtab} -\end{lstlisting} -\end{minipage}% -\begin{minipage}{0.25\linewidth} -\centering -\begin{spreadtab}{{tabular}{*5c}} -\multicolumn{5}{c}{Tổng=:={sum(a2:e6)}}\\ -[0,1] & [-1,1]+[0,1] & [-1,1]+[0,1] & [-1,1]+[0,1] & [-1,1] \\ -[0,1] & [-1,1]+[0,1] & [-1,1]+[0,1] & [-1,1] & \\ -[0,1] & [-1,1]+[0,1] & [-1,1] & & \\ -[0,1] & [-1,1] & & & \\ -1 & & & & -\end{spreadtab} -\end{minipage}% - -\subsubsection{Hàm giai thừa} -Macro hàm \verbinline=fact()= cho phép tính giai thừa của tham số \verb=n=, trong đó \verb=n= là một số nguyên trong khoảng từ 0 đến 18\footnote{Đối với \falseverb{fp}, số lớn nhất là $10^{18}-1$. Giai thừa của 19 vượt quá số này.}. \verb=n= có thể là một tham chiếu đến một ô chứa một số nguyên. - -Bảng sau chứa giai thừa của các số từ 0 đến 8: -\begin{lstlisting} -\begin{spreadtab}{{tabular}{*9c}} - 0 & 1 & 2 & 3 & 4 & 5 & 6 & 7 &8\\\hline -fact(a1)&fact(b1)&fact(c1)&fact(d1)&fact(e1)&fact(f1)&fact(g1)&fact(h1)&fact(i1) -\end{spreadtab} -\end{lstlisting} -\begin{center} -\begin{spreadtab}{{tabular}{*9c}} - 0 & 1 & 2 & 3 & 4 & 5 & 6 & 7 &8\\\hline -fact(a1)&fact(b1)&fact(c1)&fact(d1)&fact(e1)&fact(f1)&fact(g1)&fact(h1)&fact(i1) -\end{spreadtab} -\end{center} - -\subsubsection{Macro hàm \ttfamily sumprod} -Hàm \verbinline=sumprod= cho phép lấy tích của các phần tử tương ứng của hai hay nhiều mảng, sau đó tính tổng của các tích này. Cú pháp: -\begin{center} -\verbinline{sumprod}\verb=(;;...;)= -\end{center} -Tất cả các mảng của hàm phải có cùng kích thước. - -Ví dụ đơn giản sau đây tính tuổi trung bình của một nhóm trẻ em từ 10 đến 15 tuổi: -\begin{lstlisting}[escapechar=!] -\begin{spreadtab}{{tabular}{r*6c}} -@!Tuổi! & 10 & 11 & 12 & 13 & 14 & 15\\ -@!Số lượng! & 5 & 8 & 20 & 55 & 9 & 3\\\hline -@!Trung bình!&\multicolumn{6}{l}{:={sumprod(b1:g1;b2:g2)/sum(b2:g2)}} -\end{spreadtab} -\end{lstlisting} -\begin{center} -\begin{spreadtab}{{tabular}{r*6c}} -@Tuổi & 10 & 11 & 12 & 13 & 14 & 15\\ -@Số lượng & 5 & 8 & 20 & 55 & 9 & 3\\\hline -@Trung bình&\multicolumn{6}{l}{:={sumprod(b1:g1;b2:g2)/sum(b2:g2)}} -\end{spreadtab} -\end{center} -Cũng giống như macro hàm \verbinline-sum-, các ô chứa văn bản hoặc được nhập bởi \verbinline-\multicolumn- được xem như có giá trị 0. - -\subsubsection{Số ngẫu nhiên} -Macro hàm \verbinline-randint- và \verbinline-rand- trả về một số ngẫu nhiên. - -Chú ý: giá trị ngẫu nhiên này phụ thuộc vào thời điểm biên dịch của tài liệu. Nếu chúng ta muốn nhận được những giá trị không phụ thuộc vào thời điểm biên dịch, cần định nghĩa lại macro \verb-\ST@seed- và gán cho \verb-\FPseed- một giá trị nguyên: - -\begin{lstlisting}[backgroundcolor=\color{ST@codebckgcolor},escapechar=!] -\makeatletter -\renewcommand\ST@seed{} -\makeatletter -\FPseed=27% !chẳng hạn, hoặc một số nguyên bất kì nào khác! -\end{lstlisting} -Macro hàm \verbinline-randint- trả về một \emph{số nguyên} phụ thuộc vào tham số. Cú pháp như sau: -\begin{center} -\verbinline=randint=\verb=([,])= -\end{center} -trong đó \verb== là một tham số nguyên (mặc định bằng 0). Số nguyên ngẫu nhiên được trả về sẽ nằm trong đoạn \verb=[;]=. - -Macro hàm \verbinline-rand()- trả về một số thập phân ngẫu nhiên giữa 0 và 1: -\begin{lstlisting}[escapechar=!] -\STautoround{6} -\begin{spreadtab}{{tabular}{|l|cccc|}}\hline -@!Số thuộc đoạn! [0;1] &rand() &rand() &rand() &rand() \\ -@!Số thuộc đoạn! [-5;5] &randint(-5,5) &randint(-5,5) &randint(-5,5) &randint(-5,5)\\ -@!Số thuộc đoạn! [0;20] &randint(20) &randint(20) &randint(20) &randint(20) \\ -\hline -\end{spreadtab} -\end{lstlisting} -\begin{center} -\STautoround{6} -\begin{spreadtab}{{tabular}{|l|cccc|}}\hline -@Số thuộc đoạn [0;1] &rand() &rand() &rand() &rand() \\ -@Số thuộc đoạn [-5;5] &randint(-5,5) &randint(-5,5) &randint(-5,5) &randint(-5,5)\\ -@Số thuộc đoạn [0;20] &randint(20) &randint(20) &randint(20) &randint(20) \\ -\hline -\end{spreadtab} -\end{center} - -\subsection{Các macro hàm kiểm tra} -Có ba macro hàm kiểm tra, chúng có cú pháp như sau: -\begin{center} -\verbinline=ifeq=\verb=(,,,)=\par -\verbinline=ifgt=\verb=(,,,)=\par -\verbinline=iflt=\verb=(,,,)= -\end{center} -Phép so sánh được thực hiện giữa \verb-- và \verb--:\parindent2em\smallskip -\begin{itemize} - \item kiểm tra đẳng thức với \verbinline-ifeq-: \verb-- = \verb-- ? - \item kiểm tra tính lớn hơn nghiêm ngặt với \verbinline-ifgt- : \verb-- > \verb-- ? - \item kiểm tra tính nhỏ hơn nghiêm ngặt với \verbinline-iflt- : \verb-- < \verb-- ? -\end{itemize}\parindent0pt\medskip - -Nếu phép kiểm tra là đúng thì \verb-- được trả về, nếu không thì \verb-- được trả về. - -Ví dụ sau đây xác định một vài giá trị của hàm số -$f(x)=\begin{cases} -10 &\text{nếu }x<1\\ -0 &\text{nếu }x=1\\ --10 &\text{nếu }x>1 -\end{cases} -$ -\begin{lstlisting} -\begin{spreadtab}{{tabular}{|*2c|}}\hline -@$x$ & @$f(x)$ \\\hline --0.5 & iflt([-1,0],1,10,ifeq([-1,0],1,0,-10))\\ -[0,-1]+0.5 & iflt([-1,0],1,10,ifeq([-1,0],1,0,-10))\\ -[0,-1]+0.5 & iflt([-1,0],1,10,ifeq([-1,0],1,0,-10))\\ -[0,-1]+0.5 & iflt([-1,0],1,10,ifeq([-1,0],1,0,-10))\\ -[0,-1]+0.5 & iflt([-1,0],1,10,ifeq([-1,0],1,0,-10))\\ -[0,-1]+0.5 & iflt([-1,0],1,10,ifeq([-1,0],1,0,-10))\\ -[0,-1]+0.5 & iflt([-1,0],1,10,ifeq([-1,0],1,0,-10))\\\hline -\end{spreadtab} -\end{lstlisting} -\begin{center} -\begin{spreadtab}{{tabular}{|*2c|}}\hline -@$x$ & @$f(x)$ \\\hline --0.5 & iflt([-1,0],1,10,ifeq([-1,0],1,0,-10))\\ -[0,-1]+0.5 & iflt([-1,0],1,10,ifeq([-1,0],1,0,-10))\\ -[0,-1]+0.5 & iflt([-1,0],1,10,ifeq([-1,0],1,0,-10))\\ -[0,-1]+0.5 & iflt([-1,0],1,10,ifeq([-1,0],1,0,-10))\\ -[0,-1]+0.5 & iflt([-1,0],1,10,ifeq([-1,0],1,0,-10))\\ -[0,-1]+0.5 & iflt([-1,0],1,10,ifeq([-1,0],1,0,-10))\\ -[0,-1]+0.5 & iflt([-1,0],1,10,ifeq([-1,0],1,0,-10))\\\hline -\end{spreadtab} -\end{center} - - -\section{Một số lưu ý đặc biệt} -\subsection{Định nghĩa lại lệnh vẽ đường kẻ ngang} -Chúng ta có thể thử định nghĩa một lệnh để vẽ một đường kẻ ngang kép chẳng hạn: -\begin{center} -\verbinline-\newcommand\dline{\hline\hline}- -\end{center} -rồi sau đó sử dụng nó trong một bảng tính số hạng của dãy Fibonacci: -\begin{center} -\newcommand\dline{\hline\hline} -\begin{spreadtab}{{tabular}{*7c}} -0 & 1 & 2 & 3 & 4 & 5 & 6 \\\dline -:={1} & 1 & a2+b2 & b2+c2 & c2+d2 & d2+e2 & e2+f2 -\end{spreadtab} -\end{center} -Nhưng khi nhập vào đoạn mã sau -\begin{lstlisting} -\newcommand\dline{\hline\hline} -\spreadtab{\begin{tabular}{*7c}} -{ -0 & 1 & 2 & 3 & 4 & 5 & 6 \\\dline -1 & 1 & a2+b2 & b2+c2 & c2+d2 & d2+e2 & e2+f2 -} -\end{lstlisting} -và biên dịch thì hệ thống báo lỗi:\par -\hfill\falseverb{! Improper alphabetic constant.}\hfill\null - -Lí do rất đơn giản, đó là \ST \emph{không hiểu} được lệnh \verb-\dline- và do đó không xem nó như một đường kẻ ngang, như vậy nó được xem như thuộc \emph{ô đầu tiên của hàng tiếp theo}. Với \ST, ô \falseverb{b1} chứa:\par -\hfill\falseverb{\dline 1}\hfill\null - -Do không có \verb-@- hay \verb-:={...}-, \verb-\FPeval- cố gắng tính giá trị của ô, và tất nhiên là thất bại ! - -Để có thể biên dịch mà không bị lỗi, cần phải có một công thức trong ô \falseverb{b1}: -\begin{lstlisting} -\newcommand\dline{\hline\hline} -\begin{spreadtab}{{tabular}{*7c}} -0 & 1 & 2 & 3 & 4 & 5 & 6 \\\dline -:={1} & 1 & a2+b2 & b2+c2 & c2+d2 & d2+e2 & e2+f2 -\end{spreadtab} -\end{lstlisting} -\begin{center} -\newcommand\dline{\hline\hline} -\begin{spreadtab}{{tabular}{*7c}} -0 & 1 & 2 & 3 & 4 & 5 & 6 \\\dline -:={1} & 1 & a2+b2 & b2+c2 & c2+d2 & d2+e2 & e2+f2 -\end{spreadtab} -\end{center} - -\subsection{Sử dụng cùng lúc {\ttfamily\textbackslash multicolumn} và \ttfamily\textbackslash SThidecol} -Trước hết, thông thường việc sử dụng cùng lúc \verbinline|\multicolumn| và \verbinline-\SThiderow- là không thể, và đa số người sử dụng sẽ không rơi vào hoàn cảnh này, và do đó, không cần đọc mục này. - -Nhưng nếu bạn đọc nào muốn hiểu rõ vấn đề, chúng ta hãy cùng xem. Một cột được ẩn đi không được chứa một ô có lệnh \verbinline-\multicolumn-, nhưng chuyện gì sẽ xảy ra nếu ta rơi vào trường hợp này ? - -Nói chung, hệ thống sẽ không báo lỗi, nhưng các vị trí và tham chiếu sẽ bị xáo trộn ở hàng chứa \verbinline-\multicolumn-\ldots. - -Hãy lấy một ví dụ, trong bảng sau, ta sẽ hợp nhất các ô từ \falseverb{b2} đến \falseverb{h2} và ta muốn ẩn đi các cột \falseverb{c}, \falseverb{d} và \falseverb{f} (màu xám): -\begin{center} -\ttfamily -\begin{tabular}{|c|c|c|c|c|c|c|c|c|c|} -\hline - a1 & b1 & \cellcolor[gray]{0.6}c1 & \cellcolor[gray]{0.6}d1 & e1 & \cellcolor[gray]{0.6}f1 & g1 & h1 & i1 & j1\\\hline - a2 & \multicolumn1c{b2} & \multicolumn1{>{\cellcolor[gray]{0.6}}c}{} & \multicolumn1{>{\cellcolor[gray]{0.6}}c}{} & \multicolumn1c{} & \multicolumn1{>{\cellcolor[gray]{0.6}}c}{} & \multicolumn1{c}{} & \multicolumn1{c|}{} & i2 & j2\\\hline -\end{tabular} -\end{center} -Có 4 ô \emph{ẩn} được hợp nhất, do đó ta sẽ nhập vào \verbinline-\multicolumn{4}-, bởi vì khi đếm số ô để hợp nhất, ta sẽ trừ ra các ô đã được ẩn. - -Bây giờ, nếu đếm 4 chữ cái kể từ chữ cái \falseverb{b} ta sẽ đi đến chữ cái \falseverb{e}: ta được "đoạn cột \falseverb{b-e}". Đoạn này chứa $\underline{\color{red}{2}}$ cột ẩn (\falseverb c và \falseverb d) và không chứa $\underline{\color{blue}{1}}$ cột ẩn khác (\falseverb f). Hai giá trị này là rất quan trọng để hiểu được phần tiếp theo, trong trường hợp tổng quát ta hãy kí hiệu chúng là $\underline{\color{red}{a}}$ và $\underline{\color{blue}{b}}$. - -Cần tuân thủ các quy tắc sau :\parindent2em\smallskip -\begin{itemize} - \item phải thêm vào $b$ kí tự "\verb-&-" sau \verbinline-\multicolumn- (con số này là 1 với ví dụ trên); - \item dịch chữ cái thứ tự cột của các ô sau \verbinline-\multicolumn- $a$ chữ cái về phía đầu của bảng chữ cái. Đối với ví dụ trên, nếu ta muốn tham chiếu đến ô "\falseverb{i2}", cần phải nhập vào \falseverb{g2}. -\end{itemize}\parindent0pt\medskip - -Trong ví dụ sau, mỗi số ở hàng dưới sẽ bằng tổng của số ở hàng trên và 1. Bảng này có cấu trúc tương tự như ví dụ trước: $a=2$ và $b=1$. Chú ý rằng ta sẽ thêm vào một kí tự "\textcolor{red}{\texttt{\&}}" bởi vì $b=1$. -\begin{lstlisting}[escapechar=Z] -\begin{spreadtab}{{tabular}{|*{7}{c|}}} -\hline -1 & 2 & \SThidecol3 & \SThidecol4 & 5& \SThidecol6 & 7& 8& 9 & 10 \\\hline -a1+1& \multicolumn4{l|}{:={b1+1}}Z\ttfamily\color{red}\rlap\&Z & i1+1 & j1+1\\\hline -a2+1& b2+1 & & & & & & & g2+1 & h2+1\\\hline -\end{spreadtab} -\end{lstlisting} -\begin{center} -\begin{spreadtab}{{tabular}{|*{7}{c|}}} -\hline -1 & 2 & \SThidecol3 & \SThidecol4 & 5& \SThidecol6 & 7& 8& 9 & 10 \\\hline -a1+1& \multicolumn4{l|}{:={b1+1}}& & i1+1 & j1+1\\\hline -a2+1& b2+1 & & & & & & & g2+1 & h2+1\\\hline -\end{spreadtab} -\end{center} -Sau đây là một ví dụ khác tương tự, ta sẽ ẩn một cột (cột \falseverb d): $a=1$ và $b=0$. -\begin{lstlisting} -\begin{spreadtab}{{tabular}{|*{9}{c|}}} -\hline -1 & 2 & 3 & \SThidecol4 & 5 & 6 & 7 & 8 & 9 & 10 \\\hline -a1+1& \multicolumn6{l|}{:={b1+1}} & i1+1 & j1+1\\\hline -a2+1& b2+1 & & & & & & & h2+1 & i2+1\\\hline -\end{spreadtab} -\end{lstlisting} -\begin{center} -\begin{spreadtab}{{tabular}{|*{9}{c|}}} -\hline -1 & 2 & 3 & \SThidecol4 & 5 & 6 & 7 & 8 & 9 & 10 \\\hline -a1+1& \multicolumn6{l|}{:={b1+1}} & i1+1 & j1+1\\\hline -a2+1& b2+1 & & & & & & & h2+1 & i2+1\\\hline -\end{spreadtab} -\end{center} - -\subsection{Các thông báo lỗi} -\ST sẽ dừng biên dịch và thông báo lỗi trong các trường hợp sau:\parindent2em\smallskip -\begin{itemize} - \item để tính giá trị của một ô, chúng ta tính các ô mà nó tham chiếu đến; với các ô này chúng ta lại làm tương tự, và nếu có một ô nào đó tham chiếu đến ô ban đầu (tham chiếu vòng), hệ thống sẽ báo lỗi và hiển thị trong tin nhắn báo lỗi vòng tham chiếu này; - \item một công thức chứa một tham chiếu đến một ô rỗng hoặc chỉ chứa văn bản; - \item một ô tham chiếu đến một ô không xác định (bên ngoài giới hạn của bảng); - \item một ô tham chiếu đến một ô bị hợp nhất bởi \verbinline-\multicolumn-; - \item một ví trí tương đối không đúng cú pháp. -\end{itemize}\parindent0pt\medskip - -\ST có thể thông báo lỗi trong tập tin \verb-log-. Lệnh \verbinline-\STmessage- với tham số \verb-true- hoặc \verb-false- cho phép thực hiện hay không việc báo lỗi này (\verb-true- theo mặc định). - -Chúng ta hãy lấy một ví dụ đơn giản: - -\begin{minipage}{0.65\linewidth} -\begin{lstlisting} -\begin{spreadtab}{{tabular}{|cccc|c|}}\hline -b1+1 & c1+1 & d1+1 & 10 & a1+b1+c1+d1\\\hline -\end{spreadtab} -\end{lstlisting} -\end{minipage}% -\begin{minipage}{0.35\linewidth} -\centering -\begin{spreadtab}{{tabular}{|cccc|c|}}\hline -b1+1 & c1+1 & d1+1 & 10 & a1+b1+c1+d1\\\hline -\end{spreadtab} -\end{minipage} - -Việc tiến hành xây dựng bảng ở đây rất đơn giản. Sau đây là một số thông tin cho bởi \ST: -\begin{lstlisting} -[spreadtab] New spreadtab ({tabular}{|cccc|c|}) -* reading tab: ok -* computing formulas: - cell A1-B1-C1 - cell B1 - cell C1 - cell D1 - cell E1 -* building tab: ok -[spreadtab] End of spreadtab -\end{lstlisting} -Môi trường bảng cho bởi người sử dụng được đặt trong các dấu ngoặc (trong trường hợp này là \verbinline-{tabular}{|cccc|c|}-). Chúng ta thấy rõ 3 bước cần thiết của \ST (bắt đầu bởi các dấu sao) để thực hiện nhiệm vụ của nó: đọc bảng, tính các công thức rồi sau đó xây dựng lại và hiển thị bảng. - -Ở bước thứ hai, các ô được đánh giá từ trên xuống dưới, từ trái sang phải: ta thấy rằng \ST bắt đầu tính ô \falseverb{A1}. Để làm điều đó, nó phải tính \falseverb{B1} trước, và trước đó nữa là \falseverb{C1}. Vì \falseverb{C1} chỉ phụ thuộc vào \falseverb{D1} (có giá trị bằng 10) nên nó có thể được tính. - -Các hàng tiếp theo chỉ có một ô, nghĩa là \ST tính các ô này trong khi chúng đã có sẵn giá trị hoặc tham chiếu đến những ô đã được tính. - -\section{Một số ví dụ} -Chúng ta hãy kết thúc bằng một vài ví dụ thú vị ! - -Để biết được kết quả nào đã được tính, chỉ những số không được tính (cho bởi người dùng) sẽ được in đỏ. Trong các ví dụ này, rất nhiều kĩ năng và gói (chủ yếu là \verb-numprint- và các cột "N" của nó để canh thẳng hàng các dấu phẩy thập phân) đã được sử dụng để nhận được những kết quả, nhiều hay ít, thỏa mãn mỹ quan của chúng ta. Mã nhập vào đôi khi khá nặng nề, nhưng đây không phải là những ví dụ cơ bản, mà là những bảng được "trang điểm" tỉ mỉ ! - -\subsection{Lại là tam giác Pascal} -\begin{lstlisting} -\begin{spreadtab}{{tabular}{*7r}} -[0,1] & [-1,1]+[0,1] & [-1,1]+[0,1] & [-1,1]+[0,1] & [-1,1]+[0,1] & [-1,1]+[0,1] & [-1,1]\\ -[0,1] & [-1,1]+[0,1] & [-1,1]+[0,1] & [-1,1]+[0,1] & [-1,1]+[0,1] & [-1,1] & \\ -[0,1] & [-1,1]+[0,1] & [-1,1]+[0,1] & [-1,1]+[0,1] & [-1,1] & & \\ -[0,1] & [-1,1]+[0,1] & [-1,1]+[0,1] & [-1,1] & & & \\ -[0,1] & [-1,1]+[0,1] & [-1,1] & & & & \\ -[0,1] & [-1,1] & & & & & \\ -\color{red}:={1}& & & & & & -\end{spreadtab} -\end{lstlisting} -\begin{center} -\begin{spreadtab}{{tabular}{*7r}} -[0,1] & [-1,1]+[0,1] & [-1,1]+[0,1] & [-1,1]+[0,1] & [-1,1]+[0,1] & [-1,1]+[0,1] & [-1,1]\\ -[0,1] & [-1,1]+[0,1] & [-1,1]+[0,1] & [-1,1]+[0,1] & [-1,1]+[0,1] & [-1,1] & \\ -[0,1] & [-1,1]+[0,1] & [-1,1]+[0,1] & [-1,1]+[0,1] & [-1,1] & & \\ -[0,1] & [-1,1]+[0,1] & [-1,1]+[0,1] & [-1,1] & & & \\ -[0,1] & [-1,1]+[0,1] & [-1,1] & & & & \\ -[0,1] & [-1,1] & & & & & \\ -\color{red}:={1}& & & & & & -\end{spreadtab} -\end{center} - -\subsection{Chuỗi hội tụ} -Chuỗi mà chúng ta sẽ xét đến là khai triển giới hạn của hàm số mũ: -\[ -\forall x\in \mathbf{R}\qquad e^x=\sum_{k=0}^\infty\frac{x^k}{k!} -\] -Bảng sau minh họa "tốc độ" hội tụ ngày càng tăng theo bậc khai triển giới hạn tại \numprint{0.5}. -\begin{lstlisting}[escapechar=M] -\STautoround{15} -\begin{spreadtab}[\STsavecell\xvalue{a1}]{{tabular}{cN{2}{15}}} -\multicolumn{2}{c}{MHội tụ tạiM $x=\color{red}{\numprint{:={0.5}}}$}\\[1.5ex] -@$n$ & e^a1\SThidecol & \hfill{@ $\displaystyle e^{\numprint\xvalue}-\sum_{k=0}^n\frac{\numprint\xvalue^k}{k!}$}\hfill\\[3ex]\hline -\color{red}:={0}& a1^[-1,0]/fact([-1,0]) & b2-[-1,0] \\ - [0,-1]+1 & a1^[-1,0]/fact([-1,0])+[0,-1] & b2-[-1,0] \\ - [0,-1]+1 & a1^[-1,0]/fact([-1,0])+[0,-1] & b2-[-1,0] \\ - [0,-1]+1 & a1^[-1,0]/fact([-1,0])+[0,-1] & b2-[-1,0] \\ - [0,-1]+1 & a1^[-1,0]/fact([-1,0])+[0,-1] & b2-[-1,0] \\ - [0,-1]+1 & a1^[-1,0]/fact([-1,0])+[0,-1] & b2-[-1,0] \\ - [0,-1]+1 & a1^[-1,0]/fact([-1,0])+[0,-1] & b2-[-1,0] \\ - [0,-1]+1 & a1^[-1,0]/fact([-1,0])+[0,-1] & b2-[-1,0] \\ - [0,-1]+1 & a1^[-1,0]/fact([-1,0])+[0,-1] & b2-[-1,0] \\ - [0,-1]+1 & a1^[-1,0]/fact([-1,0])+[0,-1] & b2-[-1,0] \\\hline -\end{spreadtab} -\end{lstlisting} - -\begin{center} -\STautoround{15} -\begin{spreadtab}[\STsavecell\xvalue{a1}]{{tabular}{cN{2}{15}}} -\multicolumn{2}{c}{Hội tụ tại $x=\color{red}{\numprint{:={0.5}}}$}\\[1.5ex] -@$n$ & e^a1\SThidecol & \hfill{@ $\displaystyle e^{\numprint\xvalue}-\sum_{k=0}^n\frac{\numprint\xvalue^k}{k!}$}\hfill\\[3ex]\hline -\color{red}:={0}& a1^[-1,0]/fact([-1,0]) & b2-[-1,0] \\ - [0,-1]+1 & a1^[-1,0]/fact([-1,0])+[0,-1] & b2-[-1,0] \\ - [0,-1]+1 & a1^[-1,0]/fact([-1,0])+[0,-1] & b2-[-1,0] \\ - [0,-1]+1 & a1^[-1,0]/fact([-1,0])+[0,-1] & b2-[-1,0] \\ - [0,-1]+1 & a1^[-1,0]/fact([-1,0])+[0,-1] & b2-[-1,0] \\ - [0,-1]+1 & a1^[-1,0]/fact([-1,0])+[0,-1] & b2-[-1,0] \\ - [0,-1]+1 & a1^[-1,0]/fact([-1,0])+[0,-1] & b2-[-1,0] \\ - [0,-1]+1 & a1^[-1,0]/fact([-1,0])+[0,-1] & b2-[-1,0] \\ - [0,-1]+1 & a1^[-1,0]/fact([-1,0])+[0,-1] & b2-[-1,0] \\ - [0,-1]+1 & a1^[-1,0]/fact([-1,0])+[0,-1] & b2-[-1,0] \\\hline -\end{spreadtab} -\end{center} - -\subsection{Hội tụ đến tỉ số vàng} -Sau đây là định nghĩa của dãy số Fibonacci: $F_0=1\qquad F_1=1\qquad F_{n+2}=F_{n+1}+F_n$ - -Chúng ta biết rằng thương của hai số hạng liên tiếp $F_{n}$ và $F_{n-1}$ của dãy tiến đến tỉ số vàng $\varphi=\frac{1+\sqrt{5}}{2}$ và dãy $u_n=\varphi-\frac{F_n}{F_{n-1}}$ là một dãy đan dấu và hội tụ về 0. -\begin{lstlisting} -\STautoround{9} -$ -\begin{spreadtab}{{matrix}{}} -@n & @F_n & @\dfrac{F_n}{F_{n-1}} & @\varphi-\dfrac{F_n}{F_{n-1}}\\[2ex]\hline -\color{red}:=1 & \color{red}:=1 & & \\ -[0,-1]+1 & \color{red}:=1 & [-1,0]/[-1,-1] & (1+5^0.5)/2-[-1,0] \\ -[0,-1]+1 & [0,-1]+[0,-2] & [-1,0]/[-1,-1] & d3+1-[-1,0] \\ -[0,-1]+1 & [0,-1]+[0,-2] & [-1,0]/[-1,-1] & d3+1-[-1,0] \\ -[0,-1]+1 & [0,-1]+[0,-2] & [-1,0]/[-1,-1] & d3+1-[-1,0] \\ -[0,-1]+1 & [0,-1]+[0,-2] & [-1,0]/[-1,-1] & d3+1-[-1,0] \\ -[0,-1]+1 & [0,-1]+[0,-2] & [-1,0]/[-1,-1] & d3+1-[-1,0] \\ -[0,-1]+1 & [0,-1]+[0,-2] & [-1,0]/[-1,-1] & d3+1-[-1,0] \\ -[0,-1]+1 & [0,-1]+[0,-2] & [-1,0]/[-1,-1] & d3+1-[-1,0] \\ -[0,-1]+1 & [0,-1]+[0,-2] & [-1,0]/[-1,-1] & d3+1-[-1,0] \\ -[0,-1]+1 & [0,-1]+[0,-2] & [-1,0]/[-1,-1] & d3+1-[-1,0] \\ -[0,-1]+1 & [0,-1]+[0,-2] & [-1,0]/[-1,-1] & d3+1-[-1,0] \\ -[0,-1]+1 & [0,-1]+[0,-2] & [-1,0]/[-1,-1] & d3+1-[-1,0] \\ -[0,-1]+1 & [0,-1]+[0,-2] & [-1,0]/[-1,-1] & d3+1-[-1,0] \\ -[0,-1]+1 & [0,-1]+[0,-2] & [-1,0]/[-1,-1] & d3+1-[-1,0] \\ -[0,-1]+1 & [0,-1]+[0,-2] & [-1,0]/[-1,-1] & d3+1-[-1,0] \\ -[0,-1]+1 & [0,-1]+[0,-2] & [-1,0]/[-1,-1] & d3+1-[-1,0] \\\hline -\end{spreadtab} -$ -\end{lstlisting} -\begin{center} -\STautoround{9} -$ -\begin{spreadtab}{{matrix}{}} -@n & @F_n & @\dfrac{F_n}{F_{n-1}} & @\varphi-\dfrac{F_n}{F_{n-1}}\\[2ex]\hline -\color{red}:=1 & \color{red}:=1 & & \\ -[0,-1]+1 & \color{red}:=1 & [-1,0]/[-1,-1] & (1+5^0.5)/2-[-1,0] \\ -[0,-1]+1 & [0,-1]+[0,-2] & [-1,0]/[-1,-1] & d3+1-[-1,0] \\ -[0,-1]+1 & [0,-1]+[0,-2] & [-1,0]/[-1,-1] & d3+1-[-1,0] \\ -[0,-1]+1 & [0,-1]+[0,-2] & [-1,0]/[-1,-1] & d3+1-[-1,0] \\ -[0,-1]+1 & [0,-1]+[0,-2] & [-1,0]/[-1,-1] & d3+1-[-1,0] \\ -[0,-1]+1 & [0,-1]+[0,-2] & [-1,0]/[-1,-1] & d3+1-[-1,0] \\ -[0,-1]+1 & [0,-1]+[0,-2] & [-1,0]/[-1,-1] & d3+1-[-1,0] \\ -[0,-1]+1 & [0,-1]+[0,-2] & [-1,0]/[-1,-1] & d3+1-[-1,0] \\ -[0,-1]+1 & [0,-1]+[0,-2] & [-1,0]/[-1,-1] & d3+1-[-1,0] \\ -[0,-1]+1 & [0,-1]+[0,-2] & [-1,0]/[-1,-1] & d3+1-[-1,0] \\ -[0,-1]+1 & [0,-1]+[0,-2] & [-1,0]/[-1,-1] & d3+1-[-1,0] \\ -[0,-1]+1 & [0,-1]+[0,-2] & [-1,0]/[-1,-1] & d3+1-[-1,0] \\ -[0,-1]+1 & [0,-1]+[0,-2] & [-1,0]/[-1,-1] & d3+1-[-1,0] \\ -[0,-1]+1 & [0,-1]+[0,-2] & [-1,0]/[-1,-1] & d3+1-[-1,0] \\ -[0,-1]+1 & [0,-1]+[0,-2] & [-1,0]/[-1,-1] & d3+1-[-1,0] \\ -[0,-1]+1 & [0,-1]+[0,-2] & [-1,0]/[-1,-1] & d3+1-[-1,0] \\\hline -\end{spreadtab} -$ -\end{center} - -\subsection{Bảng hóa đơn} -Trong bảng hóa đơn sau, các dấu chấm thập phân được canh thẳng hàng trong các cột nhờ kiểu hàng "N" của gói \falseverb{numprint}. - -Bảng này sử dụng môi trường \verb=tabularx= sao cho chiều rộng của nó chiếm 80\% độ rộng văn bản (của tài liệu này). Lệnh \verbinline=\multicolumn= được sử dụng nhiều lần để định dạng bảng: -\begin{lstlisting}[escapechar=!] -\nprounddigits2 -\let\PC\% -\begin{spreadtab}{{tabularx}{0.8\linewidth}{|>{\rule[-1.2ex]{0pt}{4ex}}X>{{\color{red}}}N42>{\color{red}}cN42>{\color{red}}cN42|}} -\hline -@!Mục!&@\multicolumn{1}{c}{!Giá đơn vị!} & @\multicolumn{1}{c}{!Số lượng!} & @\multicolumn{1}{c}{!Giá!} &@\multicolumn{1}{c}{!Giảm giá!} &@\textbf{!Còn lại!}\\\hline -@Item 1& 5.99 & 20 & [-2,0]*[-1,0] & $-:={20}\PC$ & [-2,0]*(1-[-1,0]/100)\\ -@Item 2& 12 & 7 & [-2,0]*[-1,0] & $-:={10}\PC$ & [-2,0]*(1-[-1,0]/100)\\ -@Item 3& 4.50 & 40 & [-2,0]*[-1,0] & $-:={35}\PC$ & [-2,0]*(1-[-1,0]/100)\\ -@Item 4& 650 & 2 & [-2,0]*[-1,0] & $-:={15}\PC$ & [-2,0]*(1-[-1,0]/100)\\\hline -@\multicolumn{6}{c}{\vspace{-1.5ex}}\\\cline{4-6} -@\multicolumn{1}{c}{\rule[-1.2ex]{0pt}{4ex}}&@\multicolumn{2}{r|}{!\textbf{Tổng cộng}!}& sum(d2:[0,-2]) &\multicolumn{1}{c}{$:={round(([1,0]/[-1,0]-1)*100,0)}\PC$} &{\fontseries{b}\selectfont}:={sum(f2:[0,-2])}\\ -\cline{4-6} -\end{spreadtab} -\end{lstlisting} -\begin{center} -\nprounddigits2 -\let\PC\% -\begin{spreadtab}{{tabularx}{0.8\linewidth}{|>{\rule[-1.2ex]{0pt}{4ex}}X>{{\color{red}}}N42>{\color{red}}cN42>{\color{red}}cN42|}} -\hline -@Mục &@\multicolumn{1}{c}{Giá đơn vị}& @\multicolumn{1}{c}{Số lượng} & @\multicolumn{1}{c}{Giá} & @\multicolumn{1}{c}{Giảm giá} & @\textbf{Còn lại}\\\hline -@Item 1 & 5.99 & 20 & [-2,0]*[-1,0] & $-:={20}\PC$ & [-2,0]*(1-[-1,0]/100)\\ -@Item 2 & 12 & 7 & [-2,0]*[-1,0] & $-:={10}\PC$ & [-2,0]*(1-[-1,0]/100)\\ -@Item 3 & 4.50 & 40 & [-2,0]*[-1,0] & $-:={35}\PC$ & [-2,0]*(1-[-1,0]/100)\\ -@Item 4 & 650 & 2 & [-2,0]*[-1,0] & $-:={15}\PC$ & [-2,0]*(1-[-1,0]/100)\\\hline -@\multicolumn{6}{c}{\vspace{-1.5ex}}\\\cline{4-6}% ligne vide et on remonte un peu ! -@\multicolumn{1}{c}{\rule[-1.2ex]{0pt}{4ex}}&@\multicolumn{2}{r|}{\textbf{Tổng cộng}}& sum(d2:[0,-2]) & \multicolumn{1}{c}{$:={round(([1,0]/[-1,0]-1)*100,0)}\PC$} & {\fontseries{b}\selectfont}:={sum(f2:[0,-2])}\\ -\cline{4-6} -\end{spreadtab} -\end{center} - -\subsection{Ô vuông ma thuật} -\begin{lstlisting} -\begin{spreadtab}{{tabular}{|*3{>{\hfill\rule[-0.4cm]{0pt}{1cm}$}m{0.7cm}<{$\hfill\null}|}}} -\hline -\color{red}:=2 & 5*b2-4*a1 & 3*a1-2*b2 \\\hline -2*a1-b2 & \color{red}:={-1} & 3*b2-2*a1 \\\hline -4*b2-3*a1 & 4*a1-3*b2 & 2*b2-a1 \\\hline -\end{spreadtab} -\end{lstlisting} -\begin{center} -\begin{spreadtab}{{tabular}{|*3{>{\hfill\rule[-0.4cm]{0pt}{1cm}$}m{0.7cm}<{$\hfill\null}|}}} -\hline -\color{red}:=2 & 5*b2-4*a1 & 3*a1-2*b2 \\\hline -2*a1-b2 & \color{red}:={-1} & 3*b2-2*a1 \\\hline -4*b2-3*a1 & 4*a1-3*b2 & 2*b2-a1 \\\hline -\end{spreadtab} -\end{center} - -\subsection{Kim tự tháp tổng} -Mỗi số hạng là tổng của hai số ngay dưới nó. -\begin{lstlisting} -\begin{spreadtab}{{tabular}{*{8}{m{2ex}}}} -\cline{4-5} -:={}\rule{0pt}{2.7ex}&&&\multicolumn{2}{|c|}{$:={[-1,1]+[1,1]}$}&&&\\\cline{3-6} -:={}\rule{0pt}{2.7ex}&&\multicolumn{2}{|c}{$:={[-1,1]+[1,1]}$}&\multicolumn{2}{|c|}{$:={[-1,1]+[1,1]}$}&&\\\cline{2-7} -:={}\rule{0pt}{2.7ex}&\multicolumn{2}{|c}{$:={[-1,1]+[1,1]}$}&\multicolumn{2}{|c}{$:={[-1,1]+[1,1]}$}&\multicolumn{2}{|c|}{$:={[-1,1]+[1,1]}$}&\\\hline -\multicolumn{2}{|c}{\rule{0pt}{2.7ex}\color{red}$:={-5}$}&\multicolumn{2}{|c}{\color{red}$:={3}$}&\multicolumn{2}{|c}{\color{red}$:={-2}$}&\multicolumn{2}{|c|}{\color{red}$:={-3}$}\\\hline -&&&&&&& -\end{spreadtab} -\end{lstlisting} -\begin{center} -\begin{spreadtab}{{tabular}{*{8}{m{2ex}}}} -\cline{4-5} -:={}\rule{0pt}{2.7ex}&&&\multicolumn{2}{|c|}{$:={[-1,1]+[1,1]}$}&&&\\\cline{3-6} -:={}\rule{0pt}{2.7ex}&&\multicolumn{2}{|c}{$:={[-1,1]+[1,1]}$}&\multicolumn{2}{|c|}{$:={[-1,1]+[1,1]}$}&&\\\cline{2-7} -:={}\rule{0pt}{2.7ex}&\multicolumn{2}{|c}{$:={[-1,1]+[1,1]}$}&\multicolumn{2}{|c}{$:={[-1,1]+[1,1]}$}&\multicolumn{2}{|c|}{$:={[-1,1]+[1,1]}$}&\\\hline -\multicolumn{2}{|c}{\rule{0pt}{2.7ex}\color{red}$:={-5}$}&\multicolumn{2}{|c}{\color{red}$:={3}$}&\multicolumn{2}{|c}{\color{red}$:={-2}$}&\multicolumn{2}{|c|}{\color{red}$:={-3}$}\\\hline -&&&&&&& -\end{spreadtab} -\end{center} -\parskip0pt -\begin{center} -$\star$\par -$\star$\quad$\star$ -\end{center} - -Đó là tất cả, hi vọng rằng gói này sẽ giúp ích cho các bạn !\par\medskip\nobreak - -Vì mới ra đời nên \ST không thể không có những sai sót. Xin vui lòng báo cho tác giả qua \href{mailto:unbonpetit@gmail.com}{\texttt{\textbf{email}}} các lỗi mà các bạn gặp phải, các macro hàm cần bổ sung và tất cả các ý kiến đóng góp \emph{mang tính thực tế}: \ST cần giữ được nét đơn giản của nó, nó không phải là \verb-excel- hay \verb-calc- và không thể bổ sung tất cả các chức năng nâng cao của các bảng tính này.\par\nobreak\bigskip -Christian \textsc{Tellechea}\par\nobreak\bigskip - -Nd: Xin vui lòng góp ý cho bản dịch qua \href{mailto:huudienkhue.le@gmail.com}{\texttt{\textbf{email}}}. Người dịch xin cảm ơn anh \textsc{Huỳnh Kỳ Anh} đã giúp đỡ trong việc hoàn thành tài liệu này ! -\end{document} \ No newline at end of file diff --git a/Master/texmf-dist/tex/latex/spreadtab/spreadtab.sty b/Master/texmf-dist/tex/latex/spreadtab/spreadtab.sty index c4d2f63e7f3..a35d324c957 100644 --- a/Master/texmf-dist/tex/latex/spreadtab/spreadtab.sty +++ b/Master/texmf-dist/tex/latex/spreadtab/spreadtab.sty @@ -1,23 +1,22 @@ % ____________________________________________________________________________ % | | % | | -% | spreadtab v0.1 | +% | spreadtab v0.2 | % | | -% | November 3 2009 | +% | January 24, 2010 | % | | % |___________________________________________________________________________| % % This is spreadtab.sty, the code of the spreadtab package. % -% Copyright Christian Tellechea 2009 +% Copyright Christian Tellechea 2009-2010 % email : unbonpetit@gmail.com % -% The "spreadtab" package consists of the 8 following files: +% The "spreadtab" package consists of the 6 following files: % spreadtab.sty (this file) % README % spreadtab_doc_fr.tex, spreadtab_doc_fr.pdf (manual in french) % spreadtab_doc_en.tex, spreadtab_doc_en.pdf (manual in english) -% spreadtab_doc_vn.tex, spreadtab_doc_vn.tex (manual in vietnamese) % % ------------------------------------------------------------------- % This work may be distributed and/or modified under the @@ -38,10 +37,10 @@ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%% Définitions préalables %%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -\newcommand\ST@ver {0.1} -\newcommand\ST@date {2009/11/02} -\newcommand\ST@fr@date {3 novembre 2009} -\newcommand\ST@eng@date{November $3^\text{rd}$ 2009} +\newcommand\ST@ver {0.2} +\newcommand\ST@date {2010/01/20} +\newcommand\ST@fr@date {24 janvier 2010} +\newcommand\ST@eng@date{January $24^\text{th}$ 2010} \ProvidesPackage{spreadtab}[\ST@date\space v\ST@ver\space Spreadsheet features for table environments] \NeedsTeXFormat{LaTeX2e} @@ -54,6 +53,9 @@ \newcount\ST@rowcount \newcount\ST@rowcount@i \newif\ifST@hiddencol +\newif\ifST@debugmode +\newif\ifST@colortblloaded +\AtBeginDocument{\@ifpackageloaded{colortbl}\ST@colortblloadedtrue\ST@colortblloadedfalse} % Définit le marqueur qui signale le commencement du champ numérique \newcommand\STnumericfieldmarker{:=} @@ -61,6 +63,9 @@ % définit le marqueur qui signale une cellule de texte \makeatother\newcommand\STtextcell{@}\makeatletter +% Commande qui permet à l'utilisateur de définir le caractère qui conserve une référence lors de la copie d'une formule +\AtBeginDocument{\newcommand\STtransposecar{!}} + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Messages d'erreur %%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -136,6 +141,12 @@ \@latex@error{\ST@errname Invalid range in cell \ST@temp@callcell.}\ST@seedoc@i\stop } +\newcommand\ST@invalidSTcopy{% + \edef\ST@temp@callcell{\ST@current@colnumber,\ST@current@rownumber}% + \ST@coord@toref\ST@temp@callcell + \@latex@error{\ST@errname Numeric field marker found, \string\STcopy\space forbidden in cell \ST@temp@callcell.}\ST@seedoc@i\stop +} + % transforme la chaine de cellules "(1,3)(4,5)(3,2)(1,3)" rencontré en référence circulaire en "A3-D5-C2-A3" \newcommand\ST@show@dependance@tree{% \ST@between\ST@dependance@tree()\ST@currentref @@ -155,6 +166,10 @@ N\or O\or P\or Q\or R\or S\or T\or U\or V\or W\or X\or Y\or Z\fi#1}% } +\newcommand\ST@illegal@copy{% + \@latex@error{\ST@errname Illegal reference in copied formula!}\ST@seedoc@i +} + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%% Macros d'affectation et d'expansion %%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -169,11 +184,30 @@ \newcommand\ST@expadd@tomacro[2]{\expandafter\ST@add@tomacro\expandafter#1\expandafter{#2}} +\newcommand\ST@edefadd@tomacro[2]{% + \begingroup\edef\ST@tmpstr{#2}\expandafter\endgroup + \expandafter\ST@add@tomacro\expandafter#1\expandafter{\ST@tmpstr}% +} + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%% Macros de manipulation de chaines %%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \def\ST@gobble@remain#1\relax{} +\newcommand\ST@splitatfirstcar[3]{% + \def\ST@splitatfirstcar@i##1##2\@nil{\def#2{##1}\def#3{##2}}% + \expandafter\ST@splitatfirstcar@i#1\@nil +} + +% dans la sc #1, remplace le . par le séparateur décimal +\newcommand\ST@substdecsep[1]{% + \ST@Ifinstr#1.{\expandafter\ST@substdecsep@i\expandafter#1\expandafter{\ST@decsep}}\relax +} +\newcommand\ST@substdecsep@i[2]{% + \def\ST@substdecsep@ii##1.##2\@nil{\def#1{##1#2##2}}% + \expandafter\ST@substdecsep@ii#1\@nil +} + % enlève tous les espaces de la sc #1 et assigne le résultat à #1 \newcommand\ST@remove@first@spaces[1]{% \IfBeginWith#1\space @@ -223,14 +257,14 @@ \expandafter\ST@split@i#1\@nil } -% Dans la sc #1, assigne ce qui est avant la sc #2 à la sc #3 +% Dans la sc #1, assigne ce qui est avant le développement de la sc #2 à la sc #3 \newcommand\ST@left[3]{\ST@exp@two@args\ST@left@i{#1}{#2}#3} \newcommand\ST@left@i[3]{% \def\ST@left@ii##1#2##2\@nil{\def#3{##1}}% \ST@left@ii#1\@nil } -% Dans la sc #1, assigne ce qui est après la sc #2 à la sc #3 +% Dans la sc #1, assigne ce qui est après le développement de la sc #2 à la sc #3 \newcommand\ST@right[3]{\ST@exp@two@args\ST@right@i{#1}{#2}#3} \newcommand\ST@right@i[3]{% \def\ST@right@ii##1#2##2\@nil{\def#3{##2}}% @@ -328,37 +362,71 @@ \ST@Ifinstr\ST@current@cell{\@empty\multicolumn}% tester la présence d'un \multicol {\ST@firstarg@after\ST@current@cell\multicolumn\ST@multicol@number}% {\let\ST@multicol@number\@empty}% - \IfSubStr\ST@current@cell\STnumericfieldmarker% il y a un champ numérique ? - {\StrBehind\ST@current@cell\STnumericfieldmarker[\ST@current@formula]% + \IfSubStr\ST@current@cell\STnumericfieldmarker% il y a un marqueur de champ numérique ? + {\IfSubStr\ST@current@cell{\@empty\STcopy}\ST@invalidSTcopy\relax% s'il y a un \STcopy, erreur (pas de champ numérique et de \STcopy dans une même cellule) + \StrBehind\ST@current@cell\STnumericfieldmarker[\ST@current@formula]% \noexploregroups \StrChar\ST@current@formula1[\ST@temp@a]% \ST@temp@a contient {} par \= + \StrSubstitute[1]\ST@current@cell\ST@temp@b\STnumericfieldmarker[\ST@current@cell]% on remplace \={} par ":=" \noexploregroups \ST@keep@firstcar\ST@temp@a% dans la formule, on enlève les accolades \ST@removespaces\ST@temp@a% et tous les espaces \ifx\ST@temp@a\@empty% \ST@temp@a contient la formule : si la formule est vide - \@namedef{code@\number\ST@colcount @\number\ST@rowcount}{0}% on mettra le code à 0 - \StrDel[1]\ST@current@cell\STnumericfieldmarker[\ST@current@cell]% on supprime aussi \= - \else% la formule n'est pas vide : + \ifx\ST@copylist\@empty% pas de copylist ? + \@namedef{code@\number\ST@colcount @\number\ST@rowcount}{0}% met le code à 0 + \StrDel[1]\ST@current@cell\STnumericfieldmarker[\ST@current@cell]% on supprime aussi ":=" + \else% si la copylist existe + \ST@lookincopylist{\number\ST@colcount}{\number\ST@rowcount}\ST@celltocopy% on cherche si la cellule en cours est dans une plage de copie + \ifx\ST@celltocopy\@empty + \@namedef{code@\number\ST@colcount @\number\ST@rowcount}{0}% si c'est non, met le code à 0 + \else + \ST@letname{formula@\number\ST@colcount @\number\ST@rowcount}\ST@celltocopy% il y a une cellule à copier : on l'assigne au champ numérique + \@namedef{code@\number\ST@colcount @\number\ST@rowcount}{1}% et on met le code à 1 + \fi + \fi + \else% la formule n'est pas vide \ST@letname{formula@\number\ST@colcount @\number\ST@rowcount}\ST@temp@a% et on assigne à la formule \@namedef{code@\number\ST@colcount @\number\ST@rowcount}{1}% code 1 à priori \fi - }% + }% ci dessous, il n'y a pas de marqueur de champ numérique {\IfSubStr\ST@current@cell\STtextcell% si c'est une cellule de texte {\StrDel\ST@current@cell\STtextcell[\ST@current@cell]% on le(s) supprime les flags \@namedef{code@\number\ST@colcount @\number\ST@rowcount}{0}% met le code à 0 - }% pas de \= ni de @ + }% ci dessous, ce n'est pas une cellule texte, c'est donc une cellule purement champ numérique sans marqueur {\StrDel\ST@current@cell\space[\ST@temp@a]% - \ifx\@empty\ST@temp@a% il n'y a que des espaces ? - \@namedef{code@\number\ST@colcount @\number\ST@rowcount}{0}% met le code à 0 - \else + \ifx\@empty\ST@temp@a% il n'y a que des espaces, c'est donc une cellule vide + \ifx\ST@copylist\@empty% pas de copylist ? + \@namedef{code@\number\ST@colcount @\number\ST@rowcount}{0}% met le code à 0 + \else% si la copylist existe + \ST@lookincopylist{\number\ST@colcount}{\number\ST@rowcount}\ST@celltocopy% on cherche si la cellule en cours est dans un oplage de copie + \ifx\ST@celltocopy\@empty + \@namedef{code@\number\ST@colcount @\number\ST@rowcount}{0}% si c'est non, met le code à 0 + \else + \let\ST@current@cell\STnumericfieldmarker% il y a une cellule à copier ici + \ST@letname{formula@\number\ST@colcount @\number\ST@rowcount}\ST@celltocopy% on l'assigne au champ numérique + \@namedef{code@\number\ST@colcount @\number\ST@rowcount}{1}% et on met le code à 1 + \fi + \fi + \else% ici, la cellule est composée d'une champ numérique sans marqueur \@namedef{code@\number\ST@colcount @\number\ST@rowcount}{1}% toute la cellule est considérée comme champ numérique \ST@remove@first@spaces\ST@current@cell - \ST@letname{formula@\number\ST@colcount @\number\ST@rowcount}\ST@current@cell% et on assigne toute la cellule - \let\ST@current@cell\STnumericfieldmarker% et on met le flag pour la formule + \ST@Ifinstr\ST@current@cell{\@empty\STcopy}% + {\ST@findcopyargs\ST@current@cell\ST@copyrange\ST@copyformula% on chope les arguments de \STcopy + \ST@seekcopyoffset\ST@copyrange% cherche les décalages + \edef\ST@copyrange{\ST@hoffest,\ST@voffest}% et affecte sous forme a,b où a et b sont des nombres ou sont vides + \expandafter\def\expandafter\ST@newtocopylist\expandafter{\expandafter{\ST@copyformula}}% \ST@newtocopylist est le nouvel élément à ajouter à la copylist + \ST@edefadd@tomacro\ST@newtocopylist{[\number\ST@colcount,\number\ST@rowcount]}% + \ST@expadd@tomacro\ST@newtocopylist{\expandafter(\ST@copyrange)}% + \ST@expadd@tomacro\ST@newtocopylist\ST@copylist% ajoute la copylist à la fin + \let\ST@copylist\ST@newtocopylist% et l'assigne à copylist + \ST@transposeformula00\ST@copyformula\ST@copyformula + \ST@letname{formula@\number\ST@colcount @\number\ST@rowcount}\ST@copyformula% affecte la formule inchangée au champ numérique courant + }% + {\ST@letname{formula@\number\ST@colcount @\number\ST@rowcount}\ST@current@cell% et on assigne toute la cellule + \let\ST@current@cell\STnumericfieldmarker}%% et on met le flag pour la formule \fi }% }% @@ -366,7 +434,7 @@ \unless\ifnum\csname code@\number\ST@colcount @\number\ST@rowcount\endcsname=\z@% si le code est <> 0 \ST@try@calc@cell(\number\ST@colcount,\number\ST@rowcount)% on essaie de calculer la cellule en cours \fi - \ST@letname{cell@\number\ST@colcount @\number\ST@rowcount}\ST@current@cell + \ST@letname{text@\number\ST@colcount @\number\ST@rowcount}\ST@current@cell \unless\ifx\@empty\ST@multicol@number% si c'est une cellule qui contient \multicolumn \loop% on met tous les codes des cellules fusionées qui suivent la cellule en cours à -1 \ifnum\ST@multicol@number>\@ne @@ -383,16 +451,216 @@ \newcommand\ST@search@hline[1]{% \unless\ifcsname endrow@\number\ST@rowcount\endcsname\ST@letname{endrow@\number\ST@rowcount}\@empty\fi \ST@remove@first@spaces#1% on enlève les espaces au début + %\let\ST@temp@a#1\ST@keep@firstcar\ST@temp@a \StrChar#11[\ST@temp@a]% \ST@temp@a est le 1er car \let\next\ST@search@hline \IfStrEqCase\ST@temp@a{% on envisage tous les cas de tracé de ligne horizontale {\@empty\hline}{\StrGobbleLeft#11[#1]\expandafter\ST@add@tomacro\csname endrow@\number\ST@rowcount\endcsname\hline}% {\@empty\cline}{\StrSplit#12\ST@temp@a#1\expandafter\ST@expadd@tomacro\csname endrow@\number\ST@rowcount\endcsname\ST@temp@a}% {\@empty\hhline}{\StrSplit#12\ST@temp@a#1\expandafter\ST@expadd@tomacro\csname endrow@\number\ST@rowcount\endcsname\ST@temp@a}% + {\@empty\noalign}{\StrSplit#12\ST@temp@a#1\expandafter\ST@expadd@tomacro\csname endrow@\number\ST@rowcount\endcsname\ST@temp@a}% + {\@empty\toprule}{% les commandes de booktabs + \StrSplit#11\ST@temp@a#1% chope le 1er lexème : la commande \toprule + \IfBeginWith#1[{\StrBefore#1][\ST@temp@b]\ST@expadd@tomacro\ST@temp@a{\ST@temp@b]}\StrBehind#1][#1]}\relax + \expandafter\ST@expadd@tomacro\csname endrow@\number\ST@rowcount\endcsname\ST@temp@a + }% + {\@empty\midrule}{% + \StrSplit#11\ST@temp@a#1% chope le 1er lexème : la commande \midrule + \IfBeginWith#1[{\StrBefore#1][\ST@temp@b]\ST@expadd@tomacro\ST@temp@a{\ST@temp@b]}\StrBehind#1][#1]}\relax + \expandafter\ST@expadd@tomacro\csname endrow@\number\ST@rowcount\endcsname\ST@temp@a + }% + {\@empty\bottomrule}{% + \StrSplit#11\ST@temp@a#1% chope le 1er lexème : la commande \bottomrule + \IfBeginWith#1[{\StrBefore#1][\ST@temp@b]\ST@expadd@tomacro\ST@temp@a{\ST@temp@b]}\StrBehind#1][#1]}\relax + \expandafter\ST@expadd@tomacro\csname endrow@\number\ST@rowcount\endcsname\ST@temp@a + }% + {\@empty\cmidrule}{% + \StrSplit#11\ST@temp@a#1% chope le 1er lexème : la commande \cmidrule + \IfBeginWith#1[{\StrBefore#1][\ST@temp@b]\ST@expadd@tomacro\ST@temp@a{\ST@temp@b]}\StrBehind#1][#1]}\relax + \IfBeginWith#1({\StrBefore#1)[\ST@temp@b]\ST@expadd@tomacro\ST@temp@a{\ST@temp@b)}\StrBehind#1)[#1]}\relax + \StrSplit#11\ST@temp@b#1% chope l'argument obligatoire : {a-b} + \ST@expadd@tomacro\ST@temp@a\ST@temp@b% l'ajoute à \ST@temp@b + \expandafter\ST@expadd@tomacro\csname endrow@\number\ST@rowcount\endcsname\ST@temp@a% et on ajoute le tout à endrow + }% + {\@empty\addlinespace}{% + \StrSplit#11\ST@temp@a#1% chope le 1er lexème : la commande \addlinespace + \IfBeginWith#1[{\StrBefore#1][\ST@temp@b]\ST@expadd@tomacro\ST@temp@a{\ST@temp@b]}\StrBehind#1][#1]}\relax + \expandafter\ST@expadd@tomacro\csname endrow@\number\ST@rowcount\endcsname\ST@temp@a + }% + {\@empty\morecmidrules}{\StrGobbleLeft#11[#1]\expandafter\ST@add@tomacro\csname endrow@\number\ST@rowcount\endcsname\morecmidrules}% + {\@empty\specialrule}{\StrSplit#14\ST@temp@a#1\expandafter\ST@expadd@tomacro\csname endrow@\number\ST@rowcount\endcsname\ST@temp@a}% }[\let\next\@gobble]% \next#1% } +% Cette macro transpose toutes les références (absolues et relatives) de la sc #3. +% Le décalage est de #1 (nombre signé) pour les colonnes et de #2 (nombre signé) pour les lignes. +% La sc #4 recoit la formule transposée. +\newcommand\ST@transposeformula[4]{% + \def\ST@addcol{#1}\def\ST@addrow{#2}\let\ST@temp@formula#3% + \let\ST@transposed@formula\@empty + \ST@transposeformula@i + \let#4\ST@transposed@formula +} + +\newcommand\ST@transposeformula@i{% + \unless\ifx\@empty\ST@temp@formula% tant que l'on n'a pas parcouru \ST@temp@formula + \ST@splitatfirstcar\ST@temp@formula\ST@firstcar\ST@temp@formula% prend le 1er car de \ST@temp@formula + \if\expandafter\noexpand\STtransposecar\expandafter\noexpand\ST@firstcar% si ce caractère est un ! + \let\ST@addcol@\z@% pas de tranposition sur la colonne + \ST@splitatfirstcar\ST@temp@formula\ST@firstcar\ST@temp@formula% on prend le premier caractère qui suit le ! + \else + \let\ST@addcol@\ST@addcol% sinon, on copie le vecteur + \fi + \expandafter\ST@ifcar@isletter\expandafter{\ST@firstcar}% est-ce que le 1er car est une lettre ? + {\if\expandafter\noexpand\STtransposecar\expandafter\expandafter\expandafter\noexpand\expandafter\@car\ST@temp@formula\@nil% le caractère suivant est un "!" ? + \let\ST@addrow@\z@% pas de tranposition sur la ligne + \expandafter\expandafter\expandafter\def\expandafter\expandafter\expandafter\ST@temp@formula\expandafter\expandafter\expandafter{\expandafter\@cdr\ST@temp@formula\@nil}% on prend ce qui est après le ! + \else + \let\ST@addrow@\ST@addrow% sinon, on copie le vecteur + \fi + \IfInteger\ST@temp@formula\relax\relax% on prend le nombre qui suit + \ifnum\integerpart>\z@% si ce nombre est plus grand que 0 -> référence valide + \let\ST@temp@formula\@xs@afterinteger% on prend ce qui est après le nombre + \expandafter\lowercase\expandafter{\expandafter\def\expandafter\ST@firstcar\expandafter{\ST@firstcar}}% met en minuscules + \edef\ST@firstcar{\number\numexpr\expandafter`\ST@firstcar-`a+1+\ST@addcol@}% est le numéro de la colonne + \ifnum\ST@firstcar<\@ne\ST@illegal@copy\fi% erreur de copie ? + \ST@edefadd@tomacro\ST@transposed@formula{% + \ifcase\ST@firstcar \or a\or b\or c\or d\or e\or f\or g\or h\or i\or j\or k\or l\or m\or + n\or o\or p\or q\or r\or s\or t\or u\or v\or w\or x\or y\or z\fi + \number\numexpr\integerpart+\ST@addrow@}% + \ifnum\numexpr\integerpart+\ST@addrow@<\@ne\ST@illegal@copy\fi% erreur de copie ? + \else + \let\ST@temp@formula\@xs@afterinteger + \ST@expadd@tomacro\ST@transposed@formula\ST@firstcar + \fi + }% + {\if[\expandafter\noexpand\ST@firstcar% si le 1er car est [ + \ST@left\ST@temp@formula]\ST@temp@ref% on prend ce qui est entre crochet + \ST@right\ST@temp@formula]\ST@temp@formula% pour la suite, on prend ce qui après le crochet + \ST@left\ST@temp@ref,\ST@rel@num% ce qui est avant la virgule + \if\expandafter\noexpand\STtransposecar\expandafter\expandafter\expandafter\noexpand\expandafter\@car\ST@rel@num\@nil% commence par un "!" ? + \let\ST@addcol@\ST@addcol% compensation pour conserver la cellule initiale + \expandafter\expandafter\expandafter\def\expandafter\expandafter\expandafter\ST@rel@num\expandafter\expandafter\expandafter{\expandafter\@cdr\ST@rel@num\@nil}% on prend ce qui est après le ! + \else + \let\ST@addcol@\z@% sinon, on n'ajoute rien + \fi + \IfInteger\ST@rel@num + {\edef\ST@addcol@{\number\numexpr\ST@rel@num-\ST@addcol@}% + \ST@right\ST@temp@ref,\ST@rel@num% ce qui est après la virgule + \if\expandafter\noexpand\STtransposecar\expandafter\expandafter\expandafter\noexpand\expandafter\@car\ST@rel@num\@nil% commence par un "!"? + \let\ST@addrow@\ST@addrow% on compense pour conserver la cellule initiale + \expandafter\expandafter\expandafter\def\expandafter\expandafter\expandafter\ST@rel@num\expandafter\expandafter\expandafter{\expandafter\@cdr\ST@rel@num\@nil}% on prend ce qui est après le ! + \else + \let\ST@addrow@\z@% sinon, on n'ajoute rien + \fi + \IfInteger\ST@rel@num + {\ST@edefadd@tomacro\ST@transposed@formula{[\ST@addcol@,\number\numexpr\ST@rel@num-\ST@addrow@]}% + }% + \ST@illegal@relativeref + }% + \ST@illegal@relativeref + \else + \ST@expadd@tomacro\ST@transposed@formula\ST@firstcar + \fi + }% + \expandafter\ST@transposeformula@i + \fi +} + +% Cherche dans la sc #1 les 3 arguments qui se trouvent après \STcopy +% Affecte le 1er à #2, le 2è à #3 et le 3è à #4 +\newcommand\ST@findcopyargs[3]{% + \def\ST@argaftercopy##1\STcopy##2##3##4\@nil{% + \def#1{##1}\ST@expadd@tomacro#1{\STnumericfieldmarker##4}% dans #1,supprime \STcopy{}{} et le remplace par := + \def#2{##2}\def#3{##3}% + }% + \expandafter\ST@argaftercopy#1\@nil +} + +% teste si #1 est dans l'intervalle [#3,#3+#5] et si #2 est dans [#4,#4+#6] +% si #5 est vide, c'est l'intervalle [#3,+inf] et si #6 est vide, c'est [#4,+inf] +\def\ST@Ifin#1#2[#3,#4](#5,#6)% +{% + \csname @% + \ifnum#1<#3 second% + \else + \ifnum#2<#4 second% + \else + \ifx\@empty#5\@empty + \ifx\@empty#6\@empty first% + \else + \ifnum#2>\numexpr#4+#6 second% + \else first% + \fi + \fi + \else + \ifnum#1>\numexpr#3+#5 second% + \else + \ifx\@empty#6\@empty first% + \else + \ifnum#2>\numexpr#4+#6 second% + \else first% + \fi + \fi + \fi + \fi + \fi + \fi oftwo\endcsname +} + +% Regarde dans la liste de copie si la cellule de coodonnées #1 #2 est dans une plage de copie +% si oui, affecte à #3 la formule transposée +% La liste de copy est parcourue de gauche à droite avec sortie dès qu'une plage qui convient est rencontrée +\newcommand\ST@lookincopylist[3]{% + \let\ST@copylist@\ST@copylist\let\ST@returnedformula\@empty + \def\ST@copycol{#1}\def\ST@copyrow{#2}\let#3\@empty + \ST@lookincopylist@i + \let#3\ST@returnedformula +} + +\newcommand\ST@lookincopylist@i{% + \expandafter\ST@testfirstincopylist\ST@copylist@\@nil + \csname + \ifx\@empty\ST@copylist@ relax% + \else + \ifx\@empty\ST@returnedformula ST@lookincopylist@i% + \else relax% + \fi + \fi\endcsname +} + +% Teste si un élément de la copylist contient une plage qui inclus la cellule en cours. +\def\ST@testfirstincopylist#1[#2,#3](#4,#5)#6\@nil% +{% + \def\ST@copylist@{#6}% on enlève le premier élément de la copylist + \ST@Ifin\ST@copycol\ST@copyrow[#2,#3](#4,#5)% si ça correspond + {\def\ST@returnedformula{#1}% + \ST@transposeformula{\numexpr\ST@copycol-#2}{\numexpr\ST@copyrow-#3}\ST@returnedformula\ST@returnedformula + }% + \relax +} + +% Cherche dans la sc#1 du type ">4,v9" les décalages horizontaux et verticaux +% spécifiés avec > et v +% S'il trouve > ou v sans nombre derrière, le décalage correspondant est vide +% S'il ne trouve pas > ou v, le décalage correspond est égal à 0 +% Assigne les décalages trouvés dans \ST@hoffest et \ST@voffest +\newcommand\ST@seekcopyoffset[1]{% + \ST@Ifinstr#1>% + {\ST@findcopyoffest#1>\ST@hoffest}% + {\def\ST@hoffest{0}}% + \ST@Ifinstr#1v% + {\ST@findcopyoffest#1v\ST@voffest}% + {\def\ST@voffest{0}}% +} + +% Cherche dans la sc #1 ce qui est entre #2 et , +\newcommand\ST@findcopyoffest[3]{% + \def\ST@findcopyoffest@i##1#2##2,##3\@nil{\def#3{##2}}% + \expandafter\ST@findcopyoffest@i#1,\@nil +} + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%% Recherche d'une référence %%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -415,16 +683,11 @@ % si on trouve, renvoie les coordonnées dans #2 sous la forme x@y % si on ne trouve pas, #2 est vide. \newcommand\ST@findref@informula[2]{% - \let\ST@temp@formula#1 + \let\ST@temp@formula#1% \ST@findref@informula@i \let#2\ST@temp@formula } -\newcommand\ST@splitatfirstcar[3]{% - \def\ST@splitatfirstcar@i##1##2\@nil{\def#2{##1}\def#3{##2}}% - \expandafter\ST@splitatfirstcar@i#1\@nil -} - \newcommand\ST@findref@informula@i{% \let\ST@next@search\ST@findref@informula@i \ifx\@empty\ST@temp@formula @@ -434,7 +697,7 @@ \expandafter\ST@ifcar@isletter\expandafter{\ST@firstcar}% est-ce que le 1er car est une lettre ? {\IfInteger\ST@temp@formula\relax\relax% on prend le nombre qui suit \ifnum\integerpart>\z@% si ce nombre est plus grand que 0 -> référence valide - \edef\ST@ref@found{\ST@firstcar\number\integerpart}% + \edef\ST@ref@found{\ST@firstcar\number\integerpart}% est la référence trouvée \edef\ST@distant@rownumber{\number\integerpart}% on chope ce nombre pour le numéro de colonne \edef\ST@distant@colnumber{\expandafter\number\expandafter\numexpr\expandafter`\ST@firstcar-`a+1}% traduction lettre->chiffre \ifnum\ST@distant@colnumber<\z@\edef\ST@distant@colnumber{\number\numexpr\ST@distant@colnumber+32}\fi% met les majuscules en minuscules @@ -508,7 +771,7 @@ \unless\ifx\ST@autouround\@empty\FPround\ST@temp@a\ST@temp@a\ST@autouround\fi% on arrondi s'il faut \FPclip\ST@temp@a\ST@temp@a% puis on supprime les 0 inutiles \ST@letname{formula@#1@#2}\ST@temp@a% assigne le résultat à la formule - \@namedef{code@#1@#2}{2}%% et met le code à 2 (cellule calculée) + \@namedef{code@#1@#2}{2}% et met le code à 2 (cellule calculée) \fi } @@ -584,7 +847,7 @@ \else \ST@Ifinstr{\ST@functions@with@textresult,}{\ST@function@namesaved,}% si la dernière fonction rend du texte {\@namedef{code@#1@#2}{0}% on met le code à 0, la cellule devient textuelle - \expandafter\let\csname cell@#1@#2\expandafter\endcsname\csname formula@#1@#2\endcsname% copie de la formule vers la zone texte (avec écrasement de ce qui s'y trouvait) + \expandafter\let\csname text@#1@#2\expandafter\endcsname\csname formula@#1@#2\endcsname% copie de la formule vers la zone texte (avec écrasement de ce qui s'y trouvait) \ST@letname{formula@#1@#2}\@empty% et plus rien dansla formule }% {\ST@calc@cell(#1,#2)}% c'est une fonction qui donne un arg numérique : on calcule la cellule en cours @@ -677,7 +940,7 @@ \def\ST@nexteval{\ST@eval@cell@i(#1,#2)}% puis, on évalue à nouveau cette cellule \else% il y a une référence dans l'argument de la fontion \ifnum\csname code@\ST@temp@formula\endcsname=\z@% si la référence est une cellule texte - \expandafter\let\expandafter\ST@current@formula\csname cell@\ST@temp@formula\endcsname% alias pour la zone texte distante + \expandafter\let\expandafter\ST@current@formula\csname text@\ST@temp@formula\endcsname% alias pour la zone texte distante % on ne prend que le texte s'il y a un \multicolumn qui traine \ST@Ifinstr\ST@current@formula{\@empty\multicolumn}% {\ST@thirdarg@after\ST@current@formula\multicolumn\ST@current@formula}\relax @@ -757,7 +1020,7 @@ fact,ifeq,ifgt,iflt,numtofrshortdate,numtoengshortdate,numtofrlongdate,% numtoenglongdate,numtofrmonth,numtoengmonth,numtofrday,numtoengday} -% liste des fonctions dont l'argument est une plage +% liste des fonctions dont l'argument est une plage ou est vide \newcommand\ST@functions@with@range@arg{sum,rand,randint,sumprod} % liste des fonctions dont l'argument ne doit pas être calculé @@ -1177,44 +1440,39 @@ \ST@Ifinstr\ST@row@skiplist{\number\ST@rowcount,}% la ligne fait partie de la skiplist ? {\advance\ST@rowcount\@ne}% on passe à la ligne suivante {% - \ifcsname code@\number\ST@colcount @\number\ST@rowcount\endcsname% le code existe ? (tenir compte d'une ligne complètement vide du genre ////) - \ST@Ifinstr\ST@col@skiplist{\number\ST@colcount,}% la colonne fait partie de la skiplist ? - \ST@hiddencoltrue - {% - \ST@hiddencolfalse - \ifcsname cell@\number\ST@colcount @\number\ST@rowcount\endcsname% si la cellule existe - \expandafter\let\expandafter\ST@temp@a\csname formula@\number\ST@colcount @\number\ST@rowcount\endcsname% la valeur - \expandafter\let\expandafter\ST@temp@b\csname cell@\number\ST@colcount @\number\ST@rowcount\endcsname% on créé un alias - \exploregroups - \StrSubstitute[1]\ST@temp@b\STnumericfieldmarker\ST@temp@a[\ST@temp@a]% on remplace le flag de formule par la valeur calculée - \noexploregroups - \ST@expadd@tomacro\ST@tab\ST@temp@a% on ajoute la cellule au tableau + \ST@Ifinstr\ST@col@skiplist{\number\ST@colcount,}% la colonne fait partie de la skiplist ? + \ST@hiddencoltrue + {% + \ST@hiddencolfalse + \ifcsname text@\number\ST@colcount @\number\ST@rowcount\endcsname% si la cellule existe + \expandafter\let\expandafter\ST@temp@a\csname formula@\number\ST@colcount @\number\ST@rowcount\endcsname% la valeur + \expandafter\let\expandafter\ST@temp@b\csname text@\number\ST@colcount @\number\ST@rowcount\endcsname% on créé un alias + \ifnum\csname code@\number\ST@colcount @\number\ST@rowcount\endcsname=\tw@% si la cellule contient un champ numérique + \unless\ifx\ST@decsep\ST@decsepfp\ST@substdecsep\ST@temp@a\fi% et si le "." doit être remplacé par "," on substitue \fi - }% - \advance\ST@colcount\@ne% on passe à la colonne suivante ! - \ifcsname code@\number\ST@colcount @\number\ST@rowcount\endcsname% y a t-il encore un code défini ensuite ? - \ifnum\csname code@\number\ST@colcount @\number\ST@rowcount\endcsname<\z@% on est dans une cellule contenant \multicol ? - \expandafter\ST@firstarg@after\csname cell@\number\numexpr\ST@colcount-1@\number\ST@rowcount\endcsname\multicolumn\ST@multicol@number% combien de cellules ? - \advance\ST@colcount\ST@multicol@number% on va voir après le multicol en sautant toutes les valeurs des colonnes intermédiaires - \advance\ST@colcount\m@ne - \ifcsname code@\number\ST@colcount @\number\ST@rowcount\endcsname% y a t-il un code défini après le multicol ? - \ST@add@tomacro\ST@tab&% on ajoute la tabulation - \fi - \else% pas de \multicolumn - \unless\ifST@hiddencol% si la cellule n'est pas masquée - \unless\ifnum\ST@colcount>\ST@lastshowcol% si ce n'est pas la dernière cellule affichée - \ST@add@tomacro\ST@tab&%on ajoute la tabulation - \fi - \fi + \exploregroups + \StrSubstitute[1]\ST@temp@b\STnumericfieldmarker\ST@temp@a[\ST@temp@a]% on remplace le flag de formule par la valeur calculée + \noexploregroups + \ST@expadd@tomacro\ST@tab\ST@temp@a% on ajoute la cellule au tableau + \fi + }% + \advance\ST@colcount\@ne% on passe à la colonne suivante ! + \ifcsname code@\number\ST@colcount @\number\ST@rowcount\endcsname% y a t-il encore un code défini ensuite ? + \ifnum\csname code@\number\ST@colcount @\number\ST@rowcount\endcsname<\z@% on est dans une cellule contenant \multicol ? + \expandafter\ST@firstarg@after\csname text@\number\numexpr\ST@colcount-1@\number\ST@rowcount\endcsname\multicolumn\ST@multicol@number% combien de cellules ? + \advance\ST@colcount\ST@multicol@number% on va voir après le multicol en sautant toutes les valeurs des colonnes intermédiaires + \advance\ST@colcount\m@ne + \ifcsname code@\number\ST@colcount @\number\ST@rowcount\endcsname% y a t-il un code défini après le multicol ? + \ST@add@tomacro\ST@tab&% on ajoute la tabulation \fi - \else% il n'y a plus de code ensuite donc c'était la dernière colonne - \ifcsname endrow@\number\ST@rowcount\endcsname - \expandafter\ST@expadd@tomacro\expandafter\ST@tab\csname endrow@\number\ST@rowcount\endcsname% ajoute la fin de la ligne + \else% pas de \multicolumn + \unless\ifST@hiddencol% si la cellule n'est pas masquée + \unless\ifnum\ST@colcount>\ST@lastshowcol% si ce n'est pas la dernière cellule affichée + \ST@add@tomacro\ST@tab&%on ajoute la tabulation + \fi \fi - \ST@colcount\@ne% on remet la colonne à 1 - \advance\ST@rowcount\@ne% on passe à la ligne suivante \fi - \else + \else% il n'y a plus de code ensuite donc c'était la dernière colonne \ifcsname endrow@\number\ST@rowcount\endcsname \expandafter\ST@expadd@tomacro\expandafter\ST@tab\csname endrow@\number\ST@rowcount\endcsname% ajoute la fin de la ligne \fi @@ -1226,9 +1484,95 @@ \ST@nextcell } +% format des lettres et nombres représentant les coordonnées (helvetica gras très petit) +\newcommand\ST@debugformat@headers{% + \usefont{T1}{phv}{b}{n}% +} + +% format utilisé pour les cellules +\newcommand\ST@debug@format@cells{% + \usefont{T1}{lmtt}{m}{n}% +} + +\newcommand\ST@colorcell{% + \ifST@colortblloaded\noexpand\cellcolor[gray]{.6}\fi +} + +\newcommand\STdebug{% + \begingroup\ifmmode\scriptscriptstyle\else\scriptsize\fi + \def\ST@temp@a{formula}% pour n'afficher les fins de ligne que dans ce cas + \IfStrEqCase\ST@debuginfo{% + {formula}\relax{text}\relax{code}\relax + }[\ST@illegaldebugcommand]% + \ST@debug@format@cells + \tabcolsep0.3em + \ST@rowcount\@ne\ST@colcount\@ne + \edef\ST@debugtab{% + \noexpand\begin{tabular}{r|*{\number\numexpr\ST@lastshowcol+1}{c|}}% + \noexpand\multicolumn1{c}{\ST@colorcell}&% + }% + \loop + \ST@edefadd@tomacro\ST@debugtab{\noexpand\multicolumn1c{\ST@colorcell\noexpand\ST@debugformat@headers\@Alph\ST@colcount}}% + \ifnum\ST@colcount<\ST@lastshowcol + \advance\ST@colcount\@ne + \ST@add@tomacro\ST@debugtab&% + \repeat + \ST@colcount\@ne + \ST@edefadd@tomacro\ST@debugtab{% + &% passe à la dernière colonne de la première ligne + \noexpand\multicolumn1l{% + \ifx\ST@temp@a\ST@debuginfo + \ifcsname endrow@\number\ST@rowcount\endcsname + \detokenize\expandafter\expandafter\expandafter{\csname endrow@0\endcsname}% + \fi + \fi}% + \noexpand\\\noexpand\cline{2-\number\numexpr\ST@lastshowcol+1}% + }% + \ST@debug@tab@i +} + +\newcommand\ST@debug@tab@i{% affiche le tableau de débobage + \ifnum\ST@rowcount>\ST@total@rownumber + \ST@edefadd@tomacro\ST@debugtab{\noexpand\cline{2-\number\numexpr\ST@lastshowcol+1}\noexpand\end{tabular}}% + \ST@debugtab% affichage du tableau de débogage + \ifmmode\\[0.5ex]\else\par\smallskip\fi% retour à la ligne + \expandafter\endgroup + \else + \ifnum\ST@colcount=\@ne + \ST@edefadd@tomacro\ST@debugtab{% + \noexpand\multicolumn1{c|}{\ST@colorcell\noexpand\ST@debugformat@headers\number\ST@rowcount}&}% + \fi + \ifcsname\ST@debuginfo @\number\ST@colcount @\number\ST@rowcount\endcsname% si l'info existe pour la cellule concernée + \ST@edefadd@tomacro\ST@debugtab{\detokenize\expandafter\expandafter\expandafter{\csname\ST@debuginfo @\number\ST@colcount @\number\ST@rowcount\endcsname}}% on ajoute la cellule au tableau que l'on a detokenisée au préalable + \fi + \advance\ST@colcount\@ne% on passe à la colonne suivante ! + \ifnum\ST@colcount>\ST@lastshowcol% si c'est la dernière cellule affichée + \ST@edefadd@tomacro\ST@debugtab{% + &\noexpand\multicolumn1l{% + \ifx\ST@temp@a\ST@debuginfo + \ifcsname endrow@\number\ST@rowcount\endcsname + \detokenize\expandafter\expandafter\expandafter{\csname endrow@\number\ST@rowcount\endcsname}% + \fi + \fi}% + \noexpand\\\noexpand\cline{2-\number\numexpr\ST@lastshowcol+1}}% + \ST@colcount\@ne% on remet la colonne à 1 + \advance\ST@rowcount\@ne% on passe à la ligne suivante + \else% il reste encore des cellules dans la ligne + \ST@add@tomacro\ST@debugtab&% on ajoute la tabulation + \fi + \expandafter\ST@debug@tab@i + \fi +} + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%% Environnement spreadtab et macros publiques %%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +% définit le séparateur décimal +\newcommand\STsetdecimalsep[1]{\StrChar{#1}1[\ST@decsep]} +\def\ST@decsepfp{.}% le séparateur décimal donné par fp +\STsetdecimalsep.% le point par défaut + \STmessage{true}% affiche les messages par défaut \newcommand\STautoround[1]{\def\ST@autouround{#1}} @@ -1246,10 +1590,10 @@ } \newcommand\ST@find@end[1]{% - \def\@tempa{#1}% - \ifx\@tempa\ST@name@env - \def\@tempa{\end{#1}}% - \expandafter\@tempa + \def\ST@temp@a{#1}% + \ifx\ST@temp@a\ST@name@env + \def\ST@temp@a{\end{#1}}% + \expandafter\ST@temp@a \else \@addtomacro\ST@tab{\end{#1}}% \expandafter\ST@get@body @@ -1265,7 +1609,7 @@ \def\ST@tab@preamble{#2}%% préambule du tableau \StrChar{\@empty#2}1[\ST@tab@name]% \def\ST@optcode{#1}% - \let\ST@row@skiplist\@empty\let\ST@col@skiplist\@empty\def\ST@last@skipcol{0}% + \let\ST@copylist\@empty\let\ST@row@skiplist\@empty\let\ST@col@skiplist\@empty\def\ST@last@skipcol{0}% \edef\ST@previous@seed{\number\FPseed}% sauvegarde de la graine \ST@seed% graine variable \ST@emit@message{\ST@errname New spreadtab {\detokenize{#2}}^^J* reading tab:}% @@ -1276,15 +1620,32 @@ \ST@read@tab% analyse le tableau contenu dans \ST@tab \ST@emit@message{ok^^J}% \ST@search@lastshowcol% cherche la dernière colonne affichée - \ST@emit@message{* computing formulas:^^J}% - \ST@eval@tab - \ST@optcode% exécute l'argument optionnel - \expandafter\def\expandafter\ST@tab\expandafter{\expandafter\begin\ST@tab@preamble}% - \ST@emit@message{* building tab:}% - \ST@build@tab - \ST@emit@message{ok^^J}% - \ST@expadd@tomacro\ST@tab{\expandafter\end\ST@tab@name} - \ST@tab% affiche le tableau + \ST@debugmodefalse% à priori, on n'est pas en mode débogage + \loop% affiche éventuellement les tableaux de débogage + \ST@Ifinstr\ST@optcode{\@empty\STdebug}{\ST@debugmodetrue\iftrue}\iffalse% \fi + \ST@firstarg@after\ST@optcode\STdebug\ST@debuginfo + \ST@emit@message{\space\space\space\space\space Debug mode: display debug tab "\ST@debuginfo"^^J}% + \StrDel\ST@optcode{\expandafter\STdebug\expandafter{\ST@debuginfo}}[\ST@optcode]% + \STdebug + \repeat + \ifST@debugmode + \ST@Ifinstr\ST@optcode{\@empty\STdisplaytab}% + {\ST@debugmodefalse + \ST@emit@message{\space\space\space\space\space Debug mode: display final tab^^J}% + }\relax + \fi + \let\STdisplaytab\relax% on neutralise au cas où l'arg optionnel contient cette commande sans contenir \STdebug + \unless\ifST@debugmode% si on doit afficher le tableau, on fait le boulot + \ST@emit@message{* computing formulas:^^J}% + \ST@eval@tab + \ST@optcode% exécute l'argument optionnel + \expandafter\def\expandafter\ST@tab\expandafter{\expandafter\begin\ST@tab@preamble}% + \ST@emit@message{* building tab:}% + \ST@build@tab + \ST@emit@message{ok^^J}% + \ST@expadd@tomacro\ST@tab{\expandafter\end\ST@tab@name}% + \ST@tab% affiche le tableau + \fi \ST@emit@message{\ST@errname End of spreadtab^^J^^J}% \global\FPseed\ST@previous@seed% restauration de la graine } @@ -1357,4 +1718,32 @@ v0.1pre 2009/09/02 7 Améliorations et optimisations ------------------------------------------------------------------------------- v0.1 2009/11/03 Première version publique sur le CTAN -------------------------------------------------------------------------------- \ No newline at end of file +------------------------------------------------------------------------------- +v0.2 2010/01/24 + 1 On peut définir le séparateur décimal par la macro + \STsetdecimalsep{} + 2 Il est possible de copier une formule dans le tableau à l'aide de + \STcopy{>a,vb}{formule} où a et b sont les nombres de cellules + horizontaux et verticaux vers lesquels la formule sera copiée. + 3 Désormais, spreadtab est entièrement compatible avec toutes les + commandes du package booktabs + 4 La commande \noalign et son argument est prise en compte lorsqu'elle se + trouve après un \\ + 5 Suppression d'espaces indésirables + 6 Mise en place d'un mode débogage où l'on peut visualiser les champs + numériques, les champs textuels ou les codes des cellules du tableau + +############################################################################### +# TODO list # +############################################################################### + 1 Augmenter le nombre de macro-fonctions + - arithmetique : calcul de pgcd, ppcm, de reste de division + - conversion : deg-rad-gra et système métrique <-> anglo saxon + - autres... + 2 Améliorer l'algorithme pour \STcopy : enlever une formule de + \ST@copylist lorsqu'on a dépassé la dernière ligne de la plage où elle + doit être copiée + 3 Améliorer les tableaux de débogage + 4 Dans un champ textuel, créer une nouvelle fonctionnalité pour afficher + le résultat du champ numérique d'une autre cellule, sans avoir à le + sauvegarder avec \STsave pour l'afficher ensuite. \ No newline at end of file -- cgit v1.2.3