3

This is related to this Emacs.SE question.

I use the code from the answer:

(setq LaTeX-begin-regexp "\\(?:begin\\|if@\\)\\b")
(setq LaTeX-end-regexp "\\(?:end\\|else\\|fi\\)\\b")
(defun LaTeX-indent-level-count ()
  "Count indentation change caused by all \\left, \\right, \\begin, and
\\end commands in the current line."
  (save-excursion
    (save-restriction
      (let ((count 0))
        (narrow-to-region (point)
                          (save-excursion
                            (re-search-forward
                             (concat "[^" TeX-esc "]"
                                     "\\(" LaTeX-indent-comment-start-regexp
                                     "\\)\\|\n\\|\\'"))
                            (backward-char)
                            (point)))
        (while (search-forward TeX-esc nil t)
          (cond
            ((looking-at "left\\b")
             (setq count (+ count LaTeX-left-right-indent-level)))
            ((looking-at "right\\b")
             (setq count (- count LaTeX-left-right-indent-level)))
            ((looking-at LaTeX-begin-regexp)
             (setq count (+ count LaTeX-indent-level)))
            ((looking-at "else\\b"))
            ((looking-at LaTeX-end-regexp)
             (setq count (- count LaTeX-indent-level)))
            ((looking-at (regexp-quote TeX-esc))
             (forward-char 1))))
        count))))

But instead of getting this indentation:

\ifx\condition
  \dosomething
\else
  \dosomethingelse
\fi

I do get

\ifx\condition
  \dosomething
  \else
  \dosomethingelse
\fi

Hoe to get the \else in line with \if and \fi?

  • What happens if you change if@ into ifx, i.e., (setq LaTeX-begin-regexp "\\(?:begin\\|ifx\\)\\b") and try it again? – Arash Esbati Jan 21 '20 at 22:08

Your Answer

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

Browse other questions tagged or ask your own question.