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


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


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

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

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


9

Here another approach using l3int: \documentclass{article} \usepackage{amsmath} \usepackage{xparse} %dt. Silbentrennung \ExplSyntaxOn \cs_generate_variant:Nn \int_set:Nn { Nx } \NewDocumentCommand \Formula { O{1} O{1} m } { \int_step_inline:nnnn { #1 }%initial value { #2 }%step { #3 - #2 }%final value { \formula_func_aux:n { ##1 } \\ ...


9

\foreach strips spaces before each list item, and then collects everything up to the next comma (or the list terminating token) before assigning to the relevant variables. The \foreach problem arises in this case because of the extra space given before the closing brace in the list. Consider the following: \foreach \p/\q in {a/{1,2,3}, b/{4,5,6} } ...


9

As mentioned in the comments it is more efficient to avoid \foreach and do your own tests for empty lists or list items. Also anything done within a \foreach iteration has to be done globally to last past the end of the loop. There may be packages which already provide this functionality but here is an example of what could be done. It contains a bit more ...


9

Use it without a second member (which would denote the step): \documentclass{article} \usepackage{tikz}% http://ctan.org/pkg/tikz \newcommand{\boucle}[1]{\foreach \x in {1,...,#1} {\x }} \begin{document} From 1 to 5 : \boucle{5} From 1 to 2 : \boucle{2} From 1 to 1 : \boucle{1} \end{document} The same result could be achieved using multido: ...


8

I'd suggest you to switch to the more versatile algorithmicx package; using the noend option, you can achieve what you want: \documentclass{article} \usepackage[noend]{algcompatible} \begin{document} \begin{algorithmic} \IF{condition} \IF{another condition} \STATE do something \STATE do something else \ELSE ...


8

Here is another answer to propose an alternative to the very good egreg's answer: \documentclass{article} \newcounter{temp} \usepackage{pgffor} \begin{document} $\sum_{k=1}^N \left(\frac{1}{k}-\frac{1}{k+1} \right) = \left(1-\frac{1}{2}\right) \foreach \n in {2,...,10} {\setcounter{temp}{\n}\stepcounter{temp} +\left(\frac{1}{\n}-\frac{1}{\arabic{temp}} ...


8

Here is an etoolbox implementation: \documentclass{article} \usepackage{etoolbox}% http://ctan.org/pkg/etoolbox \makeatletter \newif\ifprinted \newcounter{select@i} \newcommand\select[2]{% \select{<num>}{<csv list>} \printedfalse% Nothing has been printed \setcounter{select@i}{0}% List starts from 1 \renewcommand*{\do}[1]{% ...


8

This also uses no counters but is perhaps a bit simpler than jfbu's but is the same idea. \documentclass{article} \usepackage{amsmath} \newcommand\y[1]{% y_{\the#1}&=A_{\the#1\,\the\numexpr2*#1-1\relax} +A_{\the#1\,\the\numexpr2*#1\relax} x_{\the\numexpr2*#1\relax}} ...


8

Without any package, you can do with \loop; the trick is to add something invisible to the empty pages, for instance \null (more efficient than \mbox{}): \documentclass{article} \newcommand{\filluptopage}[1]{% \clearpage \loop\ifnum\value{page}<#1\relax \null\clearpage \repeat } \begin{document} Page 1 has text. \filluptopage{5} This will ...


7

The problem is that each cycle of \foreach is performed inside a group. So you have to globally save \MyText after the substitution; however a straightforward \documentclass[11pt]{article} \usepackage{etoolbox} \usepackage{xstring} \usepackage{tikz} \begin{document} \def\KeyWords{one, two, three} \def\MyText{This is one, followed by two later by three} ...


7

You are missing \the \documentclass{beamer} \usepackage{pgffor} \begin{document} \begin{frame} \foreach \x in {0,1,2}{% \foreach \y in {0,1}{% \only<\the\numexpr2*\x+\y+1\relax>{\the\numexpr2*\x+\y+1\relax}}} \end{frame} \end{document} \numexpr is like an anonymous count register. For the part inside the {} you need \the (or \number or ...


7

\documentclass{article} \makeatletter \def\phiseq#1{$\let\comma\@empty\@for\tmp:=#1\do{\comma\varphi_{\tmp}\def\comma{,}}$} \makeatother \begin{document} \phiseq{1,2,3} \end{document}


7

A combination of forloop and calc: \documentclass[10pt,a4paper]{article} \usepackage{amsmath} \usepackage{calc} \usepackage{forloop} \begin{document} \hsize=8cm \newcounter{k}\newcounter{j}% \begin{align} %forloop[ step ]{ counter }{ initial value }{ condition }{ code } \nonumber \forloop{k}{1}{\value{k} < 11}{ \setcounter{j}{2*\value{k}-1} \\ ...


7

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


7

To add to Dan's answer, you may do the following to avoid the repeating \MkVec{..}'s. \newcommand{\MkVec}[1]{\expandafter\def\csname#1\endcsname{\vec{#1}}} \def\lst{x,y,z,u,v,w,a,b,c} \@for\i:=\lst\do{% \expandafter\MkVec \i } Now, with this implementation, you can maintain/modify your list of related macros in a single action. Should you ...


7

I suggest l3clist which provides the function \clist_item:Nn. A list starts add the indice 1. \documentclass{article} \usepackage{biblatex} \usepackage{xparse} \ExplSyntaxOn \NewDocumentCommand \select { m m } { \clist_item:nn { #2 } { #1 + 1 } } \ExplSyntaxOff \begin{document} \begin{itemize} \item \verb+\select{0}{A,B,C,D,E}+ gives ...


7

I propose a different definition of \current@item \def\current@item#1{% \stepcounter{item@count} \item $|$#1$|$\ $|$\texttt{\detokenize{#1}}$|$% } so the output also shows what's really passed as its argument. Also I changed the complicated management of \my@item@count with a simple counter. I don't comment about \@tfor, which is a different tool not ...


7

Remove the second item. \documentclass[preview,border=12pt,varwidth]{standalone} \usepackage{pgffor} \newcommand{\boucle}[1]{% \foreach \x in {1,...,#1} {\x } } \begin{document} From 1 to 5 : \boucle{5} From 1 to 2 : \boucle{2} From 1 to 1 : \boucle{1} \end{document}


6

Here's a LaTeX3 implementation. \documentclass{article} \usepackage[margin=1cm]{geometry} % to fit in one page \usepackage{blindtext} \usepackage{xparse} \newcommand{\modulespec}[2]{\section{#1} #2} \ExplSyntaxOn \NewDocumentCommand{\definemodules}{m} { \farley_definemodules:n { #1 } } \tl_new:N \l_farley_temp_tl \cs_new_protected:Npn ...


6

You can legally place \global only before an assignment command: \global\def \global\let \global\mathchardef \global\catcode \global\advance and so on. One should note that \global wants and looks for a suitable command following it, doing expansion. For instance, etoolbox defines \newrobustcmd{\cslet}[2]{% \expandafter\let\csname#1\endcsname#2} so ...


6

You get ! Missing = inserted for \ifnum. because \repeat has \ifnum#1>\z@ so #1 has to expand to a number, but it is \repeat{2}{1} which includes many non expandable constructs such as \@repeat, \relax and \advance. Also although unrelated to the error in this fragment, it is a very bad idea to redefine \repeat as it is part of the basic \loop ...


6

One issue you currently have is trying to create a \frame inside another frame. Moreover, \frame takes an argument, which you're not supplying in a proper way. Here is the etoolbox implementation that inserts each item in the list on a separate frame: \documentclass{beamer} \usepackage{etoolbox} \makeatletter \newcommand\makeenumerate[1]{% ...


6

I am editing this answer because the 1.09f release of xint transparently removes all spaces around commas when dealing with comma separated lists. Thus, some of the earlier issues mentioned here are now irrelevant and have been removed. \documentclass[border=12pt]{standalone} \usepackage{xint} % for \xintFor and \xintFor* loops % the macro \chisum is ...



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