Tag Info

Hot answers tagged

32

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


28

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


25

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


24

\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

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


21

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


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

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

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


15

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


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

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

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

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

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


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

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


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

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}


11

The main error is in the line \ifnum\select@i=#1\@@select@item\@endfortrue\fi% When \@@select@item the lookup for the number is not finished and TeX keeps expanding until finding something that's not a digit; when \@@select@item is 1, it's easy to predict chaos. A better style is \ifnum#1=\select@i\@@select@item\@endfortrue\fi because \select@i is a ...


11

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


11

The tricky part is to get the maximum number of pages in a PDF file. If a file is included in pdfTeX, then it sets a primitive \pdflastximagepages with the number of pages in the included PDF file. Thus the following example defines the macro \getpdfpages. It includes the first page in a temporary box. Then it sets the LaTeX counter pdfpages to the value of ...


11

Here is a never ending counting of the primes... (except that it will end-up in some arithmetic overflow error after a while). For less overhead, I use plain PDFTeX. Launching the run in a Terminal, the page numbers correspond to how many primes have been computed so far. update: the algorithm was a bit faulty, although it computed correctly the ...


11

Nothing wrong with the the answers so far but they all use big heavyweight packages, this version doesn't use any package at all and needs rather less code. \documentclass{article} \def\Fbox#1#2{\ifnum#1=0\mbox{#2}\else\fbox{\Fbox{\numexpr#1-1\relax}{#2}}\fi} \begin{document} \Fbox{0}{hello} \Fbox{1}{hello} \Fbox{2}{hello} \Fbox{3}{hello} ...


11

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



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