1

I very much enjoying using the auto fill functionality that the key binding M-q provides. However, starting recently, I am experiencing a small (but annoying) change in its behavior when in LaTeX mode. That is, now I have to explicitly mark the paragraph that I want to auto fill, whereas before it was good enough as long as the cursor is somewhere in the paragraph. For example, to format

Hello 
World

to

Hello World

it was enough to hit M-q with my cursor somewhere in those two lines. Now I have to mark the two lines and then hit M-q to get the reformatting. I haven't installed anything new or touched my configuration file. I did update Emacs a couple days ago. Any advice will be greatly appreciated.

3
  • Turns out that this was happening because I was in the "appendices" environment, but still finding a way to make this not happen in the "appendices" environment. – apprentice Oct 7 '20 at 12:51
  • 1
    When you have your .tex file opened, what is the value of the variable LaTeX-indent-environment-list in that buffer?. You can check it with C-h v LaTeX-indent-environment-list RET. Do you see an entry for appendices? – Arash Esbati Oct 10 '20 at 14:39
  • Yes, I see ("appendices" current-indentation), which I think I added in an attempt to solve the issue. Also, not sure if relevant, but while I can use the appendices environment without any issue but auctex won't autocomplete appendices unlike other environments such as align, equation, etc. – apprentice Oct 10 '20 at 19:01
1

Entries in LaTeX-indent-environment-list control the filling behavior in environments. If you want the standard filling AUCTeX applies to environments, remove entries for your appendices from it and M-q should work again.

The appendices environment is provided by LaTeX package appendix.sty. In order to get auto-completion for it when you hit C-c C-e, you need a small AUCTeX style appendix.el which makes the addition to AUCTeX. Such a style can look like this:

(TeX-add-style-hook
 "appendix"
 (lambda ()

   (TeX-add-symbols
    "appendixpage"
    "addappheadtotoc"
    "noappendicestocpagenum"
    "appendicestocpagenum"
    "appendixname"
    "appendixtocname"
    "appendixpagename"

    "appendixtocon"
    "appendixtocoff"
    "appendixpageon"
    "appendixpageoff"
    "appendixtitleon"
    "appendixtitleoff"
    "appendixtitletocon"
    "appendixtitletocoff"
    "appendixheaderon"
    "appendixheaderoff"
    "restoreapp"

    "setthesection"
    "setthesubsection")

   (LaTeX-add-environments
    '("appendices")
    '("subappendices"))

   ;; Don't indent the content inside \(sub\)?appendices environments:
   (unless (string-match "appendices" LaTeX-document-regexp)
     (set (make-local-variable 'LaTeX-document-regexp)
          (concat LaTeX-document-regexp "\\|\\(?:sub\\)?appendices"))))
 LaTeX-dialect)

(defvar LaTeX-appendix-package-options '("toc" "page" "title"
                                         "titletoc" "header")
  "Package options for the appendix package.")

Set the variable TeX-style-private to a directory of your choice, e.g.

(setq TeX-style-private
      '("~/.emacs.d/auctex-styles"))

and save the code above there as appendix.el. Now re-start Emacs and open your .tex file. If you have this in your init file as well

(setq TeX-parse-self t)

the auto-completion should be available directly.

4
  • I'll try this tonight. Thanks for the comment. Regarding autocomplete, I didn't have to go through any of that for the amsmath environments and autocomplete still works well - why is the appendix package special in this aspect? Thanks! – apprentice Oct 14 '20 at 17:52
  • Okay, so your suggestion kind of solved the issue, but now the tab key indents everything in the appendices environment - can I make this not happen? I just want the appendices environment to work like the "document" environment without any special indentation or whatsoever. Thanks! – apprentice Oct 19 '20 at 19:25
  • @apprentice - Can't reproduce what you describe. The form (unless (string-match "appendices" LaTeX-document-regexp) (set (make-local-variable 'LaTeX-document-regexp) ...) does exactly what you're asking for. Hit C-h e when you've opened your .tex file and see if appendix.el is loaded. Also check the value of the variableLaTeX-document-regexp in the buffer. – Arash Esbati Oct 20 '20 at 20:24
  • I had to add appendices to the variable to LaTeX-verbatim-environments. Everything works like a charm now. So the bottom line is: do NOT add appdendices to LaTeX-indent-environment-list, but add it to LaTeX-verbatim-environments. Thanks for all the help! – apprentice Oct 21 '20 at 4:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.