Automatically suggest arguments for user defined commands

When using the command \ref{ it automatically suggests several arguments, such as eqn:equation1, fig:figure1, and so on.

I have defined the command \newcommand{\fref}[1]{Fig. \ref{#1}}, which rather simply puts Fig. in front of the reference number.

Is there any way to make \fref{ automatically suggest arguments, as \ref{ does? Ideally, it would only suggest arguments that begin with fig:.

This is for TexStudio, which controls this (as far as I know).

• What you are describing sounds like a function of your editor and not of LaTeX. – Steven B. Segletes Apr 14 '15 at 18:10
• @StevenB.Segletes Yeah, now what you mention it. Edited the question. – Mauvai Apr 14 '15 at 18:15
• Unrelated: the definition should be \newcommand{\fref}[1]{Fig.~\ref{#1}} in order to avoid page breaks between Fig. and the corresponding number. BTW: there's also packages like cleveref which you might want to consider tex.stackexchange.com/q/36295/5049 – clemens Apr 15 '15 at 9:14

So you want \fref to behave like a regular \ref command. TXS infers the semantics of a command from .cwl files. See the FAQ and the manual.

• create a file user.cwl in your settings directory with the content \fref{label}#r
• open TeXstudio and check user.cwl at Options -> Completion.
• Yes! that does exactly what I want, thank you! From reading the manual there doesn't seem to any way to limit the possible labels that come up, such as only the ones beginning with eqn:. Is this correct? – Mauvai Apr 17 '15 at 13:29
• This is correct. Labels cannot be filtered. – Tim Hoffmann Jul 18 '16 at 20:56

In TexStudio you can define a macro which suits your interests: Defining New ShortCuts in TexStudio

and you can put a placeholder in it: How to put placeholder in macros in TexStudio

• This doesn't do what I want :-/ – Mauvai Apr 15 '15 at 19:58
• Sorry, so I must have misinterpreted your question. – jonathan.scholbach Apr 15 '15 at 22:18