0

I have a sheet of input orders like:

  1. \input{something}
  2. \input{another thing}
  3. \input{some other thing}
  4. ...

I want to make a command like \myinput{} so that if I use \myinput{24} then that will input my 24-th tex in the main tex.

I know I can define this \myinput{} like

\ifnum #1=1 \input{...}
\else\ifnum #1=2 \input{...}
\else\ifnum #1=3 \input{...} 
\fi 

But this is too long... How can I make this command more brief?

1

1 Answer 1

2

Define a sequence from the file list and use \seq_item:Nn.

\begin{filecontents*}{aa}
I am file aa
\end{filecontents*}
\begin{filecontents*}{xyz}
I am file xyz
\end{filecontents*}
\begin{filecontents*}{cc}
I am file cc
\end{filecontents*}

\documentclass{article}

\ExplSyntaxOn

\NewDocumentCommand{\varinput}{m}
 {
  \file_input:n { \seq_item:Nn \g_ngiap_varinput_seq { #1 } }
 }

\seq_new:N \g_ngiap_varinput_seq

\NewDocumentCommand{\varinputlist}{m}
 {
  \seq_gset_from_clist:Nn \g_ngiap_varinput_seq { #1 }
 }

\ExplSyntaxOff

\varinputlist{aa,xyz,cc}

\begin{document}

\varinput{1}

\varinput{3}

\varinput{2}

\end{document}

enter image description here

You must log in to answer this question.

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