0

I frequently use the command \citeauthor{ME:paper} \cite{ME:paper}. Further, when one types \citeauthor{ or \cite{, a list of the loaded references appears; I can then type \cite{ME:p and hit enter to auto complete. (This happens in TeXstudio at least.) I would like to create a new command

\newcommand{\citeauthnum}[1]{\citeauthor{#1} \cite{#1}}

But doing this doesn't give me the auto complete options. (I tried Ctrl+Space but this doesn't load it.)

Even better, I'd be able to add an optional argument and write \cite[#2]{#1}.


It looks to me like this question is relevant: Where does TexStudio get its citation autocomplete list from?.

  • Any suggestions, anyone? :) – Sam T Jun 7 at 8:48
  • If you are using natbib the command \citeauthnum is basically \citet, if you use biblatex it is \textcite, so if you are lucky, you don't have to define a new command at all. – moewe Jun 8 at 6:32
  • \textcite is perfect, thank you! If you add that as an answer, I'll accept; I'm happy to do it too, but you should get the rep bonus! :) – Sam T Jun 8 at 15:21
1

If you are using biblatex with a numeric style, then \textcite should give you what you wrote \citeauthnum for. \textcite has the advantage of working properly with pre- and postnote and being able to handle multiple citations. In general I strongly recommend against creating new \...cite commands by putting two or more \...cite commands together in a \newcommand.

With natbib \citet would be what you are looking for.

Both of these commands are recognised as cite commands by TeXstudio and are auto-completed accordingly.


In case you really need to teach TeXstudio about a new \...cite command you'll want to add #c at the end of the command in the .cwl file

\citeauthnum{citekey}#c

That way TeXstudio will know to auto-complete it with the list of known cite keys.

0

add

\citeauthnum{citekey}

to user .cwl file.

If no user .cwl file yet, see https://tex.stackexchange.com/a/361283/190086

  • Thanks for your response, but unfortunately that hasn't worked. If I type \citeau then I see in the command autocomplete \citeauthor{citekey}, as I did before (except previously citekey was replaced with arg1, but basically no difference). However, I don't get the reference list autocomplete that I desire (see OP). See picture: i.stack.imgur.com/LKK1m.png – Sam T Jun 3 at 12:51
  • @SamT Did you try \citeauthnum{citekey}#c or \citeauthnum{bibid}#c? (Cf. github.com/texstudio-org/texstudio/blob/master/completion/…) – moewe Jun 8 at 6:37
  • Making that change has fixed it, thank you! As you pointed out above, though, there is actually an in-built – Sam T Jun 8 at 15:25

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.