Tag Info

New answers tagged

6

The short-term answer is: use token lists nested in a sequence. \RequirePackage{expl3} \ExplSyntaxOn \seq_new:N \l_lines_seq \cs_new:Npn \jb_wrap:n #1 { \exp_not:n { {#1} } } \seq_clear:N \l_lines_seq \seq_set_split:Nnn \l_tmpa_seq { \\ } { a & b \\ c & d } \seq_map_inline:Nn \l_tmpa_seq { \seq_set_split:Nnn \l_tmpb_seq { & } {#1} % use ...


7

The way that sequences are implemented means that at that level they can be nested (the nested sequences will be distinct from the outer one). However, what is not available is an interface to store or recover the whole of a sequence. \seq_get:NN \l_my_main_seq \l_tmpa_tl % Available \seq_set:NV \l_my_daughter_seq \l_tmpa_tl % Not available. Similarly, ...


1

Package environ to capture the contents of an environment. LaTeX3 code (package expl3) to split it into lines, cells, and more general programming tools. Rather than making an environment with 4 parameters as I did, you can hard-code some of them in the definition if it is more practical. \documentclass{article} \usepackage{environ} \usepackage{expl3} ...


0

A simple solution, if you know the number of columns: \def\RowMacroIII{{#1}&{#2}&{#3}\\} Usage \RowMacro{a}{b}{c} and \def\RowMacroIV{{#1}&{#2}&{#3}&{#4}\\} Usage \RowMacro{a}{b}{c}{d}


4

For typesetting Sudokus, you can also use the logicpuzzle bundle [CTAN]. \begin{center} \begin{lpsudoku} \setrow{9}{{},2,6,{},{},{},{},{},{}} \setrow{8}{{},{},{},{},{},{},1,7,{}} \setrow{7}{{},{},3,1,{},6,{},{},{}} \setrow{6}{{},6,{},{},5,{},8,{},3} \setrow{5}{{},{},9,2,6,1,7,{},{}} \setrow{4}{5,{},4,{},8,{},{},6,{}} ...


10

I believe that with expl3 it's more straightforward, since it doesn't rely on knowing what's needed to expand and when. \documentclass{article} \usepackage{xparse} \ExplSyntaxOn \seq_new:N \l_wickerson_list_seq \NewDocumentCommand{\printState}{>{\SplitList{,}}m} { \seq_clear:N \l_wickerson_list_seq \ProcessList{#1}{\splitatslash} ...


17

The following two macros need fixing: \newcommand*\@defineLine[2]{% \typeout{Defining wickerson@#1@pos = #2} \expandafter\xdef\csname wickerson@##1@pos\endcsname{#2} } That will define for \@defineLine{a}{10} the macro \wickerson@#1@pos instead of \wickerson@a@pos. Fix: \newcommand*\@defineLine[2]{% \typeout{Defining wickerson@#1@pos = #2} ...


12

A simple LaTeX code, restricted to 5 characters only: \documentclass[10pt,a4paper]{article} \usepackage[english]{babel} \usepackage{pgffor} \def\defPerm|#1#2#3#4#5|{\lccode`\1`#1\lccode`\2`#2\lccode`\3`#3\lccode`\4`#4\lccode`\5`#5} \def\typePerm#1#2#3#4#5{\char\the\lccode`#1\char\the\lccode`#2\char\the\lccode`#3\char\the\lccode`#4\char\the\lccode`#5}% ...


28

The \permute macro is plain TeX, so it's very portable. Why don't you want it cryptic? It does the job, cryptically! % New simplified code -- less cryptic than before :-) \documentclass{article} \def\recurse#1#2#3#4\endmarker{% \dopermute{#1#3}#2#4\endmarker \ifx\relax#4\relax\else % add a \par before \else if there are more than 8 items ...


45

Use the right tool for the job: \documentclass{article} \usepackage{python} \begin{document} \begin{python} import itertools for p in itertools.permutations("suvat"): print ''.join(p) \end{python} \end{document} Run it with pdflatex -shell-escape.


21

run with lualatex \documentclass{article} \usepackage{luacode} \begin{luacode*} local function perm_generate(a, n) if n == 0 then coroutine.yield(a) else for i=1,n do a[n], a[i] = a[i], a[n] -- put i-th element as the last one -- generate all permutations of the other elements perm_generate(a, n - 1) a[n], a[i] ...


33

Here's a better version, with lots of comments! Incidentally, the method of generating all permutations is based on the Knuth shuffle. The latest version of the code avoids nested loops and the separator is a \par token every now and again to avoid building too large boxes (see discussion in comments). I ran it with abcdefghij and it worked, although the ...


7

\documentclass{minimal} \parindent=0pt \usepackage{pstricks} \usepackage[nomessages]{fp} \def\LoadConstants{} \makeatletter \def\const{\@ifnextchar[\const@i{\const@i[r]}} \def\const@i[#1]{\expandafter\const@ii#1,,\@nil} \def\const@ii#1,#2,#3\@nil#4#5{% \if\relax\detokenize{#2}\relax \if\relax\detokenize{#1}\relax ...


6

\def\zzA#1,#2#3\relax#4{ \if t#2 trunc(#4:#1)% \else\if r#2 round(#4:#1)% \else clip(#4)% \fi\fi} % Constant declarator invoked in the preamble \newcommand\const[3][]{% \if\relax\detokenize{#1}\relax \edef\temporary{#3}% \else \edef\temporary{\zzA#1,c\relax{#3}}% \wlog{::\temporary}% \fi ...


2

it maybe a good idea to choose the correct documentclass ;-) \documentclass{article} [ ... ] but you are using the frame environment ... However, with the current pstricks.tex from http://texnik.dante.de/tex/generic/pstricks/ I can do something like: \documentclass{beamer} \usepackage{pst-tools,multido} \SpecialCoor \begin{document} ...


2

\documentclass{beamer} \usepackage[nomessages]{fp} % constants declarator \def\LoadConstants{}% to load PostScript constants defined in the preamble \newcommand\const[3][6]{% \edef\temporary{trunc(#3}% \expandafter\FPeval\csname#2\expandafter\endcsname \expandafter{\temporary:#1)}% \edef\LoadConstants{\LoadConstants ...



Top 50 recent answers are included