Tag Info

Hot answers tagged

38

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

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


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


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


10

You could use the TikZ polygon shapes in a \foreach loop. Add color and styles as you like. Key points are regular polygon shape of the shapes.geometric library relative positioning of the positioning library remember the last node, using characters a, b, ... for node names using the south anchor for positioning and anchoring at the same base line ...


9

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{#1\cr\hidewidth\scalebox{0.5}{\textbullet}\hidewidth\cr}% } \makeatletter \newcommand{\ds}[1]{% \@tfor\next:=#1\do{\d{\next}}% } \makeatother ...


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

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


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


8

Update I simplified the code using a \pic for the fundamental domain. For the color, I present three options: Randomly selecting shades of a fixed color (red, in my example), gives different coloring for each piece: \documentclass[tikz]{standalone} \usetikzlibrary{calc} \tikzset{ fundamental/.pic={ \draw[,scale=0.4,black,fill=red!\tmp,rotate ...


8

One possibility: \documentclass[a4paper,10pt,landscape]{article} \usepackage{tikz} \begin{document} \begin{tikzpicture} \foreach [count=\i] \j in {a,b,...,j}{ \node (\i) at (\i, \i) {\j} ; } \end{tikzpicture} \end{document} percusse mentions the alphalph package in a comment, and its \alphalph does exactly what you ...


8

The definitions of \B and \C are the problem: \def\B{\advance\cnt@a by-1} \def\C{\ifnum\cnt@a>0} TeX does not stop at the end of the numbers, but continue expanding until it finds a token, which is not a digit, e.g.: \B1234\relax will decrease \cnt@a by -11234, not by -1. Or \B\C Then the \ifnum is executed before the counter is decreased. Both ...


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

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

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

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

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


6

This is a Lua snippet with some CJKV characters in the strings. I've selected an opentype font from TeX Live, but it doesn't contain some diacritical letters (e.g. č, ř and š), let me hope it is sufficient as a demonstration of handling UTF-8 strings. We run lualatex mal-letters.tex. % lualatex mal-letters.tex \documentclass[a4paper]{article} ...


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

You can use the macro \scanargs \macro x1,y1 x2,y2 ... xn,yn; and then you can use the scanned arguments in your \macro in the form \x1, \x2, ... \x9, \y9, but \x{10}, \y{22} etc. I show the example using your example: \documentclass{article}\usepackage{tikz} \newcount\tmpnum \def\scanargs #1#2;{\let\tmp=#1\tmpnum=0 \scanargsA #2 {},{} } \def\scanargsA ...


6

This would be my first try, using a counter (no need of additional packages): \documentclass[a4paper,10pt,landscape]{article} \usepackage{tikz} \newcounter{cnti} \begin{document} \begin{tikzpicture} \foreach \i in {0,...,9}{ \setcounter{cnti}{\i}\addtocounter{cnti}{1} \node (i) at (\i, \i) {\alph{cnti}} ; } ...


6

Like this? \documentclass{article} \usepackage{pgffor} \usepackage{graphicx} \begin{document} \foreach \x in {a,b,c} { \begin{figure}[p] \includegraphics[scale=.5]{example-image-\x} \caption{So, three figures displayed, and this one has the number \x\ of the letter position (or iteration count)} % ie. 1 for a, 2 for b, 3 for c \end{figure} ...


5

As a single path: \documentclass[tikz,border=5]{standalone} \begin{document} \tikz\draw (0,0) \foreach \i in {3,...,10} \foreach \j in {1,...,\i}{ -- ++(360/\i*\j:1) }; \end{document}


5

\documentclass[12pt]{article} \usepackage{forloop} \begin{document} \newcounter{x} \forloop{x}{0}{\value{x}<5}{\noindent value is \arabic{x}\\} \end{document} You can also print the numbers as strings (zero, one, two , ...), if you load the fmtcount package and instead of \arabic{x} you can use \numberstring{x}.



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