# Automatically generate similar docs

I need to generate the document containing items from txt file (for example). Txt file:

Item 1
Item 2
Item 3
Item 4
Item 5
Item 6


Can I run script (?) which generate about the following:

1. Item 1 (from txt)
2. Item 4 (from txt)

1.Item 2 (from txt)

2.Item 5 (from txt)

1.Item 3 (from txt)

2.Item 6 (from txt)

Is it possible or I should use other language and it will be more easier?

• Your question is very unclear at the moment. What do you mean by "Header" here? Are you generating a single document as output? If so, you might want to use the datatool package, which can read CSV files. – Alan Munn Apr 17 '17 at 16:11
• Or have a look at Pandoc, but how is this TeX-related? – TeXnician Apr 17 '17 at 16:16
• "Header" here is arbitrary string. Yes, I need a single document. I have a list of items and I need to generate a document with a specific structure. Document should contains items from the list. – Vasya Pravdin Apr 17 '17 at 16:34
• I'm sorry but this is still not clear. How do you choose which line from the file goes in which list? Is it arbitrary? Is there a pattern? Do you search for something? Do you have control over the text file format? If you do, then formatting the text file as CSV would be simpler, I suspect. – Alan Munn Apr 17 '17 at 17:14
• So, I have the txt file with questions. And I want to generate the file with random questions without repetitions. But the output file should be not only list, I need to numerate the pairs of qustions: Ticket #1. 1.Question 1. 2. Question 2. Ticket #2. 1. Question 3. 2. Question 4. – Vasya Pravdin Apr 17 '17 at 17:22

Here is an option.

file.txt

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer nec odio.
Praesent libero. Sed cursus ante dapibus diam. Sed nisi.
Nulla quis sem at nibh elementum imperdiet. Duis sagittis ipsum.
Praesent mauris. Fusce nec tellus sed augue semper porta. Mauris massa.
Vestibulum lacinia arcu eget nulla.
Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos.
Curabitur sodales ligula in libero.
Sed dignissim lacinia nunc. Curabitur tortor.
Pellentesque nibh. Aenean quam. In scelerisque sem at dolor.
Maecenas mattis. Sed convallis tristique sem.
Proin ut ligula vel nunc egestas porttitor.


Main.tex

\documentclass{article}

\newcounter{mtctr}
\newcounter{tmp}
\openin\mt=file.txt
\loop
\unless\ifeof\mt
\stepcounter{mtctr}
\expandafter\xdef\csname question\themtctr\endcsname{\mtt}
\repeat
\closein\mt
\xdef\qustionnbr{\themtctr}
\setcounter{mtctr}{0}

\renewcommand\labelenumi{\thetmp.\theenumi.}

\begin{document}
\loop
\stepcounter{tmp}
\begin{enumerate}
\stepcounter{mtctr}
\item \csname question\themtctr\endcsname
\ifnum\value{mtctr}<\qustionnbr
\stepcounter{mtctr}
\item \csname question\themtctr\endcsname
\fi
\end{enumerate}
\ifnum\value{mtctr}<\qustionnbr
\repeat
\end{document}


Update Here is a shorter version.

\documentclass{article}

\newcounter{tmp}
\openin\mt=file.txt

\renewcommand\labelenumi{\thetmp.\theenumi.}

\begin{document}

\loop
\unless\ifeof\mt
\ifeof\mt\else
\stepcounter{tmp}