Skip to content

Instantly share code, notes, and snippets.

@shakthimaan
Created February 6, 2016 04:17
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 shakthimaan/a0c434af0d3fa8997692 to your computer and use it in GitHub Desktop.
Save shakthimaan/a0c434af0d3fa8997692 to your computer and use it in GitHub Desktop.
replace-regexp on file
(defun org-to-latex-toc ()
"Map org sections to LaTeX ToC."
(interactive)
(let ((case-fold-search nil))
(goto-char 1)
(replace-regexp "^\\\\section" "\\\\chapter")
(goto-char 1)
(replace-regexp "^\\\\subsection" "\\\\section")
(goto-char 1)
(replace-regexp "^\\\\subsubsection" "\\\\subsection")
)
)
@offby1
Copy link

offby1 commented Feb 6, 2016

How I'd do it:

(defun org-to-latex-toc (filename)
  "Map org sections to LaTeX ToC."
  (interactive "fFile to hack on: ")
  (with-current-buffer (find-file filename)
    (let ((case-fold-search nil))
      (goto-char (point-min))
      (while (re-search-forward  (rx bol "\\\\section") (point-max) nil)
        (replace-match "\\\\chapter" nil t))
      (goto-char (point-min))
      (while (re-search-forward (rx bol "\\\\subsection") (point-max) nil)
        (replace-match "\\\\section" nil t))
      (goto-char (point-min))
      (while (re-search-forward (rx bol "\\\\subsubsection") (point-max) nil)
        (replace-match  "\\\\subsection" nil t)))))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment