Hot answers tagged

47

One way of doing this is using leaders: \documentclass{article} \newcommand\kitty{\leavevmode\xleaders\hbox{kitty!}\hfill\kern0pt} \begin{document} This is a test. \kitty \par This is a test. \noindent \kitty \end{document} The general format for constructing leaders is \leaders<box or rule><glue> (which repeats <box or rule>). There ...


43

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


42

To answer the specific question you are asking, here is a complete minimal example. \documentclass{standalone} \usepackage{pgfmath} \begin{document} \def\names{{"Katie","Frank","Laura","Joe"}}% \pgfmathparse{\names[2]}\pgfmathresult \end{document} So, you need to use the pgfmath parser to do the job through \pgfmathparse and then use the result of the ...


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

The pgffor package allows for-loop style repetition using the following format: \foreach \<cmd> in {1,...,<total>} {% % stuff } Using this as base, the following is probably what you're after: \documentclass{beamer}% http://ctan.org/pkg/beamer \usepackage{graphicx}% http://ctan.org/pkg/graphicx \usepackage{pgffor}% http://ctan.org/pkg/pgffor ...


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


34

According to pages 470-471 of the pgfplots documentation: 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 are immediately evaluated; but pgfplots postpones the evaluation of many macros....


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


30

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]{% \@...


27

Look, ma! No loops! :) Borrowed from the TeXbook, exercise 21.8 (p. 225). \documentclass{minimal} \usepackage[a4paper,margin=2mm]{geometry} \usepackage{graphicx} \sbox0{% \includegraphics{image}% \kern2mm \vrule width 0pt depth 2mm} \setlength{\parindent}{0pt} \begin{document} \null \cleaders\hbox to\textwidth{\leaders\copy0\hfill}\vfill \end{...


27

Suppose your pictures are all following certain naming convention (here I used pic1.png up to pic4.png), the lipsumpackage is just for the dummy text: \documentclass[parskip]{scrartcl} \usepackage[margin=10mm,a6paper]{geometry} \usepackage{tikz} \usepackage{lipsum} \begin{document} \foreach \x in {1,2,3,4} { \lipsum[\x] \includegraphics[scale=1]{pic\x....


25

This answer may be more generic than specifically relating to TikZ/PGF. (La)TeX is a macro-based language, so it does not work as expected compared to other languages when dealing with "arrays". For example, while \names[2] should yield Laura where \def\names{Katie, Frank, Laura, Joe} (indexing from 0), (La)TeX considers [2] to have no connection to \...


23

How about using a chunk with <<results=tex, echo=FALSE>>=? It will allow you to: (a) paste together the LaTeX code you'd like to run (i.e. 200 \begin{frame} ... \includegraphics ... \end{frame} constructs); and (b) place that constructed text verbatim in the *.tex file produced by Sweave(). For more details, see here. It's a FAQ! <<...


23

Using the wonderful python.sty package (see github) and some embedded python code, this is very easy: \documentclass{article} \usepackage{python} \usepackage{graphicx} \begin{document} \begin{python} import os directory = "." extension = ".png" files = [file for file in os.listdir(directory) if file.lower().endswith(extension)] for file in files: ...


23

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


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

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


22

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


20

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


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


19

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


18

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


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

\documentclass{article} \usepackage{tikz} \begin{document} \begin{tikzpicture} \foreach[count=\i] \txt in {20,18,...,2} \node at (\i,0) {\txt}; \end{tikzpicture} \end{document} Note: It is always possible to cauculate one variable using the other one. Or you can't use ... in pgffor. So you can also use: \begin{tikzpicture} \foreach[evaluate=\y using int(...


17

This doesn't work with Knuth's TeX, because it requires e-TeX's \unless; but pdftex has it. \newcount\X \X=10 \loop \the\X\endgraf \advance \X by -1 \unless\ifnum \X<0 \repeat \bye There are no predefined operators for combining conditionals. Loops with \loop...\if...\repeat are really easy: \loop <codeA> <conditional> <codeB> \...


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


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