2

I am currently using songs package, which via some TeX trickery uses escaped brackets to mark chords (for example \[G] is G-major, while \[a] is a-minor). This causes problems with indentation, for example this is how the following snippet gets indented (every \[ introduces new indent level):

\begin{song}
  \begin{verse}
    \[G]This is \[D]some \[A]guitar song
          \[G]annotated with \[D]the chords
              to \[e]make playing ea\[H7]sier.
  \end{verse}
\end{song}

while of course I would like to get:

\begin{song}
  \begin{verse}
    \[G]This is \[D]some \[A]guitar song
    \[G]annotated with \[D]the chords
    to \[e]make playing ea\[H7]sier.
  \end{verse}
\end{song}

I managed to resolve this by removing bracket indentation completely:

(setq LaTeX-begin-regexp "begin\\b")      ; Default is begin\\b\\|\\[
(setq LaTeX-end-regexp "end\\b")          ; Default is end\\b\\|\\]

but this impacts also my various other uses of \[, including math…

So, the question is, whether it is possible to disable indenting behaviour of bracket just inside specific environment (song), while leaving it unchanged everywhere else.

If impossible, what is the easiest/recommended way to change LaTeX-begin-regex and LaTeX-end-regexp just for specific files instead of customizing it globally?

2

You can advise LaTeX-indent-level-count

(defadvice LaTeX-indent-level-count
    (around advice-LaTeX-indent-level-count activate)
  (let ((LaTeX-begin-regexp
     (if (equal (LaTeX-current-environment) "verse")
         "begin\\b"
       "begin\\b\\|\\["))
    (LaTeX-end-regexp
     (if (equal (LaTeX-current-environment) "verse")
         "end\\b"
       "end\\b\\|\\]")))
    ad-do-it))

This will set LaTeX-begin-regexp to "begin\\b" within verse environment and to "begin\\b\\|\\[" otherwise, the same for LaTeX-end-regexp.

  • Thank you, it works. I slightly fixed the function to accomodate more environments, will post it as next answer. Question: could this be improved to handle indirect cases (like \begin{verse}\begin{somethelse}...) – Mekk Sep 21 '15 at 17:26
  • LaTeX-current-environment can take an optional argument with the number of the outer environment to check. For small changes you can also edit this answer ;-) – giordano Sep 21 '15 at 21:05
0

Slightly fixed function, to accomodate different wrapping environments

 (defadvice LaTeX-indent-level-count
      (around advice-LaTeX-indent-level-count activate)
    (let* ((dont-indent-bracket (member (LaTeX-current-environment)
                                        '("song" "verse" "chorus")))
           (LaTeX-begin-regexp (if dont-indent-bracket
                                   "begin\\b"
                                 "begin\\b\\|\\["))
           (LaTeX-end-regexp (if dont-indent-bracket
                                 "end\\b"
                               "end\\b\\|\\]")))
      ad-do-it))

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.