Last call to make your voice heard! Our 2022 Developer Survey closes in less than a week. Take survey.

# Tag Info

### How to split input string in a LaTeX command?

This is very easy with xparse: \documentclass{article} \usepackage{xparse} \NewDocumentCommand{\myfunc}{ >{\SplitList{,}} m }{% \ProcessList{#1}{\func}% } \NewDocumentCommand{\func}{m}{% \...
• 986k

### Sorting a comma-separated list with LaTeX?

How about Lua? \def\sortlist#1{% \directlua{% local t = { #1 } table.sort(t) tex.sprint(table.concat(t,", ")) }% } \sortlist{"World", "Hello"} \bye Addendum: One of the really ...
• 105k

### How to split input string in a LaTeX command?

LaTeX has a built in command for iterating over comma separated lists: \documentclass{article} \makeatletter \newcommand\myfunc[1]{\@for\tmp:=#1\do{\func{\tmp}}} \let\func\fbox \begin{document} \...
• 666k
Accepted

### Sorting a comma-separated list with LaTeX?

This seems to work, with no packages. EDITED to solve the upper/lower-case problem. EDIT: Resolved problem when a comparison ran out of letters prior to resolving the order, for example, wash, ...
Accepted

### Combine map and use expl3 macros

You can use two sequences; first apply the mapping to get the “adorned” items, then use them. \documentclass{article} \usepackage{expl3} \usepackage{xparse} \ExplSyntaxOn \seq_new:N \...
• 986k

### Command with arguments separated by comma II (typically an easy way to write matrices)

The argument is first split at commas in a sequence which is mapped taking into account the positions, so we can add & or \\ as needed. \documentclass{article} \usepackage{amsmath} \ExplSyntaxOn \...
• 986k

### Sorting a comma-separated list with LaTeX?

You can safely compare strings consisting of ASCII characters; words with accented characters will not work. \documentclass{article} \usepackage{expl3,l3sort,xparse} \ExplSyntaxOn \...
• 986k

### How to check if comma list is empty?

The test you want is \clist_if_empty:N(TF): each data type has an appropriate test for emptiness or similar. These are defined such that they are 'aware' of the internal nature of data types (for ...
• 243k

### How can I create a comma-separated list of characters from a text string?

Here's a LuaLaTeX-based solution. It's fully utf8-code aware, i.e., the input string may contain utf8-encoded, as opposed to just ascii-encoded, characters. The code consists of a Lua function named ...
• 435k
Accepted

### Making \cpageref output commas instead of "and"

If you need this behavior all over the document, simply add the following line in your preamble \newcommand{\creflastconjunction}{,\nobreakspace} MWE: \documentclass{article} \usepackage[sort]{...
• 120k

### How to iterate over a comma separated list?

listofitems provides a pgffor-like interface for iterating over a list: \documentclass{article} \usepackage{listofitems} \begin{document} \setsepchar{,}% Parse-character = ',' \readlist\mylist{...
Accepted

### Coding a *short* newcommand with a variable number of arguments for a very specific use-case

Does the following solution meet your expectations for simplicity and flexibility? :-) Instead of thinking of each row of each of the two column vectors being a separate argument, you may want to ...
• 435k

### Building and using a list

This is essentially in expl3 out of the box. The idea is to map the original list; if an item is not in the remove list, add it to a temporary list and, at the end, reset the original list to the ...
• 986k
Accepted

### How to get the index variable in the foreach loop

Use count=\n: \documentclass{article} \usepackage{pgf, tikz} \begin{document} \textbf{Comprehensive knowledge storage follows the evolutionary sequence given by} \foreach \x in {letter, word, phrase, ...
• 986k
Accepted

### Command with arguments separated by comma II (typically an easy way to write matrices)

I am highly unused to the LaTeX3 syntax too, so I give you non-exp3 solution based only on TeX primitives. You need not any LaTeX package (and you basically don't even need LaTeX): \documentclass[12pt]...
• 52.5k
Accepted

### Beamer and a for each loop

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 ...
• 565k

### expl3: How to remove the final comma in a clist mapping

Without using sequences, you can pop the leftmost item in the clist and map the remaining clist: \documentclass{article} \usepackage{expl3} \ExplSyntaxOn \tl_new:N \l__UF_clist_use_head_tl \...
• 986k
Accepted

### Escaping special characters for use as a URL

\documentclass{article} \usepackage{url} \usepackage{pgffor} \usepackage{xparse} \usepackage{xstring} \usepackage[colorlinks=true]{hyperref} \NewDocumentCommand{\FormatLinks}{% s% #1 =* not ...
• 666k
Accepted

### Handling _ (underscores) in a macro's comma-separated list of arguments

You can use \detokenize; but if you want a printed underscore, you need to load fontenc with the T1 option. \documentclass{article} \usepackage[T1]{fontenc} \usepackage{etoolbox} \usepackage{hyperref}...
• 986k
Accepted

### Commas in \clist_map_inline:nn split values in undesired places

Any comma in the input defines an item: there's no way to distinguish a “grammatical comma” from a “separator comma” if they're at the same brace level. Besides bracing each item, which might be ...
• 986k

### Command with arguments separated by comma II (typically an easy way to write matrices)

Here I use tokcycle to replace the commas with & separators. WHile I show 2x2 and 3x3, any number of columns are acceptible, as long as the matrices contain 2 or (optionally) 3 rows. \...

### How can I create a comma-separated list of characters from a text string?

Here I use a token cycle. No mention was made of macros or groups appearing in the input (only characters and spaces), and so those should be excluded from the input, unless the OP advises on how ...
Accepted

### Create macro with variable number of comma separated arguments in plain TeX?

The solution in very simple in Plain TeX (or more precisely: using only TeX primitive commands) % fixed number of args: \def\frc#1{\frcA#1\end} \def\frcA#1,#2\end{{#1\over #2}} test: $\frc{a,b}$ % ...
• 52.5k
Accepted

### Long List of Files Names with Paths

It is generally more efficient to arrange that the list is executable rather than use a comma separated list (which needs to be parsed), traditionally LaTeX uses \@elt for this but any macro will do, ...
• 666k

### Iterator-like command, where each use expands to an item from list defined earlier

It's a breeze with expl3: \documentclass{article} \usepackage{xparse} \ExplSyntaxOn \NewDocumentCommand{\deflist}{O{,}m} { \seq_set_split:Nnn \l_narebski_list_seq { #1 } { #2 } } \...
• 986k
Accepted

### Select largest value from a list of variables in LaTeX

Use the max function provided by expl3 in the fp module: \documentclass{article} \usepackage{xparse} \ExplSyntaxOn \NewDocumentCommand{\findLargest}{ om } { \IfNoValueTF{#1} {% separator is a ...
• 986k

### Membership check on comma separated list

LaTeX has such a test built in already, so you just need to define your requested syntax: \documentclass{article} \makeatletter \newcommand\ifmember[2]{% \in@{#1}{#2}% \ifin@ \expandafter\@...
• 666k
Accepted

### newcommand with comma separated argument, and optional arguments

The following example uses \comma@parse of package kvsetkeys to parse the comma separated argument lists. \documentclass{report} \usepackage{kvsetkeys}% provides \comma@parse \usepackage{etexcmds}% ...
• 261k

### Handling _ (underscores) in a macro's comma-separated list of arguments

The simplest way to do this is to load the url package and define a url command to format the refnames: \usepackage{url} \DeclareUrlCommand{\coderefname}{\urlstyle{rm}} \newcommand{\codecitep}[1]{% ...
• 201k