# Tag Info

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

20

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

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


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

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

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

10

This is using the under-development tabstackengine package, first introduced here at Writing a table with equally spaced columns, based on the widest column (source code available at Measuring align). The package extends the stackengine package by adding tabbing capability. This answer, Can I tab inside of align environment?, gives some of the syntax of ...

10

Package kvsetkeys Package kvsetkeys provides parsers for key value lists and comma separated lists. Many formats are supported: LaTeX, plain TeX, it works even with iniTeX. Syntax: \comma@parse{⟨comma separated list⟩}{⟨code/processor with one argument⟩} Example The example is given for iniTeX to show the minimal requirements of the package. % Setup ...

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

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

8


7

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

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

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

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