Tag Info

Hot answers tagged

36

Merry Christmas! The syntax is \textwheel{string}{inner_color}{outer_color}{reps}{fade_length} where reps is the number of repetitions, and fade_length is the length over which the fade from the inner to outer color occurs (upon a recent EDIT, it can now be smaller or larger than the string length and work appropriately). If set to 0pt, it sets the ...


12

With LuaTeX you can use the script language Lua: \documentclass{article} \usepackage{luacode} \begin{luacode} function permute(n) local tab = {} for i = 1, n do tab[i] = i end for i = 1, n do local j = math.random(i, n) tab[i], tab[j] = tab[j], tab[i] end for i = 1, n do tex.print("\\shortstack{"..i.."\\\\"..tostring(tab[i]).."} ") ...


10

You can count how many elements there are in one of the arrays and use that number as the foreach limit. Then every spin accesses one element of the arrays; \documentclass[tikz]{standalone} \def\firstlist{{0,1,2}} % <== Notice the double brace for array notation \def\secondlist{{0,1,2}} \newcommand{\testa}{ \pgfmathdim{\firstlist}%Get the number of ...


10

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 {{\secondlist}[\c-1]}] in \firstlist { \draw(0,\x)--(1,\y); } } \begin{document} \begin{tikzpicture} \testa \end{tikzpicture} \end{document} An extended ...


9

I'm not so sure you want to do it. ;-) \documentclass{article} \usepackage{xparse} \def\xforeach#1#{\xforeachaux{#1}} \ExplSyntaxOn \NewDocumentCommand{\xforeachaux}{mm} { \carlitos_xforeach:nn { #1 } { #2 } } \seq_new:N \l_carlitos_xf_first_seq \seq_new:N \l_carlitos_xf_second_seq \seq_new:N \l_carlitos_xf_list_seq \cs_new_protected:Npn ...


9

A classical implementation allowing also exponents: \documentclass{article} \makeatletter \newcommand{\env}[1]{% \sigma \expandafter\startm@keprimes\expandafter{\romannumeral#1000@}% } \def\startm@keprimes#1{\m@keprimes{}#1} \def\m@keprimes#1#2{% \if#2@% \expandafter\@firstoftwo \else \expandafter\@secondoftwo \fi {#1}% ...


9

Use it without a second member (which would denote the step): \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: ...


9

I think the problem arises because when the sprial changes direction two squares are drawn at each corner. For example, if the spiral is moving right, when the x < x_max condition is not met the direction is changed but the y coordinate is not moved up so the next square is drawn in the same place as the last square. I've corrected this in the code below ...


9

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> % Date: July 4, 2007 % Version: 20120102 % Original source: efnet #TeX % License: Public Domain % Requirements: Plain TeX % \nopagenumbers ...


8

Here's an implementation of the Knuth shuffle algorithm with expl3. \documentclass{article} \usepackage{amsmath,xparse} \input{random} \ExplSyntaxOn \cs_new_eq:NN \knuthshuffle_get_random:Nnn \setrannum \tl_new:N \l_knuthshuffle_tempa_tl \tl_new:N \l_knuthshuffle_tempb_tl \int_new:N \l_knuthshuffle_random_int \prop_new:N \l_knuthshuffle_newperm_prop ...


8

There are various ways to accomplish your needs. \documentclass[11pt]{article} \usepackage{xparse} % for D % for A, B, C \newcounter{mycount} \makeatletter \newcommand\repeatstringA[2]{% \setcounter{mycount}{#1}% \ifnum\themycount>0 #2% \addtocounter{mycount}{-1}% \expandafter\@firstofone \else \expandafter\@gobble \fi ...


8

Although using multiple \foreach loops does make the "semantic" layout of the network a little unclear, it certainly makes its creation easier. I have taken some liberties with the required connections otherwise the network starts to look a bit cluttered. \documentclass[tikz,border=5]{standalone} \usetikzlibrary{arrows.meta,calc} \begin{document} ...


8

The usual approach to grabbing tokens with a delimiter in TeX would be something like \catcode`\@=11 % \def\grabargs#1#2#3{% \def\grabargs@aux##1#2{% \ifx\relax##1\relax% \else #3{##1}\par \expandafter\grabargs@aux \fi }% \grabargs@aux#1#2\relax#2 } \def\print#1{`{\tt #1}'} \catcode`\@=12 % \grabargs {Humpty Dumpty sat on a ...


8

When using xpatch (or the original commands in etoolbox) for patching macros, it's recommended to use the builtin diagnostics, that is \tracingpatches and the “fail” argument. If you add \tracingpatches to the preamble, before your usage of \IfPackageLoaded, you'll get the message [debug] tracing \pretocmd on input line 26 [debug] analyzing ...


7

Repetition via \romannumeral trick The number is multiplied with 1000 to convert it to a roman number. Then TeX produces a long string consisting of letter m, whose length is the original number. Then \repeatstringX looks at the next token, if it is an m, then the string unit is output. Otherwise the next token is the end marker F and the loop stops. ...


7

You could always "roll your own" solution, but it would require considerable work to make it look as nice as \foreach: \documentclass[tikz,border=5]{standalone} \makeatletter \def\attxt{@} \long\def\frch#1#2#3{\long\def\frchaction##1##2{#3}% \def\lsta{}\def\lstb{}% \edef\lst{#1,@,/#2,@,}\expandafter\@frch\lst\@} \def\@frch#1,#2/#3,#4\@{% ...


7

There are a number of possible approaches to doing this without the complexity: I'll cover a couple using expl3. First, if you don't mind keeping things non-expandable then you could do something like \documentclass{article} \usepackage{expl3} \ExplSyntaxOn \cs_new_protected:Npn \For #1#2#3#4 { \int_step_inline:nnnn {#1} {#2} {#3 - 1} {#4} } ...


7

You have to use a \protected@xdef: The first parameter of \coljoin as defined below can be used to pass in the macro that needs to be executed for each entry. It defaults to just passing the cell data thru without any additional processing. References: How do I use the ampersand (&) inside a foreach or conditional (or other group/environment) when ...


7

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}


7

You can legally place \global only before an assignment command: \global\def \global\let \global\mathchardef \global\catcode \global\advance and so on. One should note that \global wants and looks for a suitable command following it, doing expansion. For instance, etoolbox defines \newrobustcmd{\cslet}[2]{% \expandafter\let\csname#1\endcsname#2} so ...


7

An implementation with expl3; the complete list is generated, so relieving PGF from the burden of doing the work by itself. \documentclass{article} \usepackage{xparse,tikz} \ExplSyntaxOn \NewDocumentCommand{\mpfor}{mm} {% #1 = variable, #2 = keys \cfr_mpfor:nn { #1 } { #2 } } \keys_define:nn { cfr/mpfor } { start .fp_set:N = \l_cfr_mpfor_start_fp, ...


7

The page builder is asynchronous and TeX doesn't have any clue where a page ends when typesetting a paragraph. Only when a paragraph has ended page breaking decisions are made. My strategy is to build the gigantic paragraph in a box that's then compared to the desired text height. If it's still below it, a new box is prepared with more repetitions. When we ...


6

This is not really simple method, and not really elegant, but ... is one possibility. This is a TikZ only solution. And it can be adapted to add other keys (like second, random step, exclusive start, exclusive end, ...). \documentclass[border=5pt,tikz]{standalone} \pgfkeys{ /stepfor/.cd, start/.store in={\startvalue}, step/.store in={\stepvalue}, ...


6

A simple solution supporting a max of four primes \documentclass{article} \newcommand{\env}[1]{$ \sigma\ifcase#1% \or'\or''\or'''\or''''\else^{#1}\fi $} \begin{document} Example: \env{1} \env{2} $\sigma''$ \env{4} \env{5} \end{document} I know it's ugly to type all the cases but in this way you can preserve the right spacing between ...


6

Here's a LaTeX3 implementation. \documentclass{article} \usepackage[margin=1cm]{geometry} % to fit in one page \usepackage{blindtext} \usepackage{xparse} \newcommand{\modulespec}[2]{\section{#1} #2} \ExplSyntaxOn \NewDocumentCommand{\definemodules}{m} { \farley_definemodules:n { #1 } } \tl_new:N \l_farley_temp_tl \cs_new_protected:Npn ...


6

One issue you currently have is trying to create a \frame inside another frame. Moreover, \frame takes an argument, which you're not supplying in a proper way. Here is the etoolbox implementation that inserts each item in the list on a separate frame: \documentclass{beamer} \usepackage{etoolbox} \makeatletter \newcommand\makeenumerate[1]{% ...


6

You get ! Missing = inserted for \ifnum. because \repeat has \ifnum#1>\z@ so #1 has to expand to a number, but it is \repeat{2}{1} which includes many non expandable constructs such as \@repeat, \relax and \advance. Also although unrelated to the error in this fragment, it is a very bad idea to redefine \repeat as it is part of the basic \loop ...


6

This loop just uses expansion. In order to use #1 as the loop counter it is easiest to define it anew each time, if you didn't want access to the counter you could more easily use \myrepeat{5}{some code} Note i didn't use \repeat as that name is taken in the existing \loop syntax. \documentclass{article} \def\myrepeat#1{\ifnum#1=0 ...


6

You need a \the before the \count255 in the coordinate. \documentclass{article} %\url{http://tex.stackexchange.com/q/176229/86} \usepackage{tikz} \begin{document} \begin{tikzpicture} \count255 = 1 \loop \draw (0,0) -- (0,\the\count255) ; \advance\count255 by 1 \ifnum\count255 < 3 \repeat \end{tikzpicture} \end{document}


5

Commands such as \\ or \textbf don't survive \edef; you need \protected@edef: \newcommand\eAddTableTokens[1]{% \protected@edef\MyTempTableTokens{#1}% \expandafter\AddTableTokens\expandafter{\MyTempTableTokens}% }



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