4

There's a problem I'm trying to solve: I want to generate an Array with e.g. required Modules for a Software Installation. It should look like this:

\makebox[0pt][r]{required Modules}
\begin{tabular}[t]{p{1.8cm}p{1.8cm}}
Module01 & Module02 \\
Module03 & Module04 \\
...
\end{tabular}

I'd like to have kind of a little circle (maybe a png) in Front of each Module wich is filled, if the Module is required and empty otherwise. The Array should be generated with a simple Command like this:

\requiredModules{Module02,Module04}

so that the given Modules are the required ones...

How can i do this?

2
  • Welcome to TeX.sx! Please add a minimal working example (MWE) that illustrates your problem. Usually, we don't put a greeting or a "thank you" in our posts. While this might seem strange at first, it is not a sign of lack of politeness, but rather part of our trying to keep everything very concise. Upvoting is the preferred way here to say "thank you" to users who helped you. Jun 8, 2012 at 13:35
  • the example provided now seems to be minimized, isn't it?
    – David
    Jun 8, 2012 at 13:40

1 Answer 1

5

Here's a way with the help of expl3 and collcell:

\documentclass{article}
\usepackage{collcell,xparse}
\ExplSyntaxOn
\NewDocumentCommand{\requiredModules}{m}
 {
  \seq_set_split:Nnn \l_david_required_seq { , }{ #1 }
 }

\NewDocumentCommand{\checkRequired}{m}
 {
  \seq_if_in:NnTF \l_david_required_seq { #1 } { \textbullet\ } { $\circ$\ } #1
 }
\seq_new:N \l_david_required_seq
\ExplSyntaxOff

\newcolumntype{P}[1]{>{\collectcell\checkRequired}p{#1}<{\endcollectcell}}

\begin{document}
\requiredModules{Module02,Module04}

\begin{tabular}[t]{P{1.8cm}P{1.8cm}}
Module01 & Module02 \\
Module03 & Module04 \\
\end{tabular}

\end{document}

You declare the list of required modules and then prepare the table only changing the p specifiers to P.

Each table entry is checked against the list and, if present, a bullet is printed, otherwise a hollow circle.

enter image description here

The list is reset when \requiredModules is found. So you can even reuse a big table:

\newcommand{\moduletable}{%
  \begin{tabular}[t]{P{1.8cm}P{1.8cm}}
  \hline
  Module01 & Module02 \\
  Module03 & Module04 \\
  \hline
  \end{tabular}}

Then

\requiredModules{Module01,Module04}\moduletable

\requiredModules{Module01,Module02}\moduletable

would print

enter image description here


If you have defined the table as above, you can simplify the final input by adding another definition:

\newcommand{\generateModuleTable}[1]{%
  \requiredModules{#1}\moduletable}

So, the full code for printing the two tables above would be

\documentclass{article}
\usepackage{collcell,xparse}
\ExplSyntaxOn
\NewDocumentCommand{\requiredModules}{m}
 {
  \seq_set_split:Nnn \l_david_required_seq { , }{ #1 }
 }

\NewDocumentCommand{\checkRequired}{m}
 {
  \seq_if_in:NnTF \l_david_required_seq { #1 } { \textbullet\ } { $\circ$\ } #1
 }
\seq_new:N \l_david_required_seq
\ExplSyntaxOff

\newcolumntype{P}[1]{>{\collectcell\checkRequired}p{#1}<{\endcollectcell}}

%%% Define the big table
\newcommand{\moduletable}{%
  \begin{tabular}[t]{P{1.8cm}P{1.8cm}}
  \hline
  Module01 & Module02 \\
  Module03 & Module04 \\
  \hline
  \end{tabular}}

\newcommand{\generateModuleTable}[1]{%
  \requiredModules{#1}\moduletable}



\begin{document}

\generateModuleTable{Module01,Module04}

\generateModuleTable{Module01,Module02}

\end{document}
5
  • is it also possible to map Abbrevations for the Modules? e.g. if you want to type M1 instead of Module01, but Module01 should be displayed in the table...
    – David
    Jun 11, 2012 at 10:51
  • Are the names in the table exactly of the form "ModuleXY"?
    – egreg
    Jun 11, 2012 at 13:09
  • no they have their specific names, so it'll be necessary to define the mapping somewhere.. Tried something with iterating through the seq with the help of \seq_map_variable and mapping the names to another list with the help of a \prg_case_str, but didn't work for me...
    – David
    Jun 11, 2012 at 13:52
  • @David I don't understand why you unaccepted the answer; please, try and state precisely the new problem in your question. Probably property lists can be very useful in this case, but it's impossible to tell something precise without knowing the requirements.
    – egreg
    Jun 12, 2012 at 9:16
  • Your answer was right. I solved the other problem by my own, thanks :)
    – David
    Jun 12, 2012 at 9:53

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .