@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,enumerate和description环境,以启动:
(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-continuation为8可获得美观的结果。我什至可以切换到它:
\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}
LaTeX-indent-level将其设置为4,则您的第一种方法有效。项目将缩进为4-2 = 2,而连续行将缩进为4 = 2 +2。但是,这确实意味着文件中的所有其他环境都将缩进为4(而不是2),这可能是合乎要求的,也可能不是。我希望他们自己缩进2,这就是我遇到的问题。