0

I have to create something that looks like this:

\begin{frame}[fragile]{frame title}
  lorem ipsum ...
\end{frame}

Note that the portion [fragile] is optional. That is, if I enter some text in the $1 placeholder, it should include the brackets. If I don't enter text in the $1 placeholder, I don't want the brackets at all.

I'm not sure how to make the $1 placeholder optional. So far I've created this snippet, which does everything except the optional part.

snippet frame "frame environment" b
\begin{frame}[$1]{${2:frame title}}
  ${0:${VISUAL}}
\end{frame}
endsnippet

How can I make an optional placeholder that disappears when no text is given?

jlconlin
  • 14,206
  • 22
  • 72
  • 105

1 Answers1

1

Here is a very simple snippet that I think will explain the optional placeholder:

snippet \dc "Document Class" b
\documentclass${1:[${2:options}]}{${3:class}}
$0
endsnippet

Here is how it works:

  • Type \dc and press <tab>.
  • The \documentclass[options]{class} text will appear with [options] highlighted.
  • At this time you can either press <backspace> and delete the whole [options] part (including the square brackets) and press <C-j> (forward trigger keymap) to continue to the {class} placeholder and so on...
  • Or you can press <C-j> and proceed to change the [options] placeholder inside the square brackets. Then press <C-j> again to jump to the {class} placeholder and so on.
Gustavo Seidler
  • 2,011
  • 1
  • 14
  • 12