I created a new command like this:

\newcommand{\longref}[1]{{\ref{#1} (\nameref{#1})}}

it works as expected - it prints the chapter number and it's name. Great.

Now I'm using Texstudio, and it always showed me a list of available labels when I was typing in a \ref-command. With my own command, it doesn't do that anymore.

Is there any way I get auto-completion with my own command?

2 Answers 2


Probably too late for OP, but for the record:

To let TeXstudio know what type of fields your command contains, you have to tell it in a .cwl file, which is used for auto-completion.

Their default location is %appdata%\texstudio\completion\ or .config/texstudio/completion/.

For your own commands, you can create a file called something like mycmds.cwl in the user folder there and write the line


After restarting TeXstudio, the completion should work the way you want it to:

enter image description here

See also my answer here.


I use TexStudio and it is my favorite editor. I have not particularly tried what you are trying to do here, but here is what I have observed in the latest version of TexStudio. When you load a file in TexStudio, it tries to detect which the parent file is (specially if there are multiple files included in the document, for example, using subfiles package). What TexStudio does is that it also loads the resources within those files which you can access. For example, if you load \usepackage{biblatex} and the bibliography file \bibliography{ref.bib} in the preamble, you will get autocompletion suggestions of the references which are in the ref.bib file. So, if you start typing \textcite{ you will see a list of suggestions (most likely sorted alphabetically) from which you can choose the reference. I am guessing this is the feature you are looking for.

If that is the case, then I do not think custom commands will get the autocompletion feature based on how TexStudio works (at least from what I have seen). I could be wrong since this is just my observation but this is probably it. Hope that helps you understand your situation.

  • 1
    Thank you. Yes, I think I understand. I thought there would be kind of hacky way to declare the type of expected input...
    – Standard
    Commented Oct 2, 2020 at 9:39

You must log in to answer this question.

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