Skip to content

Instantly share code, notes, and snippets.

@vermiculus
Created January 1, 2014 18:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vermiculus/8210123 to your computer and use it in GitHub Desktop.
Save vermiculus/8210123 to your computer and use it in GitHub Desktop.
(require 'cl) ; place your cursor after this paren and pres C-x C-e
(defun **strip-stuff (file &optional environments)
"Takes the current file and strips every environment from
`ENVIRONMENTS` into `FILE`."
(interactive "FFile name: \nxList of Environments (\"one\" \"two\" \"etc\"): ")
(if (every 'stringp environments)
(progn
(beginning-of-buffer)
(let ((search-regex (concat "\\\\begin{"
(mapconcat 'identity
environments
"\\|")
"}")))
(while (search-forward-regexp search-regex nil t)
(LaTeX-mark-environment)
(copy-region-as-kill (point) (mark))
(save-excursion
(find-file file)
(end-of-buffer)
(yank)
(newline 2)
(save-buffer)
(previous-buffer))
(exchange-point-and-mark)))
(message "Strip complete. Check %s for the output." file))
(message (concat "The environment variable you provided"
" was not a list of strings.")))) ; here too
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment