[Tex/LaTex] Update the default autocompletion of `itemize` in TeXStudio

auto-completiontexstudio

I want to change the auto-completion of itemize from

\begin{itemize}
content ...
\end{itemize}

to

\begin{itemize}
  \item content...
  \item content...
  \item content...
\end{itemize}

However, I tried to find the latex-document.cwl, latex-mathsymbols.cwl, and tex.cwl (which are the defaults autocomplete files) with no luck.

So, how can I make TeXStudio to change the autocomplete behavior of this specific macro?

Best Answer

Here's a potential solution using user macros.

From the menu, select Macros -> Edit macros. Add a new macro called "Itemize selection" and paste the following for the macro code:

%SCRIPT
sel=cursor.selectedText().split('\n')
out="\\begin{itemize}\n"
for (line in sel){
    out += '\t\\item ' + sel[line] + '\n'
}
out += "\\end{itemize}"

cursor.replaceSelectedText(out)

Now click OK to save. Select the text in the editor that you wish to put into an itemize environment and select "Itemize selection" from the Macros menu.

Here's the result on some text.

First sentence.
Second sentence.
Third sentence.

to give

\begin{itemize}
    \item First sentence.
    \item Second sentence.
    \item Third sentence.
\end{itemize}
Related Question