Tag Info

Hot answers tagged

33

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


31

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


30

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


29

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


29

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


26

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


25

\documentclass{article} \usepackage{graphicx} \usepackage{pgffor} \def\pdfappendix#1#2{% \foreach \index in {1, ..., #2} {% \includegraphics[scale=0.6]{#1\index.pdf}\par% }} \begin{document} \pdfappendix{pdf/test}{4} \end{document} The above code will the thing you want. However I haven't tested it extensively. I just tested this minimal ...


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


21

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


19

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


18

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


18

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


17

For the sake of completeness, in Luatex: \newcommand{\pdfappendix}[2]{ \directlua{ for index=1,#2 do tex.print("\includegraphics[scale=0.6]{pdf/#1"..index..".pdf}") end}


17

I don't think that this is possible. However, in your case the / notations isn't really necessary: \begin{tikzpicture} \foreach \y [count=\i] in {0,0.25,...,1} { \only<\i>{ \draw (0,0) rectangle (1,1); \draw (0,0) -- (1,\y); } } \end{tikzpicture} For more complicated cases, when one variable is dependent on the other via some ...


16

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


14

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


14

\usepackage{multido} \newcommand\pdfappendix[2]{% \multido{\I=1+1}{#2}{% \includegraphics[scale=0.6]{pdf/#1\I.pdf}}}


13

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


13

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


13

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


13

As David Carlisle has already said, do not fully expand \nocorrlist. LaTeX's code for the italic correction looks for the next token using \futurelet (in macro \maybe@ic). If the next token is an element of the list \nocorrlist, then the italic correction is suppressed. LaTeX's original definition only includes the comma and period as tokens with catcode 12 ...


13

To abort the loop after the current iteration simply \let the internal \iterate macro to \relax. If you want to skip the rest of the loop code you can use a macro defined to \fi\iffalse for this (as Bruno already said). Abort at end of current iteration: \documentclass{article} \begin{document} \newcount\mycount \mycount=1 \loop\ifnum\mycount<13 ...


12

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


12

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


12

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


12

I've found that when passing options to TikZ elements as macros then I need to expand the macro before passing it in: \documentclass{article} \usepackage{tikz} \usetikzlibrary{intersections} \begin{document} \begin{tikzpicture} \foreach \i in {1,2,...,6} { \edef\optname{name path global=line\i} \expandafter\draw\expandafter[\optname] (-3,\i) -- ...


12

\documentclass{article} \usepackage{longtable} \newcounter{xyz}\newcounter{uvw} \makeatletter \newtoks\@tabtoks \newcommand\addtabtoks[1]{\@tabtoks\expandafter{\the\@tabtoks#1}} \newcommand*\resettabtoks{\@tabtoks{}} \newcommand*\printtabtoks{\the\@tabtoks} \makeatother \pagestyle{empty} \begin{document} \resettabtoks \loop\ifnum\theuvw<10\relax ...


12

The difficulty is not in producing it, but rather in printing it. Here's a way; for printing ten terms we need two lines and I decided to let TeX bother with the splitting. The \telescope command is generic, by redefining \Term you can print other similar series. \documentclass{article} \usepackage{xparse,amsmath} \ExplSyntaxOn ...


12

egreg just got there first but: \documentclass{article} \newcommand\term[1]{% {(\ifnum#1=1 1 \else\frac{1}{#1}\fi - \frac{1}{\the\numexpr#1+1\relax})}} \newcommand\xsum[1]{% \term{#1}% \ifnum#1<10 + \expandafter\xsum\expandafter{\the\numexpr#1+1\relax}% \fi} \begin{document} $ \xsum{1} $ \end{document}


12

Macros in a node name are merely expanded, but not parsed by a math parser. You need to do this yourself, either by using an explicit command like Marco suggested in his answer, or by using the [evaluate = <variable> as <new macro> using <expression>] option of the \foreach statement. Note that you want to use the int(...) function to make ...



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