# Tag Info

12

With LuaTeX you can use the script language Lua: \documentclass{article} \usepackage{luacode} \begin{luacode} function permute(n) local tab = {} for i = 1, n do tab[i] = i end for i = 1, n do local j = math.random(i, n) tab[i], tab[j] = tab[j], tab[i] end for i = 1, n do tex.print("\\shortstack{"..i.."\\\\"..tostring(tab[i]).."} ") ...

9

Fireworks, in any flavor of TeX, but only text? Then the old package happy4th meets the requirements. Really is only an little obfuscated TeX file: % Author: Brian Blackmore <blb8@po.cwru.edu> % Date: July 4, 2007 % Version: 20120102 % Original source: efnet #TeX % License: Public Domain % Requirements: Plain TeX % \nopagenumbers ...

8

Here's an implementation of the Knuth shuffle algorithm with expl3. \documentclass{article} \usepackage{amsmath,xparse} \input{random} \ExplSyntaxOn \cs_new_eq:NN \knuthshuffle_get_random:Nnn \setrannum \tl_new:N \l_knuthshuffle_tempa_tl \tl_new:N \l_knuthshuffle_tempb_tl \int_new:N \l_knuthshuffle_random_int \prop_new:N \l_knuthshuffle_newperm_prop ...

7

An implementation with expl3; the complete list is generated, so relieving PGF from the burden of doing the work by itself. \documentclass{article} \usepackage{xparse,tikz} \ExplSyntaxOn \NewDocumentCommand{\mpfor}{mm} {% #1 = variable, #2 = keys \cfr_mpfor:nn { #1 } { #2 } } \keys_define:nn { cfr/mpfor } { start .fp_set:N = \l_cfr_mpfor_start_fp, ...

6

This is not really simple method, and not really elegant, but ... is one possibility. This is a TikZ only solution. And it can be adapted to add other keys (like second, random step, exclusive start, exclusive end, ...). \documentclass[border=5pt,tikz]{standalone} \pgfkeys{ /stepfor/.cd, start/.store in={\startvalue}, step/.store in={\stepvalue}, ...

4

If you accept to use a library outside of TikZ, and you want to loop over integers only, you can take for example xinttools. Method 1: using xint only. \documentclass[tikz,border=5pt]{standalone} \usepackage{xinttools} \begin{document} \begin{tikzpicture} \xintFor* #1 in {\xintSeq[2]{-4}{8}} \do { \node at (#1,0) {#1}; } ...

4

First, you cannot nest a \csvreader into another \csvreader. But, you could read the countries, remember them, and then read the bottles. In my following suggestion, I use the list features from the etoolbox package to store the country names into a \countrylist. Next, we loop through this list using \dolistloop which itself uses the \do macro. This \do ...

3

Usual expansion problem: \documentclass[12pt]{article} \usepackage{comment} \usepackage{forloop} \newcounter{probnum} \forloop{probnum}{1}{\value{probnum} < 6}{% \begingroup\edef\x{\endgroup \noexpand\excludecomment{prob\arabic{probnum}}% }\x } \begin{document} \begin{prob1} hidden \end{prob1} shown \end{document} Alternative version ...

3

Since you claimed that you solved your problem, I am here to respond to cfr's comment. Some explanation follows: According to The TeXBook, \char is used to print the desired character. So TeX would treat \char as \ c h a r when {fa-\char97.jpg} is passed as an input. (But it printed an "a" for \subsection, didn't it?) dealing with a count/counter by index ...

3

You have to expand the row number as far as you can before adding it to the \tablines token list. Here's one way of achieving that: \documentclass{article} \newcounter{it} \newcounter{tot} \newtoks\tablines \newcommand{\addtomytablines}[1]{\tablines\expandafter{\the\tablines#1}} \setcounter{it}{2} \setcounter{tot}{7} \loop ...

2

You can do this with two counters, one inside the \addtomytablines command, and one for the main loop. (I don't fully understand why.) I took the liberty of cleaning up your code and writing it in LaTeX. \documentclass{article} \newtoks\tablines \def\addtomytablines#1{\tablines\expandafter{\the\tablines#1}} \newcounter{row} \newcounter{loop} ...

Only top voted, non community-wiki answers of a minimum length are eligible