23

Are there useful navigation shortcuts in emacs when editing a TeX source? For example jump to the beginning/end of section, or similar thing for environment, etc.

C-v and M-v are too coarse, and I am looking for smarter navigation tips. Something in the spirit of C-M f and C-M b which jump over balanced braces.

2
  • 1
    There is the C-M-a and C-M-e keys which jump to beginning and end of current environment? But only by using AucTeX.
    – nickpapior
    Aug 7, 2012 at 10:39
  • I use the jove (Jonathan's Own Version of Emacs) editor. While it is not intrinsically set up to support LaTeX, it is programmable with macros, key rebinding, etc. Here is a full manual: manuals.its.virginia.edu/unixdocs/u003a.jove.ref.html Jun 25, 2015 at 2:24

5 Answers 5

22

If you use AucTeX, with outline minor mode turned on, you get a series of useful key-bindings, including (C- = Ctrl-):

C-c @ C-n   Move to next heading (at any level)
C-c @ C-p   Move to previous heading (at any level)
C-c @ C-f   Move Forward to next heading at the same level
C-c @ C-b   Move Backward to previous heading at the same level

(A quick look at the AucTeX Reference Card will get you started.)

5
  • AucTeX Reference Card link is broken Jun 23, 2015 at 21:42
  • @CharlesHolbrow I've updated the answer, but unfortunately haven't been able to find a good replacement for the link. What I did find didn't have the details of the key bindings. Jun 24, 2015 at 20:04
  • @Thérèse Actually, I had the good sense to look on CTAN first :) Updated with the new link. Jun 24, 2015 at 20:29
  • @SeanAllred The new link might break when the next version of Auctex is released. Note that the source for the reference card, tex-ref.info, ships with auctex in the ./doc directory. The pdf is also available from manual and reference card link on the auctex project pages: gnu.org/software/auctex/download-for-unix.html
    – Tyler
    Jun 24, 2015 at 20:38
  • @Tyler Hmm, right. (And yes, I know that the source is distributed with AucTeX, but web-based tools (like SE) should provide web-based resources (like hosted PDFs).) Jun 24, 2015 at 20:43
6

The answer lies in Emacs for navigating around a document.

For specific needs in Tex, I would make a macro.

For next section (which is same as ending of previous section):

    F3          % start recording
    C-s section % search forward for any type of "section"; \sec for specifically \section
    RETURN      % stop there
    F4          % end recording  
    % you could choose to search for \begin{, or for anything.
    Reusing the F4 will replay the macro, so you can test it.

Save it for later use " C-x C-k n " then giving the name, and using Return.

M-x insert-kbd-macro RETURN the-given-name RETURN will paste the code into your document.

If you then put the code into your .emacs file, followed by

    (eval-after-load 'latex
                     '(define-key LaTeX-mode-map (kbd "C-c C-z") 'the-given-name))

The keybind will only load when you enter latex mode. (First restart/reload the .emacs) This way C-c C-z would go to the next section (or other specified search)

1
  • It might seem like a lot of work, but once you get the hang of it you can make new commands within the minute. Aug 7, 2012 at 11:14
6

C-c = in reftex. But reftex is much more than that

How to use reftex http://jblevins.org/log/large

Keybindins at Section 1.2 RefTeX in a Nutshell
https://www.gnu.org/software/auctex/manual/reftex.html#SEC1

3

I've recently discovered that imenu works well in TeX buffers. Paired with Helm completion, it's a force to be reckoned with. It isn't as heavy-weight as RefTeX for documents that wouldn't otherwise benefit from RefTeX's functionality.

For a sample, try out this document:

\documentclass{article}
\begin{document}
\section{hello}
\subsection{this}
\subsubsection{is}
\subsubsection{a}
\paragraph{simple}
\subparagraph{test}
\subsubsection{of}
\subsection{imenu}
\section{in}
\part{emacs}
\end{document}

Again, I strongly recommend using Helm with this solution.

1

outline-magic extends the outline modes to use org-mode-like hiding/showing with the magic tab key.

Then I added smarter navigation tips as you asked in my init file

;; OUTLINE MAGIC
(add-hook 'LaTeX-mode-hook 'outline-minor-mode)
(use-package outline-magic
  :ensure t
  :config
  (define-key outline-minor-mode-map (kbd "<C-tab>") 'outline-cycle)
  (define-key outline-minor-mode-map (kbd "<M-up>") 'outline-previous-visible-heading)
  (define-key outline-minor-mode-map (kbd "<M-down>") 'outline-next-visible-heading)
  (define-key outline-minor-mode-map (kbd "<M-S-up>") 'outline-backward-same-level)
    (define-key outline-minor-mode-map (kbd "<M-S-down>") 'outline-forward-same-level)
  )

If you don't use use-package the following code should work if you put it in your init file:

;; OUTLINE MAGIC
(add-hook 'LaTeX-mode-hook 'outline-minor-mode)
(eval-after-load 'outline
  '(progn
    (require 'outline-magic)
    (define-key outline-minor-mode-map (kbd "<C-tab>") 'outline-cycle)
    (define-key outline-minor-mode-map (kbd "<M-up>") 'outline-previous-visible-heading)
    (define-key outline-minor-mode-map (kbd "<M-down>") 'outline-next-visible-heading)
    (define-key outline-minor-mode-map (kbd "<M-S-up>") 'outline-backward-same-level)
    (define-key outline-minor-mode-map (kbd "<M-S-down>") 'outline-forward-same-level)))

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .