Hot answers tagged

21

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@repeat@count\@ne}% \endgroup } \makeatother \begin{document} \myrepeat{4}{x} \myrepeat{4}{\myrepeat{2}{x}} \end{document} Why the group? It allows nested ...


15

The \foreach command has its quirks; however, the behaviour shown in your MWE is consistent with section 56 of the PGF manual (2.10), which describes in detail what the ... does inside \foreach. Consider \foreach \xx in {x,y,...,z}. The difference d=y-x is used to "fill in" the elements implicitly specified by ... (see p.505): In this situation, the part ...


7

\documentclass[pstricks,preview,margin=5mm]{standalone} \usepackage{multido} \def\obj#1{% \begin{pspicture}(-2,-2)(2,2) \multido{\i=#1+30}{12}{\rput{\i}(0,0){\pswedge*(0,0){2}{0}{15}}} \end{pspicture}% } \begin{document} \obj{0}\obj{15}% \end{document} Note: Starred \pswedge does not need linestyle=none,linewidth=0 to remove the outline ...


5

\documentclass{article} \usepackage{pstricks,multido} \begin{document} \begin{pspicture} \multido{\i=0+15}{24}{% \def\dowedge{\pswedge}% \ifodd\i\def\dowedge{\pswedge*}\fi \dowedge(0,0){2}{\i}{\number\numexpr\i+15}% } \end{pspicture} \end{document} Potentially one could also draw a filled, black circle and insert 12 white wedges. As a ...


5

I show the plain TeX-like solution but it works in LaTeX too because only eTeX primitives and \newcount macro are used. We needn't any LaTeX packages. \def\nederst#1{\the\numexpr #1*(#1+1)/2 \relax} \def\iAlt#1{\the\numexpr #1*(#1+1)*(#1+2)/6 \relax} \newcount\i \i=1 \def\skyIDtable{ \the\i & \the\i & \the\i & \hbox to1em{\hss\nederst\i} &...


4

It's an expansion problem in \regtotcounter; I'll investigate whether it's possible to avoid the cumbersome code, but here's a working solution: \documentclass{article} \usepackage{multido,totcount} \multido{\i=1+1}{3}{% \begingroup\edef\x{\endgroup \noexpand\newtotcounter{compteurCh\romannumeral\i}% }\x } \begin{document} \thecompteurChi \...


4

More complicated code, but way simpler syntax: \documentclass{article} \usepackage[T1]{fontenc} \usepackage[utf8]{inputenc} \usepackage[danish]{babel} \usepackage{xparse,siunitx,booktabs} \ExplSyntaxOn \DeclareExpandableDocumentCommand{\nederst}{m} { \fp_eval:n { #1 * (#1+1)/2 } } \DeclareExpandableDocumentCommand{\iAlt}{m} { \fp_eval:n { #1 * ( #1 ...


4

The transposition is not as straight-forward. You'll have to cycle through each row individually: \documentclass{article} \usepackage{siunitx,multido,booktabs} \ExplSyntaxOn \cs_new_eq:NN \calc \fp_eval:n \ExplSyntaxOff \newcommand*\nederst[1]{\calc{#1*(#1+1)/2}} \newcommand*\iAlt[1]{\calc{#1*(#1+1)*(#1+2)/6}} \begin{document} \centering \...


4

The answer is probably "don't do that". \paragraph is (by default) an inline heading this means that it is held back until the next paragraph starts so that it can be typeset as part of that paragraph. But here the next paragraph does not start until the loop has spun and so \i has incremented. If the paragraph is within the loop, it all works better: \...


4

FWIW, in ConTeXt you can use \dorecurse to repeat something. For example: \dorecurse{10}{Hello world. } will print Hello world. 10 times. The current iteration number is stored in the macro \recurselevel.


3

I used latex-dvips-ps2pdf sequence with TeXLive 2015 and did not find any problem using either standalone or article or article with preview. standalone \documentclass[pstricks]{standalone} \usepackage{pst-solides3d} \colorlet{Green}{green!100!white!40} \begin{document} \multido{\iA=0+15}{18}{% \psset{lightsrc=viewpoint,viewpoint=30 \iA\space 20 rtp2xyz,...


3

The problem in this case is with \addvspace (hidden in the definitions of center and \centering) being called outside vmode, as the following simple example demonstrates: \documentclass{article} \usepackage{rotating} \begin{document} \begin{sideways} \addvspace{3em} This is some centered text... \end{sideways} \end{document} This code triggers the "...


3

Use \DTLforeach: \begin{filecontents*}{students.csv} firstname,lastname FirstName1,LastName1 FirstName2,LastName2 FirstName3,LastName3 \end{filecontents*} \begin{filecontents*}{\jobname-exam.tex} \noindent Student ID = \fbox{\studentid}\quad \studentfirstname\ \studentlastname \bigskip Solve the equation $x-1=0$. \end{filecontents*} \documentclass{...


3

You can construct the inner part of the table outside the tabular in the form of a macro, and then set it with the construction of the table by just calling the macro. Improper expansion of "sensitive elements" (& and \\) are protected via \protected@xdef - a global expansion definition. With each iteration of \multido, a new row is added to the ...


2

You also can use commands from pst-fp: \documentclass[border=3pt]{standalone} \usepackage{pst-node, multido} \usepackage{auto-pst-pdf} \begin{document} \begin{pspicture} \psset{unit =0.6} \multido{\i=0+3}{10}{\pstFPmul{\angle}{\i}{10}% \rput{\angle}(\i,0){\psellipse[linecolor=red](0,0)(0.5,1)} } \end{pspicture} \end{document}


2

I don't see any real problem with your code. There is \newtotcounter that creates a counter and registers it with totcount in one go, which will save some coding. Here is a complete document showing it working. \documentclass{article} \usepackage{multido,totcount} \newcounter{AuxCounter} \renewcommand{\theAuxCounter}{\roman{AuxCounter}} \multido{\i=1+1}...


2

Avoiding name clashes is achieved by using unique names for each identifier in the loop. However, in this case, passing arguments directly on to the inner \multido means they're not expanded until used, at which time they also need to be set. "Pre-expansion" (declaring macros that contain an expanded version of the arguments) helps avoid this: \...


2

The raising of a negative number to a power seems to be the problem. Using abs around \Nx for the square works: \documentclass[a4paper,10pt]{article} \usepackage{multido} \usepackage{fp} \usepackage{pstricks} \begin{document} \begin{pspicture}(-5,5)(-5,5) \multido{\Nx=4+-0.5}{12}{ \FPeval{\moncalcul}{abs(\Nx)^2/4+1} \psdots(\Nx,\moncalcul) } \end{...


2

\foreach from pgffor package is also available by default in PSTricks. As a result, you don't need to use \multido. \documentclass[pstricks,preview,margin=5mm]{standalone} \begin{document} \begin{pspicture}(-2,-2)(2,2) \foreach \i [evaluate = \i as \j using \i+15] in {0,30,..., 330}{\pswedge*{2}{\i}{\j}} \end{pspicture} \end{document} The output is ...


2

standalone is cropping an incorrect location on the page when only using pstricks as the class option under latex > dvips > ps2pdf. Rather compile with xelatex or add the preview option to the class: \documentclass[pstricks,preview]{standalone} \usepackage{pst-solides3d} \colorlet{Green}{green!100!white!40} \pagestyle{empty}% Remove header/footer \begin{...


2

Using etoolbox's \docsvlist: \documentclass{article} \usepackage{etoolbox} \makeatletter \newcommand{\preguntas}[1]{% \begingroup \count@\z@ \def\@tempa{}% \def\@ddcomma{}% \loop \ifnum\count@<#1 \advance\count@\@ne \edef\@tempa{\@tempa\@ddcomma\the\count@}% \def\@ddcomma{,}% \repeat \global\def\@...


1

The error message is ! Undefined control sequence. <inserted text> \Tex l.6 \multido{}{3}{\Tex } showing the undefined command is \Tex (should be \TeX)


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