Hot answers tagged

42

According to pages 470-471 of the pgfplots documentation: (Note: in pgfplots documentation v1.17, the page range has changed to 544-545.) Keep in mind that inside of an axis environment, all loop constructions (including custom loops, \foreach and \pgfplotsforeachungrouped) need to be handled with care: loop arguments can only be used in places where they ...


42

2016 Christmas Edition I experimented here with trying to produce a geometric figure near the firework core, by using simple glyphs like + and -. When duplicated with rotation and shift, I think the effect is very nice way to highlight the event. 2015 CHRISTMAS EDITION Here I introduce my first triple-burst firework, with "For unto us" as the inner burst,...


38

The main loop for comma separated lists in LaTeX3 is \clist_map_inline:nn The first argument is an explicit list, the second argument tells LaTeX what to do with each item. For instance, we want to print an enumerate environment from the items: \documentclass{article} \usepackage{xparse} \ExplSyntaxOn \NewDocumentCommand{\makeenumerate}{ m } { \begin{...


37

Requires xelatex: \documentclass{article} \usepackage{color} \XeTeXinterchartokenstate = 1 \newXeTeXintercharclass \vowelsclass \XeTeXcharclass `\a \vowelsclass \XeTeXcharclass `\e \vowelsclass \XeTeXcharclass `\i \vowelsclass \XeTeXcharclass `\o \vowelsclass \XeTeXcharclass `\u \vowelsclass \XeTeXcharclass `\A \vowelsclass \XeTeXcharclass `\E \...


34

This is just for practicing with LaTeX3 code. \documentclass{article} \usepackage{xparse,xcolor} \ExplSyntaxOn \NewDocumentCommand{\colorize}{mm} { \cs_set:cpn { maryjane_color_#1: } { \textcolor{#2}{#1} } } \tl_new:N \l_maryjane_text_tl \NewDocumentCommand{\changecolors}{ O{aeiou} m } { \tl_set:Nn \l_maryjane_text_tl { #2 } \tl_map_inline:nn { #1 }...


32

You can define recursive macros that call themselves until some termination is found; a solution to your problem can be as follows: \makeatletter % we need to use kernel commands \newcommand{\twoimages}{% \begin{figure}[!htb] \@twoimagesi } \newcommand\@twoimagesi{\@ifnextchar\stopimages{\@twoimagesend}{\@twoimagesii}} \newcommand\@twoimagesii[6]{% \@...


32

Edit: To give some indications for this question (What's the maximum number of pages a PDF produced by pdfTeX can have?), I tried my second version with a limit of 2.500.000 pages. The PDF produced (in approximatively 30 minutes) contains 1112672090 bytes. Here is a variation of your first solution (this document can't be terminated!): \documentclass{...


27

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


25

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


23

Update The issue with scaling in graphicx is fixed in the development sources for the next release (probably January 2017) and the issue with the xetex driver discussed in the comments is fixed and already on CTAN. The main issue is that the division macro in graphics was written to do a reasonable job for normal image scaling ranges without using more than ...


22

You can use the additional facilities of foreach macro given in the manual by adding pgfmath package too. For some reason, (initially 4) option is not working if TikZ is not fully loaded so you can define it externally. \documentclass{article} \usepackage{pgffor,pgfmath} \begin{document} \def\lastx{4} \foreach \x[count=\xi from 2,remember=\x as \lastx] ...


22

My first LaTeX3 answer! Yay! :) The l3clist package has a lot of built-in commands to deal with comma-separated lists. Here's an attempt: \documentclass{article} \usepackage{expl3} \usepackage{xparse} \ExplSyntaxOn \NewDocumentCommand \countItems { m } { \clist_count:N #1 } \NewDocumentCommand \countInlineItems { m } { \clist_count:n {#1} } \...


21

The syntax for \@for is \@for\cs:=<list>\do{<code>} Here <list> is either a comma separated list of tokens or a macro expanding to such a list. Thus, the calls \@for\next:=abc, def, gh ,ij\do{<code>} and \def\mylist{abc, def, gh ,ij} \@for\next:=\mylist\do{<code>} are equivalent. Notice that LaTeX doesn't really ...


21

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 \begin{document}...


20

\documentclass[pagenumber=footright, DIV=20, fontsize=16]{scrartcl} \usepackage[automark]{scrlayer-scrpage} \pagestyle{scrheadings} \ihead{} \ofoot[\pagemark]{\pagemark} \chead{} \cfoot[]{} \ohead{} \begin{document} \def\x{\ifnum\value{page}<501\mbox{}\clearpage\expandafter\x\fi} \x \end{document}


19

A loop and a counter: Code \documentclass{article} \makeatletter \newcommand*{\length}[1]{% \@tempcnta\z@ \@for\@tempa:=#1\do{\advance\@tempcnta\@ne}% The length of the list #1 is \the\@tempcnta.% } \makeatother \begin{document} \length{0,1,54,1,3} \def\mylist{0,1,54,1,3} \length\mylist \end{document} Output The length of the list 0,1,54,1,...


18

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


18

You don't need to connect nodes. First draw background lines. All starting from (0,0). \foreach \angle in {0,1,...,359} \draw[cyan!50!black] (0,0)--++(\angle:4); Second, draw a circular node white filled: \node[circle, fill=white, text=cyan!50!black, text width=15mm, align=center]{Orion\\2000}; And third (although it's the first command), define the ...


17

A solution without any extra packages \documentclass{article} \usepackage{graphicx} % introduce a dummy counter, initially 0 \newcount\tmp \newcommand{\pdfappendix}[2]{% need this to prevent extra vertical space % #1: image path and core part of name % #2: maximum number \tmp=0 \loop % increment dummy counter \advance\...


17

The following code will do what is asked, using the plain TeX construction \loop ... \if ... \repeat: \documentclass{article} \title{The Song That Never Ends} \author{by Norman Martin} \begin{document} \maketitle % \noindent This is the song that never ends. \newline \loop \iftrue Yes, it goes on and on my friends. \newline Some people started ...


16

It also possible a bit less hacky. (pgf-manual p. 496) Look at this modified code: \documentclass{article} \usepackage{tikz} \usetikzlibrary{intersections} \begin{document} \begin{tikzpicture} \foreach \i in {1,2,...,6} { \draw[name path global/.expanded=line\i] (-3,\i) -- (3,-\i); } \draw[name intersections={of=line1 and line2}] (...


16

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 \centerline{...


15

The following example uses the syntax that the arguments are given inside the argument for the command: \images{{...}{...}{...}{...}{...}{...}...}. The macro \images then parses its argument and catches three arguments at a time: \documentclass{article} \newif\ifimagesSep \newcommand*{\images}[1]{% \par\noindent[begin images]\\\relax \imagesSepfalse \...


15

Using \# simply defines \#. You need something that, given a name, becomes the command with that name. Such a thing exists as a TeX primitive command: \csname ... \endcsname \documentclass{article} \newcommand{\MkVec}[1]{\expandafter\def\csname#1\endcsname{\vec{#1}}} \MkVec{x}\MkVec{y} \begin{document} Some vectors: $\x$, $\y$. \end{document} If you have ...


15

There is a package lambda-lists by Alan Jeffrey for "Lists in TeX's mouth". Here's an example in plain TeX: \catcode`@=11 \input lambda.sty \catcode`@=12 \tracingmacros=1 % check out the log file afterwards! \def\mylist{\Listize[1, 2 ,3,,4=foo,5,]} \def\myfun#1{do something with #1\def\foo{}} \def\fooDefined?{\ifdefined\foo foo's defined\else foo's ...


15

The etoolbox package provides some list processing tools. For comma-separated lists there are \docsvlist{<list>} where each item is put in the input stream with \do{<item>}. This means a suitable definition of \do has to be provided. \forcsvlist{<handler>}{<list>} where each item is put in the input stream as argument to <handler&...


15

Using egreg's template for straight LaTeX \documentclass{article} \makeatletter \newcommand{\makeenumerate}[2][,]{\begin{enumerate}% \def\dolist##1{\expandafter\@dolist##1#1\@eol}% \def\@dolist##1#1##2\@eol{% \begingroup\setbox0=\hbox{##1\unskip}\ifdim\wd0=0pt\endgroup\else\endgroup\item \fbox{\ignorespaces##1\unskip}\fi% \ifx\@eol##2\@eol\else\...


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