# how to import multiple branch cases structure into LaTeX document.

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

\cmdAi{arg1}

• elseif case A2

\cmdAii{arg2}

• elseif case A3

\cmdAiii{arg3}

• endif

elseif case B

• elseif case B1

\cmdBi{arg4}

• elseif case B2

\cmdBii{arg5}

• end if

endif

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,

TxFxyxxTyxTFyT

zTyxTzzxxTyxF


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.

-
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

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:

\def\alist{A--,A+,A++,A-,A=,A==,}


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.

\def\AddElementToList#1#2#3{%
\expandafter\def\csname#2\endcsname{#3}
\lst@BubbleSort{\alist}
}


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{%
\texttt{%
\expandafter\csname\i\endcsname}\par
}


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.

\documentclass{article}
\usepackage{lstdoc}
\begin{document}
\makeatletter
%% define a list for demo purposes
\def\alist{A--,A+,A++,A-,A=,A==,}
%% typeset the unsorted list
\texttt\alist

The ordered list
%% the sorted list
\lst@BubbleSort{\alist}
\texttt\alist

%% empty the list
\let\alist\empty
%% add element and define the element macro
\expandafter\def\csname#2\endcsname{#3}
\lst@BubbleSort{\alist}
}

\AddElementToList{\alist}{A---}{$a^2+33=f_2$}

\texttt\alist

%% loop over the list
\@for \i:=\alist \do{%
\texttt{%
\expandafter\csname\i\endcsname}\par
}
\makeatother
\end{document}


You can consider that the alist is your case statement.

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