# Tag Info

## Hot answers tagged loops

7

Using \# simply defines \#. You need something that, given a name, becomes the command with that name. Such a thing exists as a TeX primitive command: \csname ... \endcsname \documentclass{article} \newcommand{\MkVec}[1]{\expandafter\def\csname#1\endcsname{\vec{#1}}} \MkVec{x}\MkVec{y} \begin{document} Some vectors: $\x$, $\y$. \end{document} If you ...

6

Use any list-processing package. Here's an etoolbox version: \documentclass{article} \usepackage[margin=2cm]{geometry}% http://ctan.org/pkg/geometry \usepackage{etoolbox}% http://ctan.org/pkg/etoolbox \newlength\cardheight \newlength\cardwidth \setlength\cardheight{0.4\textheight} \setlength\cardwidth{0.49\textwidth} \newcommand{\card}[1]{% ...

6

A pure LaTeX solution (no extra package needed): \documentclass{article} \usepackage[margin=2cm]{geometry} \newlength\cardheight \newlength\cardwidth \setlength\cardheight{0.4\textheight} \setlength\cardwidth{0.49\textwidth} \newcommand\card[1]{% \fbox{\begin{minipage}[t][\cardheight][t]{\dimexpr\cardwidth-2\fboxsep-2\fboxrule\relax} ...

4

You need to remove the parentheses from the inner loop. Namely, instead of passing {\targets} to the \foreach loop, you should be passing \targets. \documentclass{standalone} \usepackage{tikz} \begin{document} \begin{tikzpicture} \node (a) at (0, 1) {}; \node (b) at (0, -1) {}; \node (c) at (1, 0) {}; \node (d) at (-1, 0) {}; \foreach ...

4

Problems with \foreach aside, I think the syntax \path (b) edge (d) (a) edge (b) edge (c) edge (d); comes much more natural. It is also much easier to change edge options on an edge-to-edge basis (or for more than one edge, too): \path (b) edge (d) {[thick] (a) edge (b) edge[green] (c) edge[red,->] (d)}; Though, a similar thing can still ...

2

The important thing is to be consistent in the way you specify elements in a list to be processed by \foreach. In the approach below, which I find more intuitive, \targets gets expanded to {b} at the first iteration of the outer loop, and to {b,c,d} at the second one. Therefore, specifying \foreach \to in \targets for the inner loop works as expected. ...

1

Adapting this answer, here is a way to use the same XeTeX extensions to put in background colours. I've only done "a" and "e" but it could obviously be extended. \documentclass{article} \usepackage{xcolor} \begin{document} \XeTeXinterchartokenstate = 1 \newXeTeXintercharclass \tta \XeTeXcharclass \a \tta \newXeTeXintercharclass \tte \XeTeXcharclass \e ...

1

Combining the answers to two questions yields a simple solution: Leo Liu's answer to: - soul: broken highlighting with xcolor when using \selectcolormodel and egreg's answer to: - Color all vowels differently in a LaTeX document \documentclass{article} \usepackage{xparse,xcolor} \usepackage[normalem]{ulem} % use normalem to protect \emph ...

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