Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

This question already has an answer here:

How to make a command (without testing) that contains a foreach loop that may count from 1 to 1 if necessary ?

\documentclass{minimal}
\usepackage{tikz}

\newcommand{\boucle}[1]{%
    \foreach \x in {1,2,...,#1} {\x } 
    }

\begin{document}

From 1 to 5 : \boucle{5}

From 1 to 2 : \boucle{2}

From 1 to 1 : \boucle{1}

\end{document}

enter image description here

share|improve this question

marked as duplicate by ChrisS, Werner, Claudio Fiandrino, Svend Tveskæg, Guido Mar 6 at 7:29

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

    
Thank to both of you. –  Tarass Mar 6 at 5:35

2 Answers 2

up vote 7 down vote accepted

Remove the second item.

\documentclass[preview,border=12pt,varwidth]{standalone}
\usepackage{pgffor}

\newcommand{\boucle}[1]{%
    \foreach \x in {1,...,#1} {\x } 
    }

\begin{document}

From 1 to 5 : \boucle{5}

From 1 to 2 : \boucle{2}

From 1 to 1 : \boucle{1}

\end{document}

enter image description here

share|improve this answer
1  
For the specific case, it is possible to load the sole pgffor package rather than tikz. –  Claudio Fiandrino Mar 6 at 6:36

Use it without a second member (which would denote the step):

enter image description here

\documentclass{article}
\usepackage{tikz}% http://ctan.org/pkg/tikz

\newcommand{\boucle}[1]{\foreach \x in {1,...,#1} {\x }}

\begin{document}

From 1 to 5 : \boucle{5}

From 1 to 2 : \boucle{2}

From 1 to 1 : \boucle{1}

\end{document}

The same result could be achieved using multido:

\usepackage{multido}% http://ctan.org/pkg/multido
\newcommand{\boucle}[1]{\multido{\i=1+1}{#1}{\i}}

Other options also exist, of course.

share|improve this answer
1  
For the specific case, it is possible to load the sole pgffor package rather than tikz. –  Claudio Fiandrino Mar 6 at 6:35

Not the answer you're looking for? Browse other questions tagged or ask your own question.