I have an initial sentence:
The quick brown fox jumps over the lazy dog.
I have a new sentence (which is always a jumble of the original sentence):
The lazy dog jumps over the quick brown fox.
In the original sentence, for each word, I want to superscript the word position as according to the jumbled sentence. Can someone guide me as to how I can achieve this?
Any novel approach (using new packages) is appreciated. Thanks in advance. In the following MWE, I am obviously not achieving what I actually want.
\documentclass[12pt]{memoir}
\usepackage{listofitems}
\usepackage{amsmath}
\newcommand{\wordsI}
{ 1. The,
2. quick,
3. brown,
4. fox
+
5. jumps,
6. over,
7. the,
8. lazy,
9. dog
}
\newcommand{\wordsII}
{ The
lazy
dog
jumps
over
the
quick
brown
fox
}
% Tokenize the words in order to display them
\newcommand{\tokenize}[1]
{%
\setsepchar{+/,/./}
\readlist*\textarray{#1}
\foreachitem\groupoflines\in\textarray
{
\setsepchar{,}
\readlist*\linearray{\groupoflines}
\foreachitem\line\in\linearray
{
\setsepchar{.}
\readlist*\wordarray{\line}
$ \text{\wordarray[2]} ^ {\wordarray[1]} $
}%
\newline
}
}
\begin{document}
\noindent
Actual sentence:
\newline
% The splitting of the sentence in 2 lines is intentional
\tokenize{\wordsI}
\noindent
Jumbled sentence:
\textbf{\wordsII}
\end{document}
In this example, I will get the result I need if I have the following definition instead:
\newcommand{\wordsI}
{ 1. The,
7. quick,
8. brown,
9. fox
+
4. jumps,
5. over,
6. the,
2. lazy,
3. dog
}
But, I don't want to make the change manually. I am looking for a way to make it 'dynamic' based on the jumbled sentence.
EDIT: I want to achieve this even in scenarios like this:
Initial sentence:
the quick brown fox jumps over the lazy dog.
Jumbled sentence:
the lazy dog jumps over the quick brown fox.
In this case, I need to have some kind of 'tags' for the words in the initial sentence in order for the jumbled sentence to be non-ambiguous.
\newcommand{\wordsI}
{ 1. the,
2. quick,
3. brown,
4. fox
+
5. jumps,
6. over,
7. the,
8. lazy,
9. dog
}
\newcommand{\wordsII}
{ 7. the
8. lazy
9. dog
5. jumps
6. over
1. the
2. quick
3. brown
4. fox
}




the(1)andthe(7):-) – ShreevatsaR Jul 03 '17 at 14:31