Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Could I set up a structure for several cases so that I could get a TeX command branch say, behavior as below:

if case A

  • if case A1


  • elseif case A2


  • elseif case A3


  • endif

elseif case B

  • elseif case B1


  • elseif case B2


  • end if


the case A1~case B2 is given in advance, say, from the ordered collection (maybe its form is {\a,\'a,\^a,`A,\^A}`).

I knew the ifthen package, but it is too simple (or to complicated?) to use conveniently.

A intuitive explain:

this demand is related to the modal logic and semantics. Think about a given alphabetic chain of n bit (n less than 16), say,



etc. The character T denoted "True" or constant have value 1, the character F denoted "False" or constant have value 0, the other character x, y, z, and so on denoted variables whose value between 0 and 1 (not have to equal). After we assigned for the variables, I want to print the result like:

the chain given above has valuables [#1] (@1) times (or print which places has [#1] appeared in), [#2] (@2) times, [#3] (@3) times, ... and their weight sum is ...

the [#1], [#2], [#3], etc. is the x, y, z, respectively; the (@1), (@2), (@3), , etc. mean as former.

share|improve this question
It may help if you give us some more idea of the purpose of this. Also, what is it about the ifthen package that is inconvenient? –  Jan Hlavacek Apr 22 '11 at 4:10
Please have a look at tex.stackexchange.com/editing-help to learn how to format posts. Thanks. –  Martin Scharrer Apr 22 '11 at 8:30
add comment

1 Answer

up vote 1 down vote accepted

I am not exactly sure as to what you are after, but since you mentioned ordered lists here is an approach. One of the difficulties of using "TeX" as a computer language is its lack of built-in datastructures. But once you have lists, you can built any type of datastructure you wish and I think that is what you need here. However, some shift from common programming paradigms is necessary, so here is a traditional TeX solution.

Consider the following list of keywords in a list:


and for which the ordered list is, A+,A++,A--,A---,A=,A==,

Each element in the list will act as an "object" and hold some information, being a true, false or anything else you may wish.

We define a suitable macro to add an element and its definition to the list and we order the list.


We can loop the list and expand the meaning of all the elements using the @for command from the LaTeX kernel.

\@for \i:=\alist \do{%

Any individual element can be accessed by its name as \@nameuse{A==}.

As you can see from the commands you can store any type of object in the list. It can be a single digit or provided you define your macros accordingly can hold a full chapter of a book or possibly the book itself!. One caveat with the MWE shown below, if you writing in turkish change the \i to something else or run the code within a group.

%% define a list for demo purposes
%% typeset the unsorted list

The ordered list
%% the sorted list

%% empty the list
%% add element and define the element macro

%Consider adding some elements


%% loop over the list
\@for \i:=\alist \do{%

You can consider that the alist is your case statement.

share|improve this answer
@Y.L. I'am reading, though that's a bit diffcult to me. Thanks in advance. –  Stufazi Hoqckt Apr 22 '11 at 13:21
@Stufazi Hoqckt If you edit your post to define the problem a bit more clearly, I can edit the post to make it more specific. Start perhaps from a scan saying, I want to achieve this... –  Yiannis Lazarides Apr 22 '11 at 14:36
add comment

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.