1

I use a command that automatically generates labels to include pictures:

\newcommand{\plot}[3]{

    \begin{figure}[htp]
        \centering
        \includegraphics[#2]{Fig/#1}
        \caption{#3}
        \label{fig:#1}
    \end{figure}
}

How could I make texstudio autocomplete suggest the labels generated by the command?

I created a simple myDefs.cwl:

\plot{label}#l  
\figref{label}#r

Which works with:

\plot{abc}{width=\columnwidth}{caption}
\figref{abc}

but how could I make label "fig:abc" to appear among suggestions to keep figures separate?

  • You can create a custom .cwl file and specify what the auto completion should suggest. See texstudio.sourceforge.net/manual/current/… for details. – user36296 Nov 6 '17 at 11:58
  • note that you should not use \center (that is the internal form of \begin{center} it should be \centering also [h!] is usually wrong and latex will generate a warning and change it to [ht] but in most cases [htp] is better (not including p makes it far more likely that the figure goes to the end of the document) – David Carlisle Nov 6 '17 at 12:29
  • Thanks for reference and suggestions! How could one issue a label different from arg1 for auto-completion though? – Vladimir Kazei Nov 6 '17 at 15:03
2

This is not possible. There is no way to complete to strings other than the ones given as the label argument.

I suggest to use explicit labels everywhere. This is also more clear to the reader.

\plot{fig:abc}{width=\columnwidth}{caption}
\figref{fig:abc}

And since you'll have completion then, it's not too much effort.

  • Thanks, but how to use file "abc", if the argument of plot is "fig:abc" in that case? – Vladimir Kazei Nov 9 '17 at 6:26
  • There`s no easy solution. Either have two explicit arguments for label and filename, or use the same name for label and filename. – Tim Hoffmann Nov 9 '17 at 9:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.