Parentheses into Footnotes Background

LISP programmers have taken over the world!
Parentheses have been declared as sacred characters, and from now on, they can only be used in LISP programs.
It has been decided that parentheses in literary works shall be replaced by footnotes, and it's your job to automate this for simplified Markdown text.

Input

Your input is a single string containing alphabetic ASCII characters, spaces, and the special characters ,.!?().
It will not contain newlines or digits.
The parentheses will be correctly matched.

Output

You shall convert each matched pair of parentheses in the input string into a footnote.
This happens as follows:


Replace the first matching pair of parentheses and the substring between them by a running number that starts from 1, wrapped between the Markdown tags &lt;sup&gt; and &lt;/sup&gt;.
Append to the end of the string


two newlines,
the Markdown tag &lt;sub&gt;,
the number from step 1,
a space,
the substring between the parentheses, and
the closing tag &lt;/sub&gt;, in this order.

If there are still parentheses left in the string, go to step 1.


Your output is the resulting string, possibly with a trailing newline.
You don't have to implement this exact algorithm, as long as your output is correct.
Note that there may be nested parentheses; in that case, we'll have footnotes that contain references to other footnotes.
The substring between parentheses may also be empty.
See the test cases below for examples.

Rules and Scoring

Your can write either a full program or a function.
The lowest byte count wins, and standard loopholes are disallowed.

If your language does not natively support decimal numbers (cough Retina cough), you may give the footnote numbers in another base, including binary or unary; however, using unary numbers imposes a penalty of +20%.

Test Cases

Input:

This input contains no parentheses.


Output:

This input contains no parentheses.


Input:

This has (some) parentheses (but not so many).


Output:

This has &lt;sup&gt;1&lt;/sup&gt; parentheses &lt;sup&gt;2&lt;/sup&gt;.

&lt;sub&gt;1 some&lt;/sub&gt;

&lt;sub&gt;2 but not so many&lt;/sub&gt;


Input:

This has (nested (deeply (or highly?) nested)) parentheses (and several groups).


Output:

This has &lt;sup&gt;1&lt;/sup&gt; parentheses &lt;sup&gt;2&lt;/sup&gt;.

&lt;sub&gt;1 nested &lt;sup&gt;3&lt;/sup&gt;&lt;/sub&gt;

&lt;sub&gt;2 and several groups&lt;/sub&gt;

&lt;sub&gt;3 deeply &lt;sup&gt;4&lt;/sup&gt; nested&lt;/sub&gt;

&lt;sub&gt;4 or highly?&lt;/sub&gt;


Input:

Hmm()(()(,))  a()((trt)(v( (((((wut)))))(X)(Y)(Z) )!?!?!?!))oooooooo(oooo)oooo


Output:

Hmm&lt;sup&gt;1&lt;/sup&gt;&lt;sup&gt;2&lt;/sup&gt;  a&lt;sup&gt;3&lt;/sup&gt;&lt;sup&gt;4&lt;/sup&gt;oooooooo&lt;sup&gt;5&lt;/sup&gt;oooo

&lt;sub&gt;1 &lt;/sub&gt;

&lt;sub&gt;2 &lt;sup&gt;6&lt;/sup&gt;&lt;sup&gt;7&lt;/sup&gt;&lt;/sub&gt;

&lt;sub&gt;3 &lt;/sub&gt;

&lt;sub&gt;4 &lt;sup&gt;8&lt;/sup&gt;&lt;sup&gt;9&lt;/sup&gt;&lt;/sub&gt;

&lt;sub&gt;5 oooo&lt;/sub&gt;

&lt;sub&gt;6 &lt;/sub&gt;

&lt;sub&gt;7 ,&lt;/sub&gt;

&lt;sub&gt;8 trt&lt;/sub&gt;

&lt;sub&gt;9 v&lt;sup&gt;10&lt;/sup&gt;!?!?!?!&lt;/sub&gt;

&lt;sub&gt;10  &lt;sup&gt;11&lt;/sup&gt;&lt;sup&gt;12&lt;/sup&gt;&lt;sup&gt;13&lt;/sup&gt;&lt;sup&gt;14&lt;/sup&gt; &lt;/sub&gt;

&lt;sub&gt;11 &lt;sup&gt;15&lt;/sup&gt;&lt;/sub&gt;

&lt;sub&gt;12 X&lt;/sub&gt;

&lt;sub&gt;13 Y&lt;/sub&gt;

&lt;sub&gt;14 Z&lt;/sub&gt;

&lt;sub&gt;15 &lt;sup&gt;16&lt;/sup&gt;&lt;/sub&gt;

&lt;sub&gt;16 &lt;sup&gt;17&lt;/sup&gt;&lt;/sub&gt;

&lt;sub&gt;17 &lt;sup&gt;18&lt;/sup&gt;&lt;/sub&gt;

&lt;sub&gt;18 wut&lt;/sub&gt;


Note the empty lines between the footnotes.
Emacs Lisp, 335 bytes

Foreword. This answer and the Scheme ones are currently the only answers officially sanctioned by both the Mighty Popular Republic of LISP and the Church of Emacs. Other answers, shorter or not, are considered a threat to peace. In particular, and with a profound disdain to any libelious allegation of McCarthyism that is sporadically heard from hostile opponents of the state, we enjoin anyone who has information about the real identity of the anonymous  authors writing Nonlisp answers to contact your Local Bureau. It is reminded that everyone should take time to reflect and upvote in accordance to what he or she deeply believes will not threaten his or her future interactions with official representants of the power in place. Code is data. Data is code.

(defun p()(let(b(cpt 0)n)(goto-char 0)(while(search-forward"("()t)(setf b(point)n(number-to-string(incf cpt)))(backward-char)(forward-sexp)(backward-char)(kill-region b(point))(delete-backward-char 1)(delete-forward-char 1)(insert "&lt;sup&gt;"n"&lt;/sup&gt;")(save-excursion(end-of-buffer)(newline 2)(insert "&lt;sub&gt;"n" ")(yank)(insert"&lt;/sub&gt;")))))


More elegantly:

(defun parens ()
  (let (b(cpt 0)n)
    (goto-char 0)
    (while(search-forward"("()t)
      (setf b(point)n(number-to-string(incf cpt)))
      (backward-char)
      (forward-sexp)
      (backward-char)
      (kill-region b(point))
      (delete-backward-char 1)
      (delete-forward-char 1)
      (insert "&lt;sup&gt;"n"&lt;/sup&gt;")
      (save-excursion
       (end-of-buffer)
       (newline 2)
       (insert "&lt;sub&gt;"n" ")
       (yank)
       (insert "&lt;/sub&gt;")))))