5

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?

percusse
  • 157,807
BusyBee
  • 123
  • 4

1 Answers1

1

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.

egreg
  • 1,121,712