2022 Developer Survey is open! Take survey.

Hot answers tagged

50 votes
Accepted

\foreach not behaving in axis environment

According to pages 470-471 of the pgfplots documentation: (Note: in pgfplots documentation v1.17, the page range has changed to 544-545.) Keep in mind that inside of an axis environment, all loop ...
user avatar
44 votes
Accepted

Make fireworks with only text

2016 Christmas Edition I experimented here with trying to produce a geometric figure near the firework core, by using simple glyphs like + and -. When duplicated with rotation and shift, I think the ...
user avatar
30 votes
Accepted

Repeating the same column type

No pgffor package is required for this; just write your table preamble as: \begin{tabular}{l *{6}{n{2}{3}}} The general syntax is: *{n}{column(s) pattern} where n is the number of repetitions, ...
user avatar
  • 259k
28 votes
Accepted

Repeat characters n times

No packages: \documentclass{article} \makeatletter \newcount\my@repeat@count \newcommand{\myrepeat}[2]{% \begingroup \my@repeat@count=\z@ \@whilenum\my@repeat@count<#1\do{#2\advance\my@...
user avatar
  • 985k
28 votes

How to define von Neumann natural numbers (newcommand, with for loop)?

I think its more natural to use recursion than a loop, something like \documentclass{article} \usepackage{amssymb} \newcommand\nnatset[1]{% \ifnum#1=0 \varnothing \else \ifnum#1>1 \nnatset{\...
user avatar
23 votes
Accepted

Make my infinite squares math-proof

Update The issue with scaling in graphicx is fixed in the development sources for the next release (probably January 2017) and the issue with the xetex driver discussed in the comments is fixed and ...
user avatar
22 votes
Accepted

How to repeat over all characters in a string?

You can use \@tfor. I provide also a better redefinition of the dot under according to your wish: \documentclass{article} \usepackage{graphicx} \let\d\relax \DeclareRobustCommand{\d}[1]{% \oalign{#...
user avatar
  • 985k
20 votes

Empty document, only pagenumber, 500 pages needed

\documentclass[pagenumber=footright, DIV=20, fontsize=16]{scrartcl} \usepackage[automark]{scrlayer-scrpage} \pagestyle{scrheadings} \ihead{} \ofoot[\pagemark]{\pagemark} \chead{} \cfoot[]{} \ohead{} \...
user avatar
19 votes
Accepted

Foreach loop between two lists

Here is a very simple solution: \documentclass{article} \usepackage{tikz} \def\firstlist{0,1,2} \def\secondlist{0,1,2} \newcommand{\testa}{ \foreach \x [count=\c,evaluate=\c as \y using {{\...
user avatar
  • 67.8k
18 votes

a circular figure with lines behind a disc going off in all directions like a sun

You don't need to connect nodes. First draw background lines. All starting from (0,0). \foreach \angle in {0,1,...,359} \draw[cyan!50!black] (0,0)--++(\angle:4); Second, draw a circular node white ...
user avatar
  • 127k
18 votes
Accepted

New Pentagonal Tiling

I'm not sure what you are seeking in the end, but on this, the penultimate Eve of Christmas, a few nested \stackinsets make for a wonderfully festive stained glass imitation. God bless us, every one! ...
user avatar
17 votes

Make fireworks with only text

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&...
user avatar
  • 73k
16 votes
Accepted

Generate the n-th letter of the alphabet in a tikz loop

One possibility: \documentclass[a4paper,10pt,landscape]{article} \usepackage{tikz} \begin{document} \begin{tikzpicture} \foreach [count=\i] \j in {a,b,...,j}{ \node (\i) at (\...
user avatar
15 votes
Accepted

Use array in loop in tikz

The problem here is that arrayjob does some nasty stuff to get the value out of the array and this is not compatible with how \includegraphics handles its arguments. There are two solutions: 1. ...
user avatar
  • 14.6k
14 votes

Preparing a special exam sheet for every student

You can use the odsfile package, which supports manipulations with OpenDocument Spreadsheet files. You need to convert your excel file to ODS using LibreOffice (Excel can do this as well, but ...
user avatar
  • 44.9k
14 votes
Accepted

Power of number in loop in TikZ

Just do the math before the inner loop. foreach doesn't parse math in the iterable list \begin{tikzpicture} \foreach \a in {1,2,3} { \pgfmathtruncatemacro\aa{2^\a} \foreach \b in {1,2,...,\...
user avatar
  • 154k
14 votes
Accepted

Triangulation in tikz

Example, which uses both smart stuff (grid), \foreach loops and manual elements: \documentclass{article} \usepackage{tikz} \begin{document} \begin{tikzpicture} \draw (0, 0) grid[step=1cm] (3, 3)...
user avatar
14 votes
Accepted

a circular figure with lines behind a disc going off in all directions like a sun

To connect the edges of the circle you can use the border anchors of nodes (A.120) and the to Operator to connect it to the outer square. \documentclass[tikz, border=5mm]{standalone} \begin{...
user avatar
14 votes
Accepted

Looping over strings

If I modify your test a bit to make a shorter argument for tracing \documentclass{article} \def\test#1{{ \tracingonline=1 \tracingmacros=1 \markletters{#1} } \typeout{TYPEOUT: \markletters{#1}} } \...
user avatar
14 votes
Accepted

How can I fill an arbitrarily sized matrix with asterisks?

with \pAutoNiceMatrix of nicematrix. \documentclass{article} \usepackage{nicematrix} \begin{document} $\pAutoNiceMatrix{7-7}{*}$ \end{document}
user avatar
  • 25.1k
13 votes

Calling several tex files with a loop?

There are numerous ways to do this, but the simplest given what you've described is to use the pgffor package which provides a simple syntax for such loops: \documentclass{article} \usepackage{pgffor}...
user avatar
  • 201k
13 votes

Empty document, only pagenumber, 500 pages needed

A variant with package multido (50 bytes): \documentclass[DIV=20, fontsize=16]{scrartcl} \usepackage{lmodern} \usepackage[automark]{scrlayer-scrpage} \pagestyle{scrheadings} \cfoot{} \ofoot[\pagemark]...
user avatar
13 votes

Triangulation in tikz

A (hopefully accurate) scalable version for arbitrary size (can't say if it's mathematically useful but was fun to make). alphalph used to generate arbitrary number of labels some increased spacing ...
user avatar
  • 4,082
13 votes
Accepted

How to create a for loop in math mode

\documentclass{article} \usepackage{tikz} \begin{document} \[ F_x = q\left[\foreach \i/\p in {x/, y/+, z/+} {\p\frac{\partial E_\i}{\partial \i}\mathrm{d}\i} \right] \] \end{document} Note: ...
user avatar
  • 13.2k
13 votes
Accepted

What's the best way of typing the following 58 equations into LaTeX?

Here's a possible implementation; the delimiters can be changed. \documentclass{article} \usepackage{amsmath,multicol} \usepackage{xparse} \ExplSyntaxOn \NewDocumentCommand{\constraints}{omO{x}} { ...
user avatar
  • 985k

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