{comma-separated-list} is a data format consisting of fields, most commonly separated by commas

learn more… | top users | synonyms

31
votes
10answers
2k views

How to iterate over a comma separated list?

How can I iterate, loop, process, or otherwise do something, with each element from a comma separated list of things? This question has been asked perhaps many many times, and the are already lots of ...
23
votes
10answers
1k views

Get the head, the tail, and the last element of a comma-separated list

I have a comma-separated list, stored in a macro. It is non-empty, and it has commas between the elements but not at the start or end. How can I get: the first element (a.k.a. the "head")? the last ...
21
votes
8answers
827 views

What is the best way to scan over a list of somethings?

It seems that a common operation needed when defining new commands is to scan over a list of arguments (separated e.g. by a comma, but maybe by something else) and do something with each argument in ...
18
votes
7answers
599 views

How to define a command to feed the contents of a list into an \ifcase construct?

It's common to use an \ifcase construct to redefine a command depending on the value of a counter. The following example illustrates this: \documentclass{article} \usepackage{xcolor} ...
18
votes
4answers
412 views

Comma delimited list - how to obtain the length?

It's simple. I have a list like {0,1,54,1,3} as input argument to a command in making. How can I obtain the length of this list? Something like \length(#1) where #1 is the list.
18
votes
2answers
315 views

Difficulty with macro expansion

I'm not getting the output I want from my LaTeX code, and I think the problem is that I'm not expanding things at the right times. Code \documentclass{article} \usepackage{tikz} ...
17
votes
2answers
420 views

Selecting random elements from a comma separated list

I would like to have a command (either user-defined, or from a package, or whatever) that has the basic form: \selectNrandom{N}{list, of, comma, separated, elements}{code to execute} which will ...
13
votes
3answers
483 views

Get n-th element of a list (with etoolbox, or not)

I'm defining a list and I need to obtain the n-th element of this list. I was surprised that etoolbox doesn't provide a way to obtain it. The way I found to obtain the n-th element is along these ...
13
votes
5answers
863 views

Parse comma-separated list of command names with spaces

Problem This question is related to How can I specify a long list of math operators? – but with a twist: I want to allow spaces in in the comma-separated list, like so: \newacronyms{acm, ams, cpu, ...
13
votes
5answers
1k views

How do I write a macro having comma-separated and variable number of arguments?

I want to write a macro in LaTeX2e that can pass \textcolor, which is embedded in another macro, the values of the colour model gray, rgb, or cmyk. The number of arguments specified implies the colour ...
12
votes
1answer
446 views

Sorting Comma Separated Lists defined with, or without macro

I would like to be able to sort a comma separated list. Before I resort to writing something that would require \ensureunix :-) and having that do the sort for me, I thought I'd make an attempt to ...
11
votes
4answers
589 views

How to make a recursive Latex macro with comma separated argument list

I would like to make a macro that takes two arguments, the second of which is a comma separated list and then produces a nested commutator of argument1 with each entry of argument2. I've been ...
11
votes
2answers
166 views

How to process a list and ignore spaces?

