Deyan Ginev edited section_Handy_LaTeX_Programming_Some__.tex  almost 9 years ago

Commit id: c19b263e05096c3fc714e925fcd996a4a07e5461

deletions | additions      

       

Some of the tricks used in this tutorial (all of which can be found in \href{https://www.authorea.com/users/5713/articles/28015/master/file/header.tex}{the article header}):  \subsection{Listing and Execution of snippet} \subsection{For loops for quick table generation}  Source: \url{http://tex.stackexchange.com/a/134113}  \begin{lstlisting}  \newcounter{a}  \newcounter{b}  \newcounter{ab}  \newtoks\allrows  \newcommand\addrow[3]{%  \begingroup\edef\container{\endgroup  \noexpand\global\noexpand\allrows{\the\allrows  #1 & #2 & #3\noexpand\\}}\container}  \newcommand*\resetrows{\global\allrows{}}  \newcommand*\printrows{\the\allrows}  \resetrows  \setcounter{a}{0}  \loop\ifnum\thea<5  \stepcounter{a}  \setcounter{b}{0}  {\loop \ifnum\theb<10  \stepcounter{b}  \setcounter{ab}{\numexpr\thea*\theb\relax}%  \addrow{$\thea$}{$\theb$}{$\theab$}  \repeat}  \expandafter\global\expandafter\allrows\expandafter{\the\allrows\hline}  \repeat  \begin{tabular}{|rrr|}  \hline $A$ & $B$ & $A\times B$ \\ \hline  \printrows  \end{tabular}  \end{lstlisting}  \newcounter{a}  \newcounter{b}  \newcounter{ab}  \newtoks\allrows  \newcommand\addrow[3]{%  \begingroup\edef\container{\endgroup  \noexpand\global\noexpand\allrows{\the\allrows  #1 & #2 & #3\noexpand\\}}\container}  \newcommand*\resetrows{\global\allrows{}}  \newcommand*\printrows{\the\allrows}  \resetrows  \setcounter{a}{0}  \loop\ifnum\thea<5  \stepcounter{a}  \setcounter{b}{0}  {\loop \ifnum\theb<10  \stepcounter{b}  \setcounter{ab}{\numexpr\thea*\theb\relax}%  \addrow{$\thea$}{$\theb$}{$\theab$}  \repeat}  \expandafter\global\expandafter\allrows\expandafter{\the\allrows\hline}  \repeat  \begin{table}  \begin{tabular}{|rrr|}  \hline $A$ & $B$ & $A\times B$ \\ \hline  \printrows  \end{tabular}  \label{tab:multiplication}  \end{table}