Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions autoload/vimtex/fold/envs.vim
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,15 @@ function! s:folder.text(line, level) abort dict " {{{1

" Set caption/label based on type of environment
if env ==# 'frame'
let option = ''
let label = ''
let caption = self.parse_caption_frame(a:line)
elseif env ==# 'table'
elseif env ==# 'table' || env ==# 'figure'
let option = ''
let label = self.parse_label()
let caption = self.parse_caption_table(a:line)
else
let option = matchstr(a:line, '\[.*\]')
let label = self.parse_label()
let caption = self.parse_caption(a:line)
endif
Expand Down Expand Up @@ -103,7 +106,7 @@ function! s:folder.text(line, level) abort dict " {{{1
if strlen(env) > width_env - 8
let env = strpart(env, 0, width_env - 11) . '...'
endif
let env = '\begin{' . env . '}'
let env = '\begin{' . env . '}' . option

let title = printf('%*S%-*S %-*S %*S',
\ width_ind, '',
Expand Down
72 changes: 72 additions & 0 deletions test/test-folding/test-env-options.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
\documentclass{memoir}

\begin{document}

\section{test1}
\label{sec:test1}

% The fold for the definition below should contain the environment, the options, and the label:
%\begin{defn}[Definition1] (defn:definition_1)
\begin{defn}[Definition 1]
\label{defn:definition_1}
A simple environment with simple contents.
\end{defn}

Filler text

% The fold for the figure below should contain the environment, NOT the options, the caption, and the label:
%\begin{figure} Simple figure (fig:simple_theorem)
\begin{figure}[ht] % A standalone figure with label and caption
\centering
% \input{proof}
\caption{Simple figure}
\label{fig:simple_figure}
\end{figure}

Filler text

\subsection{subtests 1}
\label{sub:subtests_1}

These tests feature nesting.

% The fold for the theorem below should contain the environment, the options, and the label:
%\begin{thm}[Example Title of Theorem] (thm:example_title_of_theorem)
\begin{thm}[Example Title of Theorem]
\label{thm:example_title_of_theorem}
Suppose A and B.

\begin{itemize}
\item If C, then D
\item \(A \wedge B \implies D \iff A \wedge B \implies C\)
\end{itemize}

We demonstrate this by the figure.
% The fold for the figure below should contain the environment, NOT the options, the caption, and the label:
%\begin{figure} A visual proof of the Example Theorem (fig:visual_theorem)
\begin{figure}[ht] % Comment
\centering
% \input{proof}
\caption{A visual proof of Example Theorem}
\label{fig:visual_theorem}
\end{figure}

\end{thm}

Filler text

% If one has an unusual case of captioning in a nonstandard environment (i.e. not figure or table), the following conflict may occur:
% \begin{defn}[Definition 2] A caption for an environment typically without caption % (defn:defini
\begin{defn}[Definition 2]
\label{defn:definition_2}
A sample definition.

\caption{A caption for an environment typically without caption}
\end{defn}
% The proper folding should be:
% \begin{defn}[Definition 2] A caption for an environment typically without caption % (defn:definition)

% However, the spacing in the envs.vim folding mechanisms does not account for the spacing of both the options and the caption, and so the label is incorrectly fit within the fold.


\end{document}