Is it possible to tell latex, that it should sort the sections you used in your document according to their alphabetical order in the final pdf document? I.e. I want to have something like this
\begin{document}
\section{A}
\section{C}
\section{B}
\end{document}
and in the pdf I get the result as
A
B
C
Is that possible, and if yes, how? Putting the sections into separate files is not preferred (but possible if scripted) due to having ~300 sections.
Edit: I can also rewrite it as
\begin{sortEnvironment}{Title}
Content
\end{sortEnvironment}
if that makes it easier.
Best Answer
(This answer is an improvement over my previous answer where you had to create the external files manually and run external command from shell prompt. For the present one, you do everything in LaTeX.)
In this answer, I used the LaTeX environment you wanted to use. Here, the sections are written to separate files, and the list is put in a master file, which is sorted using external shell command and then input when you issue the
\PrintSections
command.Here is the code. You need to provide the
-shell-escape
option while executing latex or pdflatex.Here is the output.