0

I'm using the caption package in TexStudio, and it correctly highlights the various parts of the \caption command, but it does no such thing for the \captionof command. So I'm trying to write a custom .cwl for \captionof. This command takes three fields:

\captionof{floattype}[tocentry]{caption}

So a typical usage would be something like this:

\captionof{figure}[A Roman banquet]{A Roman banquet as depicted by John the Painter. Note the lack of spices and the limited selection of beverages.}

The floattype field can be at least figure or table. I assume there are more possibilities, but I haven't had the need for them. The tocentryfield is a short caption for the TOC, and the caption field is a full caption. Both are text fields, obviously.

With the \caption command, Tex Studio highlights the caption field according to its configuration, making it easy to find, and allowing it to be spell checked.

So I would like to do the same with the .cwl entry for \captionof. I've tried \captionof#S, copying the autogenerated .cwl entry for \caption in caption3.cwl, but it does nothing. I've tried \captionof{floattype}[short]{title} following latex-document.cwl's entry for \caption, but this didn't work, either. I've also tried to define the different fields following the manual, and I came up with \captionof{floattype}[TOCentry%text]{caption%text} and captionof{floattype}[TOCentry%text]{caption%title}, but these also do nothing.

Could anyone give me a hand crafting a proper .cwl entry for \captionof?

I'm using TexStudio 4.2.3 with TexLive 2021. TexStudio detects my custom .cwl file, and I've selected it to autoload in the configuration.

EDIT: In the screenshot is the result of implementing the suggestion to add \captionof{float type}[list entry%text]{heading%title} to custom .cwl file. "This is a long caption" should be highlighted in purple, but is not.

Result after implementing suggestion to add \captionof{float type}[list entry%text]{heading%title} to custom .cwl file. "This is a long caption" should be highlighted in purple, but is not.

5
  • 1
    What kind of highlighting are you looking for? The built-in file caption.cwl already has listing for \captionof (see here github.com/texstudio-org/texstudio/blob/master/completion/…).
    – mbert
    Aug 7, 2022 at 4:27
  • @mbert I'm looking to have the second and third fields of \captionof highlighted just as they are with the \caption command. The caption.cwl file you mentioned is already recognized and loaded by TexStudio, but it doesn't cause any highlighting to occur. I added the three \captionof lines it contains to my custom cwl file, and this also does nothing. Aug 7, 2022 at 4:55
  • 1
    Unless I'm missing something the only difference between \caption and \captionof highlighting is that the TOCentry argument is spellchecked in the former but not the latter (the second braced arg of \captionof should still be spellchecked). If that's what you want then you can add \captionof{float type}[list entry%text]{heading%text} to your custom cwl.
    – mbert
    Aug 7, 2022 at 5:07
  • @mbert The %text suggestion got spell checking working. However, I've replaced heading%text with heading%title in order to get this field highlighted just like section names, and nothing happens. Any idea why? Aug 7, 2022 at 5:36
  • 1
    texstudio's completer is reading multiple lines defining the highlighting and has to pick one. Apparently %text has higher priority than %title. If you want this then copy caption.cwl, change the \captionof lines to have %title, and place it in the .../texstudio/completion/user directory.
    – mbert
    Aug 7, 2022 at 5:50

1 Answer 1

1

Add \captionof{float type}[list entry%text]{heading%text} to your custom cwl. This will enable spellchecking in the "list entry" argument.

1
  • Your suggestion contained the proper code. I changed heading%textto heading%title to get the highlighting I wanted. To get it to actually work, I went into TexStudio's configuration, deactivated the built-in caption.cwl in the Completion section, and activated my own version of this file, which included your suggestion. This won't work with custom.cwl because it will exclude all of the caption.cwl file's contents except the suggested change. Cheers! Aug 7, 2022 at 15:22

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .