[Tex/LaTex] Texstudio \begin{subfigure} unrecognized command

subcaptionsubfloatstexstudio

I'm using the subcaption package to make subfigures in my document like so:

\usepackage{caption}
\usepackage{subcaption}

\begin{document}

\begin{figure}[ht]
\begin{subfigure}[b]{0.45\textwidth}
    \includegraphics[width=\textwidth]{images/1.png}
    \caption{Subcap1}
    \label{fig:1}
\end{subfigure}
\begin{subfigure}[b]{0.45\textwidth}
    \includegraphics[width=\textwidth]{images/2.png} 
    \caption{Subcap2}
    \label{fig:2}
\end{subfigure}
\caption{Cap}
\label{fig:3}
\end{figure}

\end{document}

This compiles fine, but in the texstudio editor, the \begin{subfigure} and \end{subfigure} are highlighted as "unrecognized command". I have tried activating the caption, subcaption, subfig and subfigure cwl files at Options > Completion but this doesn't remove the highlight.

While this doesn't affect the compiling, it is rather annoying. Am I missing something or incorrectly using the packages?

Best Answer

Save this as subcaptionTemp.cwl in ~/.config/texstudio/ or %APPDATA%\texstudio\!

# manipulated the auto-generated subcaption.cwl for Holt
# subcaption package
# Axel Sommerfeldt 04/16/2013
# URL: http://mirror.switch.ch/ftp/mirror/tex/help/Catalogue/entries/subcaption.html

#include:caption
#
#
# Chapter 1 Loading the package
#
#
\captionsetup[sub]{%<options%>}
#keyvals:\captionsetup
margin=%<num%>pt
margin={%<left amount%>,%<right amount%>}
margin*=%<num%>pt
margin*={%<left amount%>,%<right amount%>}
font=#scriptsize,footnotesize,small,normalsize,large,Large,normalfont,up,it,sl,sc,md,bf,rm,sf,tt,singlespacing,onehalfspacing,doublespacing,{strech=%<amount%>},normalcolor,{color=%<colour%>},normal
font+=#scriptsize,footnotesize,small,normalsize,large,Large,normalfont,up,it,sl,sc,md,bf,rm,sf,tt,singlespacing,onehalfspacing,doublespacing,{strech=%<amount%>},normalcolor,{color=%<colour%>},normal
font={%<option 1%>,%<option 2%>}
labelfont=#scriptsize,footnotesize,small,normalsize,large,Large,normalfont,up,it,sl,sc,md,bf,rm,sf,tt,singlespacing,onehalfspacing,doublespacing,{strech=%<amount%>},normalcolor,{color=%<colour%>},normal
labelfont+=#scriptsize,footnotesize,small,normalsize,large,Large,normalfont,up,it,sl,sc,md,bf,rm,sf,tt,singlespacing,onehalfspacing,doublespacing,{strech=%<amount%>},normalcolor,{color=%<colour%>},normal
labelfont={%<option 1%>,%<option 2%>}
textfont=#scriptsize,footnotesize,small,normalsize,large,Large,normalfont,up,it,sl,sc,md,bf,rm,sf,tt,singlespacing,onehalfspacing,doublespacing,{strech=%<amount%>},normalcolor,{color=%<colour%>},normal
textfont+=#scriptsize,footnotesize,small,normalsize,large,Large,normalfont,up,it,sl,sc,md,bf,rm,sf,tt,singlespacing,onehalfspacing,doublespacing,{strech=%<amount%>},normalcolor,{color=%<colour%>},normal
textfont={%<option 1%>,%<option 2%>}
labelformat=#default,empty,parens,simple,brace
labelsep=#none,period,space,quad,colon,newline,endash
skip=%<num%>pt
list=#false,true,no
hypcap=#false,true
indention=%<amount%>pt
position=#auto,top,above,bottom,below
#endkeyvals
#
#
# Chapter 2 The \subcaption command
#
#
\subcaption{heading}#/minipage
\subcaption[list entry]{heading}#/minipage
\subcaption*{heading}#/minipage
\setcaptionsubtype#S
\setcaptionsubtype*#S
#
#
# Chapter 3 The subfigure & subtable environments    
#
#
\begin{subfigure}{width}
# pos can be b (default: )
\begin{subfigure}[pos]{width}
\begin{subtable}{width}
\begin{subtable}[pos]{width}
\end{subfigure}
\end{subtable}
\captin@For{subtyelist}#S
#
#
# Chapter 4 The \subcaptionbox command
#
#
# inner-pos can be c, l, r, s (default: c)
\subcaptionbox[list entry]{heading}[width][inner-pos]{contents}
\subcaptionbox[list entry]{heading}[width]{contents}
\subcaptionbox[list entry]{heading}{contents}
\subcaptionbox{heading}[width][inner-pos]{contents}
\subcaptionbox{heading}[width]{contents}
\subcaptionbox{heading}{contents}
\subcaptionbox*{heading}[width][inner-pos]{contents}
\subcaptionbox*{heading}[width]{contents}
\subcaptionbox*{heading}{contents}
#
#
# Chapter 5 The \DeclareCaptionSubType command
#
#
# numbering-pos can be arabic, roman, Roman, alph, Alph, fnsymbol... (defaul: alph)
\DeclareCaptionSubType[numbering scheme]{float type}#*d
\DeclareCaptionSubType{float type}#*d
\DeclareCaptionSubType*[numbering scheme]{float type}#*d
\DeclareCaptionSubType{float type}#*d
#
#
# Chapter 6 References
#
#
\thesubfigure#S
\thesubtable#S
\p@subfigure#S
\p@subtable#S
\subref{key}#*r
\subref*{key}#*r
#keyvals:\captionsetup
subrefformat=#parens
#endkeyvals
\phantomsubcaption
# other commands
\subfigureautorefname#S
\subfigurename#S
\subtableautorefname#S
\subtablename#S
\theHsubfigure#S
\theHsubtable#S

Then go to your preferences and load this file:

enter image description here


I would be happy for any feedback. If this works nicely for you, I will submit it to the maintainers of TXS.