[Tex/LaTex] Can LaTeX automatically itemize a list

#enumerateautomationscripts

So I have a word list file in .txt format,

enter image description here

I want to edit it and enumerate them. But since the file runs into thousands of lines potentially, it would be a daunting task to do it manually. I wonder if it is possible to automatically enumerate all the words (and make other small repetitive changes to each word) and even better, randomize them.

N.B. I am not exactly sure if it is a task that can or should be done in LaTeX, so if not, I also welcome an alternative suggestion. Thanks in advance.

Edit: When I meant small repetitive change, I have in mind something like drawing a ____ after each word.

So essentially, I need LaTex to do three things:

  1. read the file and itemize it
  2. draw a line after every word
  3. randomize the whole list.

Sorry, I should have formated my questions better.

Best Answer

I propose a solution using the csvsimple package.

\documentclass{article}
\usepackage{csvsimple}

\begin{filecontents}{list.csv}
religion
religious
rely
remain
\end{filecontents}

\begin{document}

\csvloop{
    file = {list.csv},
    no head,
    before reading = {\begin{enumerate}},
    after reading = {\end{enumerate}},
    before line = \item
}

\end{document}

Edit

In order to draw a line after the elements, use a \rule:

\documentclass{article}
\usepackage{csvsimple}

\begin{filecontents}{list.csv}
religion
religious
rely
remain
\end{filecontents}

\begin{document}

\csvloop{
    file = {list.csv},
    no head,
    before reading = {\begin{enumerate}},
    after reading = {\end{enumerate}},
    before line = \item,
    after line = \rule{1cm}{.4pt}
}

\end{document}

As LaTeX does not store the individual items of an enumerate, it's tricky to shuffle the items. There are some heavy solutions to this problem, but I wouldn't recommend any of them when handling large datasets ("thousands of lines potentially"). Just quickly set up a Python script to shuffle your list around before compiling your document.

import random

with open('data.csv', 'r') as input_file:
    data = input_file.readlines()

random.shuffle(data)

with open('output_file.csv', 'w') as output_file:
    for item in data:
        output_file.writelines(item)

You could even have a look at the pythontex package which enables you to add executable Python code to your LaTeX file. Upon document generation, the code will be executed and the results are added to the LaTeX file. I could imagine, that this would allow you to implement the shuffling to the document generation.

Related Question