2

I added this command to reference sections (figures, chapters, etc.):

\newcommand{\secref}[1]{Section~\ref{#1}}

Now TeXstudio autocomplete shows me

enter image description here

but I am missing the autocompletion for the actual sections. Like in the autocomplete for \ref{.... Is this possible?

A not so nice solution would bt to skip the \ref command

\newcommand{\secref}[1]{Section~#1}

and then go for example \secref{\ref{sec:setup}}.

5

Instead of reinventing the wheel, I would rather use cleveref. This will automatically insert the appropriate names of the referenced labels as well as supported by texstudios auto-complete.

For example in the following document

\documentclass{article}

\usepackage[capitalise, noabbrev]{cleveref}

\begin{document}

\section{test}
\label{sec:test}

\begin{figure}
\caption{bla}\label{fig:bla}
\end{figure}

\cref{fig:bla} \cref{sec:test}

\end{document}

Texstudio will prompt

enter image description here

and the output will be

enter image description here

2

EDIT: This does not answer the question, as stated in the comments. In this answer, I explain how to add macros in texstudio, so that the cursor jumps to a specific location in that macro. A wholly different matter, indeed.


Original answer

Although I agree with samcarter, for the sake of completeness, there is a way to do the thing you originally wanted in texstudio.

Go to [Macros > Edit macros ...] Then create a new macro, give it a name, an abbreviation (not required and quite useless imho) and a trigger (good design is important for the triggers). In the code section, you would add

 \secref{%|section%|}

Save and close. In your editor window, type the trigger and the trigger text will automatically be replaced by the macro code \secref{section} with the focus of the curser select the word section in the braces, ready to be edited.

enter image description here

As you can see, I abuse of this function. (There's a lot of crap in the picture, as I was testing what was useful to me and I haven't cleaned up the mess, yet.)


btw, I use a space at the beginning and at the end of most of my triggers to prevent texstudio to convert "normal text" to some macro. E. g. the macro ml without the spaces would be really annoying, as any word containing the sequence 'ml' would get a macro right in the middle of it! If I was typing Umlaut without looking, I would get U\SI{aut and the rest of the text in the braces,}{\ml} which doesn't make sense at all. You can do much more with the triggers and the macros, just click on the ? next to the word "Trigger" and try for yourself.

  • 1
    Are you sure this would make the labels for the sections appear in the autocomplete box? If not, this does not answer the question. – Troy Feb 27 '18 at 21:45
  • This does not answer the question. I misunderstood the question, as I now realize! It zeemz zomewon wass standing on ze leadership readwithastrongGermanaccent – thymaro Feb 27 '18 at 22:05
  • Ok, no worries. I would suggest you delete the 'answer', however, lest someone else gets confused by this. – Troy Feb 27 '18 at 22:08
  • Interresting anyway, did not knew that! – Finn Feb 28 '18 at 12:56

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.