# Passing more command line argument

I am new to latex. I would like to pass command line arguments (probably more) to \newcommand macro and expecting output like below.

if input is 1
/include {1.tex}

else if input is 2
/include {2.tex}
else if input is 3
/include {3.tex}
else if input is 1 and 2
/include {1.tex}
/include {2.tex}
else if input is 1 and 2  and 3
/include {1.tex}
/include {2.tex}
/include {3.tex}


and so on. I have heard some xkeyval, xargs packages do like this. But i am not sure about its implementations.

How can i give too many arguments to latex? How can i parse/differentiate the arguments and then pass accordingly?

-
It looks like you want to have something like a \multiinput{1,2,3}, in other words input is the name of the files to be added. Am I right? –  percusse Mar 26 at 14:41
Hi Thanks for the reply.Input is not the name of file. It is actually any word (for example bird, vehicle), depends on the word i should add files probably, in following loop (ex:if word =bird then /include{parrot.tex} /include{dove.tex} else if word = vehicle then /include{car.tex} /include{bike.tex} ) –  umaraman Mar 27 at 12:16

Here's an example of a umaraman.tex file:

\documentclass{article}

\makeatletter
\ifdefined\umafiles\else\let\umafiles\@empty\fi
\newcommand{\umainput}[1]{%
\ifx\umafiles\@empty\input{#1}\else
\@for\next:=\umafiles\do{%
\ifnum\pdfstrcmp{#1}{\next}=\z@\input{#1}\fi
}
\fi}
\makeatother

\begin{document}
\umainput{uma1}
\umainput{uma2}
\umainput{uma3}
\umainput{uma4}
\umainput{uma5}
\end{document}


Of course the files can be named as you wish. If you call from the command line

pdflatex "\def\umafiles{uma1,uma3}\input{umaraman.tex}"


only uma1 and uma3 will be input. If you instead call normally

pdflatex umaraman.tex


all files will be input.

-

You can use the \getargs feature of the stringstrings package (edited for more clarity). I have set the following to take commands from a command-directive file mycommands.tex. This command-directive file gives various combinations of merge commands, which are up to the discretion of the user. It can give a list of directives, or use conditional compilation (which seems to be what you desire). The condition for the compilation is specified on the first line of the directives file.

First, here is the program

\documentclass{article}
\usepackage{stringstrings}
\newcounter{myindex}
\newcommand\merge[1]{%
\getargs{#1}%
\setcounter{myindex}{0}%
\whiledo{\value{myindex} < \narg}{%
\expandafter\input\expandafter{\csname arg\roman{myindex}.tex\endcsname}%
}%
}
\parindent 0in\parskip 1em
\begin{document}
\input{mycommands.tex}
\end{document}


There here is the content of the directives file, mycommands.tex

\merge{2 3}%


Then, here are the three data files, 1.tex, 2.tex, and 3.tex, respectively. In each, I only put a single sentence, but you could have whole chapters in these files.

This is the contents of 1.tex.


and

Here, we have the contents of 2.tex.


and

\ldots and finally, we have the contents of 3.tex.


Finally, here is the output:

-
Hi Steven, Thanks for the reply. Actually my task is 1.Get input from command line. (for example bird vehicle book. ) 2.Parse it so that it will becomes 3 inputs to my loop (bird and vehicle book .It is actually any word (for example bird, vehicle), 3. Depends on the input files are needs to be included (ex:if input = bird then /include{parrot.tex} /include{dove.tex} else if input = vehicle then /include{car.tex} /include{bike.tex} else if input = vehicle and book then /include{car.tex} /include{bike.tex} /include{magazine.tex} ) –  umaraman Mar 27 at 12:49
@umaraman You speak of getting input from command line. I'd have to look how that is done (not knowing it yet). However, is getting input from a (command directive) file an acceptable alternative? –  Steven B. Segletes Mar 27 at 13:37