Tag Info

Hot answers tagged

37

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]).."} ") ...


12

With no package, only classical TeX: \newcount\tmpnum \def\myscale#1#2{% \tmpnum=#1 \the\tmpnum \loop \ifnum\tmpnum<#2 \advance\tmpnum by1 \quad\the\tmpnum \repeat } Using eTeX extension and axpandable solution: \def\myscale#1#2{#1% \ifnum#1<#2 \space ...


11

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 ...


10

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 ...


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 ...


10

With no package (but requiring e-TeX), a fully expandable solution: \documentclass{article} \makeatletter \newcommand{\myscale}[2]{% \ifnum#1=#2 $#1$\expandafter\@gobble \else \expandafter\@firstofone \fi {\myscale@aux{#1}{#2}}% } \newcommand{\myscale@aux}[2]{% \ifnum#1>#2 \expandafter\@firstoftwo \else ...


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}% ...


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

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

EDIT Unlike the original code, this does not produce a compilation error when first typeset. Nor does it rely on the titling package. I define \subtitle{} and \@subtitle to handle the subtitles. titlepage is used within a redefined \maketitle to create the actual title pages. Since we redefine \maketitle, we can issue \maketitle, \title etc. multiple ...


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 ...


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

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

Here's a LuaLaTeX-based solution. The two arguments of \myscale can be any expressions that evaluate to numbers under TeX's and Lua's combined rules. If the macro's second argument is smaller than the first, nothing is printed. % !TEX TS-program = lualatex \documentclass{article} \newcommand{\myscale}[2]{\directlua{% for i = #1, #2 do tex.print(i) ...


7

Using \whiledo of package ifthen: \documentclass{article} \usepackage{ifthen} \newcounter{mycount} \newcommand{\myscale}[2]{ \setcounter{mycount}{#1} \whiledo{\value{mycount}<#2} {\arabic{mycount}, \stepcounter{mycount}}% \arabic{mycount}.} \begin{document} \myscale{1}{6}\par \myscale{-4}{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

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

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, and the pattern can be any number of column specifiers, @{some code}, !{some code}, >{…}, <{…}. Some part of this syntax depends on the array package – ...


7

interesting question, you can do this : \documentclass{article} \usepackage{pgffor} \newcommand{\myscale}[2]{% \foreach \index in {#1,...,#2}{\index\space\space}% } \begin{document} \myscale{1}{6} \myscale{9}{17} \end{document}


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

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

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

Just for kicks, with expl3/xparse: \documentclass{article} \usepackage{xparse} \ExplSyntaxOn \cs_new_protected:Npn \alain_range:nnN #1#2#3 { \seq_clear:N #3 \int_set:Nn \l_tmpa_int { #1 } \int_set:Nn \l_tmpb_int { #2 } \int_while_do:nNnn \l_tmpa_int < \l_tmpb_int { \seq_push:NV #3 \l_tmpb_int \int_decr:N \l_tmpb_int } \seq_push:NV #3 ...


6

It is easy to program with xstring (with no unuseful test): \documentclass{extarticle} \usepackage{xstring} \newcommand\fios{hellow world} \newcommand\occurs[1]{% \ifhmode\par\fi\begingroup\expandarg \StrDel{#1}{ }[\tempstr]% \occuraux\endgroup } \newcommand\occuraux{% \unless\ifx\tempstr\empty ...



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