0

Let's say I have a document consisting mainly of ''task''-macros that are defined as following:

% bold titles
\newcommand{\mypar}[1]{{\bf #1:}}

%task decription template
\newcommand{\task}[3]{
    \mypar{#1} #2 \\
    \emph{Solution:} #3\\
}

Where #1 is supposed to be the title of a task, #2 its description and #3 its solution.

Is there a way to sort all such macros within the same section by their titles?

Should be a way I can also extend to other macros, e.g.

\newcommand{\code}[2]{
    \subsubsection{#1}
    \lstinputlisting{#2}
}
\newcommand{\npcode}[2]{
    \newpage
    \code{#1}{#2}
}

Where I would want to sort them by subsubsection titles.

User1291
  • 545
  • I don't get this question. What should be sorted? The name of the title of a task? –  Jan 25 '16 at 13:40
  • Given a chain of such macros, I would shift the text they insert such that it appears in the same order as if they had been inserted in lexicographical order by title. (i.e. \task{A}{...}{...}\\task{B}{...}{...}\\task{C}{...}{...}). – User1291 Jan 25 '16 at 14:09
  • you clearly would need to change the markup and definitions to first collect a list of items and then output the sorted list rather than typeset as you go, it is probably possible in simple cases if there are not too many complicated characters to sort, but tex isn't particularly good at sorting which is why usually an external program is used such as makeindex or bibtex. (Unrelated but note that you are missing a lot of % in your definitions) – David Carlisle Jan 25 '16 at 14:28
  • This is probably a duplicate of http://tex.stackexchange.com/a/121492/1090 – David Carlisle Jan 25 '16 at 14:31

0 Answers0