This question is part of a new package: metrix. Typeset metric/prosodic symbols standalone and above syllables. I’m wrinting a new package and I need to process a list (using etoolbox at the ...
11
votes
2answers
292 views

How do I put card backs on my cards?

I have a a document that is making me sheets of cards. A stripped down, almost minimal example looks something like \documentclass{article} \usepackage[utf8]{inputenc} %Needed for input ...
11
votes
1answer
196 views

Using etoolbox to automatically generate input for \xymatrix

I'd like to make a command \exactseq such that, for example, \exactseq{A,f,B,g,C} corresponds to \xymatrix{A \ar[r]^{f} & B \ar[r]^{g} & C} and such that this works for inputs of ...
10
votes
2answers
178 views

How to set class options that can have multiple values?

Title says it all, but here's an example: the KOMA-Script classes provide the option toc which can have multiple values that don't interfere with each other, like values that enable the Bibliography ...
9
votes
7answers
993 views

Iterating through two lists

I have two comma delimited lists: ListA(a,b,c,d,e,f,g) and ListB(name1,name2,name3,name4,name5) I would like to iterate through both lists at the same time, something like: loop readvalue ...
8
votes
4answers
323 views

Decimal separator and axis label centering with Tikz

The following code creates a figure with Tikz without the use of pfgplots (that I want to avoid here): % compilation: pdflatex --jobname=Runge-f1 Runge.tex \documentclass[12pt]{book} ...
8
votes
2answers
215 views

Confusion regarding strings and numbers in tikz

I'm using a macro that uses \StrBetween from xstring It seems to be working great. However, when I try to use a value that it returns as a coordinate in a tikz picture, I get a confusing error. ...
8
votes
2answers
224 views

PDF keywords from Expl3 clist

I’m trying to add PDF keywords to my résumé. In the custom class file, I have these lines: \clist_new:N \jcsres_keywords_clist \NewDocumentCommand \keywords {m} { \clist_gset:Nn ...
8
votes
2answers
135 views

Mapping a macro onto multiple lists simultaneously

I have a macro (say \myMacro) that takes three arguments (say a, b, c) and I want to write another macro (say \otherMacro) that given three lists of parameters (comma delimited lists and all of the ...
7
votes
2answers
150 views

Deleting an element from a comma separated list

In this answer we learnt how to remove the n-th element from a comma-separated list. How can I remove an element from a list by its value, rather than its position? For example: if my global variable ...
7
votes
3answers
135 views

Sorting to match a given list

I am looking for ideas on the following task. I want to sort the entries in \listb to those in \lista. It cannot always be assumed that only the elements of \lista are in \listb; neither can it be ...
7
votes
2answers
170 views

How do I process a comma separated list passed through a command

When passing a comma-separated list the commas are ignored, i.e. the list becomes a single item and I can't seem to find a way to prevent this. What should I do so that TEST C in the attached code ...
7
votes
3answers
531 views

parse variable length comma separated list into command

I've been trying to modify the solution here into a LaTeX3 command that takes a variable length comma separated list of numbers and an optional argument (a unit) and prints the square root of the sum ...
7
votes
1answer
506 views

How to process a comma separated list?

Using receipt of "LaTeX3: unable to convert space separated list into clist" I elaborated the following code for my needs: \documentclass{book} ... \usepackage{expl3} \begin{document} ...
7
votes
1answer
149 views

Getting a random sublist from a given list

The etoolbox package provides macros to handle list, which can be useful to package/class writers, however it miss macros to get random sublists. So I want to define the following macros: ...
6
votes
3answers
138 views

Expansion issue when adding to CSV list from within a \foreach

Another expansion issue that I am unable to guess at the correct combination of \edef/\expandafters to get to work. Background: Below I have defined \AddToCommaSeparateList which uses \g@addto@macro ...
6
votes
1answer
261 views

Why am I processing a comma-separated list incorrectly when using etoolbox and kvoptions?

I'm trying to pick something out of a list that has been passed from some package options by kvoptions, but docsvlist doesn't appear to be recognising the commas. I suspect this may be something to ...
6
votes
1answer
1k views

\newcommand and comma separated parameters

I would like to learn to manipulate comma separated lists in Latex. To give a concreet but artificial example, I would like to have this command: \swap{1,10} expand to this: {10,1} How can I ...
6
votes
1answer
159 views

Problem with old ConTeXt separated list example

I have been trying to get the following small example from ConTeXt garden to work without success. \starttext \usemodule[database] \def\SendMe#1#2#3#4{\framed [align={flushleft,lohi}, width=4cm, ...
6
votes
1answer
76 views

Macro expanding to comma separated list

I'm trying to use a macro for pgfplotstable labels but the macro is treated as a single entry of a csl rather than a csl. The Question asked in Using a macro as value of addtotoc in \includepdf ...
5
votes
2answers
156 views

List delimited by commas (not lines)

Note: Comma delimited lists is not a duplicate. What I want to do is have a list environment of items, like itemize and enumerate, but I want the output to be delimited by commas instead of new ...
5
votes
2answers
513 views

Replacing matching text with a macro containing information from a CSV file

I have some data stored in a CSV file, in this manner: 000000001 @ name @ information @ more information @ some more information I also have a information.tex file containing the numbers from the ...
5
votes
1answer
47 views

Is there any way to add a key to a sub/module in l3keys?

I need to loop through a comma-separated list, creating them all as keys for a data structure. I can't think of a way to loop through the keys inside \keys_define:nn, so the only other option I see is ...
4
votes
2answers
619 views

Iterating through comma-separated arguments

I've looked all over and can't seem to find a succinct answer to this question. Is it possible (and if so, how) to create a command that will iterate through its `arguments' of comma-separated values ...
4
votes
1answer
131 views

Append two lists for TikZ foreach loop

How can I make a TikZ foreach loop iterate over two lists consecutively? I had hoped that in my code below, the expression \firstlist,\secondlist would evaluate to 2,3,5,7,1,4,6, but it doesn't work. ...
4
votes
2answers
352 views

Cutting a table to fit the available space on a page

I have a long list of data, in a CSV file, formatted like this: tiger, 300, 10.0, 7, 4.0 lion, 200, 15.0, 5, 3.0 bear, 100, 15.0, 3, 1.0 fish, 10, 10.0, 2, 0.1 The first rows are more important ...
3
votes
1answer
43 views

Beamer and a for each loop

I'm using the beamer presentation package and trying to combine the examples from this post How to iterate over a comma separated list? with the beamer package. In modifying the top example, chaning ...
3
votes
2answers
70 views

Reading arguments in a command?

I now know that if I want to get for example the 3rd argument passed to a command, I have use #3. My question is if this argument is an array how can I read elements of array without a for loop? For ...
3
votes
2answers
48 views

Generate comma separated list with some non-empty strings

I'm trying to generate a comma separated list that uses strings that may or may not be empty. For example \mylist{\stringA,\stringB,\stringC} would expand to A, C if B is empty or B, C if A is empty, ...
3
votes
1answer
177 views

Comma in macro parameters

I have a macro accepting several optional arguments in a comma separated list. I would like to assign a value containing a comma to a particular argument. Is there a way to "escape" this particular ...
3
votes
1answer
52 views

Check if a number is in a comma separated list (print or display selected sections from a specific list)

I'm trying to check if a section number belongs to a specified list: \ifnum\value{section}=\mylist % check if section number in mylist --- WRONG \dosomething \fi The conditional is ...
3
votes
1answer
68 views

List Version of \str_if_eq

I am using \str_if_eq:xxTF{\A}{\Target}{<true>}{<false} to execute the <true> or <false> code if \A=\Target. What is the list version equivalent of this? So I am looking for ...
3
votes
1answer
419 views

How to create a comma-separated list in LaTeX according to the number of elements in another list?

I have been looking for a way to create dynamically a comma-separated list consisting of n entries, all entries equal, defined by \newcommand\mytext{species:} (example) and n being the number of ...
2
votes
1answer
74 views

What is the right number of #’s for nested sequence mappings?

Im trying to nest two sequence mappings, which works so far but I want to use them inside a command definition so the <items> should be accessible as ##1 and ###1 but this won’t work. Is it ...
2
votes
1answer
169 views

Compare two comma separated lists

Hi I would like to compare two comma separated lists. \documentclass[a4paper]{article} \usepackage{comment} \usepackage{ifthen} \usepackage{xargs} \usepackage{xkeyval} \usepackage{xfor} ...
1
vote
0answers
37 views

Math lists: commas inside or outside of math mode? [duplicate]

I am wondering whether to use that (1) $A_{a}, B_{b}, C_{c}$ # comma in math mode or that (2) $A_{a}$, $B_{b}$, $C_{c}$ # multiple math modes, comma outside math mode Any good reasons for ...