New answers tagged

3

Not really recursive. But, hey, it works! \documentclass{article} \usepackage{amsmath} \usepackage{xparse} \ExplSyntaxOn \NewDocumentCommand{\recursematrix}{O{B}m} {% #1 is the (optional) symbol for the coefficient, #2 is the step \begin{pmatrix} \passerby_recursematrix:nn { #1 } { #2 } \end{pmatrix} } \tl_new:N \l_passerby_recursebody_tl ...


3

I think the first two matrices are what the OP asked for. I believe I have got the 3rd level, as well. The key is in realizing that the indices are basically in binary (base 2) notation. EDIT, To keep up with egreg, I also did 4th level. \documentclass[landscape]{article} \usepackage[margin=1cm]{geometry} \usepackage{amsmath} \newcommand\Amatrix[2]{% ...


1

Though there are already good answers, I contribute the version, I used for my currently growing Liederbuch-package: \def\TesT#1{ \expandafter\def\csname test\Alph{#1}\endcsname{} } \newcounter{wseva} \setcounter{wseva}{4} \TesT{wseva} \def\doesItExist#1{ \expandafter\ifx\csname test\Alph{#1}\endcsname\relax no \else yes \fi } \begin{document} ...


2

There are a few problems with your code. The code \ifdefined\expandafter\AuthorName\Alph{loopTitleCoverAuthor} tests whether \expandafter is defined. However the code \expandafter\ifdefined\expandafter\AuthorName\Alph{loopTitleCoverAuthor} would do no good either, because you'd get, when loopTitleCoverAuthor has the value 1, \ifdefined\AuthorName A ...


4

The test \value{A} < \value{B} works for me. I've used \@ifundefined{csname}{true}{false} where csname is the command name to be tested without the escape character \. The most important thing here is constructing the various command names, with \csname foo\Alph{...}\endcsname. \documentclass{article} \usepackage{forloop} ...


3

If you got trouble getting your data parsed the right way by the foreach-statement, you could do the following. Evaluate the values you need in the outer loop with evaluate and just pass them as the min/max values to the foreach. \foreach [count=\i, evaluate=\i as \ymin using int(\x-1), evaluate=\i as \ymax using int(\x+1)] \x in ...


5

Assunming that the input to \dothis is exactly one letter long in each case (which holds for this specific example -- so I guess it's the actual use case) you could simply use \expandafter: \foreach \n in {a,b,c,e} {\expandafter\dothis\n}. Full example \documentclass{beamer} \usepackage{tikz} \makeatletter \newcommand*{\dothis}[1]{% \stringcases {#1}% {% ...


3

You should accumulate the partial arrows; using \foreach is simpler: \documentclass[10pt,a4paper]{article} \usepackage[english]{babel} \usepackage{tikz-cd} \usepackage{etoolbox} \newcommand{\smallcube}[1]{% \begin{tikzcd}[ampersand replacement=\&] \gdef\partialcube{} \foreach \n in {1,...,#1} { \gappto\partialcube{ {} \arrow[r] \& } ...


4

Here's a \prg_replicate:nn version that works over cell boundaries and get's finished after that. \documentclass{article} \usepackage{longtable} \usepackage{xparse} \ExplSyntaxOn% \int_new:N\g_macmadness_int% \newcommand{\runacross}[2]{% \int_gzero:N \g_macmadness_int \prg_replicate:nn {#1}{% \int_gincr:N \g_macmadness_int ...


5

The cells in table environments (tabular, longtable, ...) are also groups, thus the internal loop definitions and the value for \n are lost after the first cell/group. Typical workaround is to put the contents into a macro or token register first: \documentclass{article} \usepackage{longtable} \begin{document} \newcount\n \n=0 \begin{longtable}{ccc} ...


3

Use \State to begin a new line for each simple statement (as you have done later for "something"): \documentclass{article} \usepackage{algpseudocode} \begin{document} \begin{algorithmic} \Function{newCenterCalculation}{$data[vector]$} \State {data\Call{.forEach}{point$\Rightarrow$}} \For{i $<$ point.size()} \State {something} ...


3

Edit I posted this answer before the MWE appeared, so I didn't know that the algpseudocode package was being used. Still... I would use the listings package: \documentclass{article} \usepackage{listings} \begin{document} \begin{lstlisting} data_points.foreach { point => for(i <- point.size()) { do something.... } ...



Top 50 recent answers are included