태그 보관물: auctex

auctex

LaTeX / AUCTeX에서 항목을 들여 쓰기하는 방법은 환경을 항목 화합니까? 라인의 원하는

Q : LaTeX itemize환경 의 “적절한”들여 쓰기를 어떻게 얻을 수 auctex있습니까?

여기 환경 item에서 함께하고 싶은 곳 이 itemize있습니다.

  • \item 선은 환경의 시작과 관련하여 두 칸 들여 쓰기
  • 항목의 연속 줄은 줄에 대해 추가로 두 칸 들여 쓰기 \item됩니다.

이것이 내가보고 / 기대하는 것입니다 :

\begin{itemize}
  \item Here's a really long item in a LaTeX itemize environment;
    note how the *initial* item line is indented two spaces, and the
    continuation lines are indented another two spaces.
\end{itemize}

LaTeX-item-indent변수 를 사용하여 항목의 초기 들여 쓰기를 조정할 수 있습니다 -2. 기본값은 입니다. 이 기본으로, 나는의 바람직하지 않은 행동을 얻을 \item들여 쓰기되지 않는,하지만 내가 추가로 두 개의 공백에 의해 상쇄되는 연속 라인의 원하는 동작을 얻을 :

\begin{itemize}
\item Here's a really long item in a LaTeX itemize environment;
  note how the *initial* item line is *NOT* indented two spaces,
  but the continuation lines are indented two spaces.
\end{itemize}

줄에 원하는 들여 쓰기 (두 공백) LaTeX-item-indent0얻 도록 설정 \item했지만 연속 줄의 원하는 동작의 두 번째 절반이 추가 두 공백으로 오프셋 되지는 않습니다 .

\begin{itemize}
  \item Here's a really long item in a LaTeX itemize environment;
  note how the *initial* item line is indented two spaces, but the
  continuation lines are *NOT* indented an additional two spaces.
\end{itemize}

그래서 하나 얻을 않는 방법을 모두 원하는 행동을 :

  • \item두 줄 의 처음 들여 쓰기
  • 연속 선에 추가로 두 칸이 들여 쓰기 되었습니까?

(참고 관련 SO 스레드 .)



답변

@sykora의 의견 (setq LaTeX-item-indent -2 LaTeX-indent-level 4)은 거의 있지만, 다른 모든 환경에도 영향을 미칩니다 . 예를 들어, 우리는 또한

\begin{abstract}
    This indents to the 4th column, which is way too far!
\end{abstract}

다음 함수는 Tassilo Horn 의 오래된 코드 스 니펫을 만듭니다. 중첩 된 환경을 포함하여 들여 쓰기가 정확합니다. 그것은 작동 itemize, enumeratedescription부팅, 환경 :

(defun LaTeX-indent-item ()
  "Provide proper indentation for LaTeX \"itemize\",\"enumerate\", and
\"description\" environments.

  \"\\item\" is indented `LaTeX-indent-level' spaces relative to
  the the beginning of the environment.

  Continuation lines are indented either twice
  `LaTeX-indent-level', or `LaTeX-indent-level-item-continuation'
  if the latter is bound."
  (save-match-data
    (let* ((offset LaTeX-indent-level)
           (contin (or (and (boundp 'LaTeX-indent-level-item-continuation)
                            LaTeX-indent-level-item-continuation)
                       (* 2 LaTeX-indent-level)))
           (re-beg "\\\\begin{")
           (re-end "\\\\end{")
           (re-env "\\(itemize\\|\\enumerate\\|description\\)")
           (indent (save-excursion
                     (when (looking-at (concat re-beg re-env "}"))
                       (end-of-line))
                     (LaTeX-find-matching-begin)
                     (current-column))))
      (cond ((looking-at (concat re-beg re-env "}"))
             (or (save-excursion
                   (beginning-of-line)
                   (ignore-errors
                     (LaTeX-find-matching-begin)
                     (+ (current-column)
                        (if (looking-at (concat re-beg re-env "}"))
                            contin
                          offset))))
                 indent))
             ((looking-at (concat re-end re-env "}"))
              indent)
            ((looking-at "\\\\item")
             (+ offset indent))
            (t
             (+ contin indent))))))

(defcustom LaTeX-indent-level-item-continuation 4
  "*Indentation of continuation lines for items in itemize-like
environments."
  :group 'LaTeX-indentation
  :type 'integer)

(eval-after-load "latex"
  '(setq LaTeX-indent-environment-list
         (nconc '(("itemize" LaTeX-indent-item)
                  ("enumerate" LaTeX-indent-item)
                  ("description" LaTeX-indent-item))
                LaTeX-indent-environment-list)))

나는 내가 놓친 매우 간단한 설정이 있다고 생각할 수는 없지만 이것이 Rube Goldberg 버전입니다. 아직도, 그것은 작동하고 그것은 몇 년 동안 가려움증을 긁 습니다 .

편집 : @ sykora의 의견에 따라 하드 코딩을 꺼내기 위해 기능을 수정했습니다. \items는 이제 들여 쓰기 LaTeX-indent-level공간입니다. 연속 선은 새로운 변수의 값을, 수 LaTeX-indent-level-item-continuation당신이 후자의 두 배 값을 바인딩하지 않으려는 경우, 또는 LaTeX-indent-level.

그것이 일어날 때, 결합하고 LaTeX-indent-level-item-continuation8로 설정 하면 미적으로 좋은 결과를 얻을 수 있습니다. 나는 그것으로 전환 할 수도 있습니다 :

\begin{itemize}
  \item Example with LaTeX-indent-level-item-continuation set to 8.
  \item Here's a really long item that will spill over onto the
        continuation line; text lines up pretty nicely this way!
        \begin{itemize}
          \item And here's a sub-item, with the environment
                indented to the relevant continuation line.
        \end{itemize}
\end{itemize}


답변