* Tyler Smith <[EMAIL PROTECTED]> [070527 00:00]: > On 2007-05-26, Tyler Smith <[EMAIL PROTECTED]> wrote: > > On 2007-05-26, Russell L. Harris <[EMAIL PROTECTED]> wrote: > >> I need to extract footnotes from a very long LaTeX document. I would > >> like to start with a copy of the document, then delete from the copy > >> all text which is not a footnote. > >> > > > > The easy way: > > > > You can use occur to extract all your footnotes to a separate buffer: > > > > M-x occur > > \\footnote{[^}]* > > > > Hi, > > As you may have realised, if you've tried my easy solution, it is > easily fooled when your footnotes contain other expressions that > contain curly-braces. I've worked out a more robust solution that > is harder to fool. What it does is copy all your footnotes to a > separate buffer called *FOOTNOTES*. The original document is not > altered, and point remains where you left it - you won't see any > change at all until you switch buffers. You can invoke this function > with 'M-x extract-footnotes'. > > To install the function put the following code in your .emacs, or I > suppose that would be .xemacs for you. It will be loaded automatically > the next time you open xemacs, or you can load it immediately by > placing the cursor just after the last parenthesis and hitting C-x C-e > One note - I had to turn off transient-mark-mode to get this to > work. I don't know why. If you like to use transient mark mode you'll > have to turn it back on afterwards. > > Here's the code, hope it helps! > > Tyler > > (defun extract-footnotes () > "Copy all footnotes to a separate *FOOTNOTES* buffer" > (interactive) > (let ((active-buffer (current-buffer))) > (save-excursion > (if (memq (get-buffer "*FOOTNOTES*") (buffer-list)) > (kill-buffer "*FOOTNOTES*")) > (transient-mark-mode -1) > (goto-char (point-min)) > (while (search-forward "\\footnote" nil t) > (goto-char (match-beginning 0)) > (push-mark) > (search-forward "e" nil t) > (forward-list) > (append-to-buffer (get-buffer-create "*FOOTNOTES*") > (mark) (point)) > (set-buffer "*FOOTNOTES*") > (goto-char (point-max)) > (insert "\n") > (set-buffer active-buffer)))))
Thanks, Tyler. I did discover the problem with the previous solution, because the footnotes utilize \emph{...} and \textit{\textbf{...}}. I looked for transient-mark-mode in XEmacs, but did not find it. "M-x transient-mark-mode" gives a "no match" error. Next, I decided to try to write a Perl script, and that's the point at which I presently find myself. So now I'll stop and give it a try with the code above. I keep thinking that this should be a feature for which there is general demand, because it is so useful. At least it is possible to set the mark and then execute M-, or M-. in order to highlight the previous or remaining portion of the document. RLH -- To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]