1

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?.

Sam OT
  • 1,329
  • Any suggestions, anyone? :) – Sam OT Jun 07 '19 at 08: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 08 '19 at 06: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 OT Jun 08 '19 at 15:21

2 Answers2

2

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.

moewe
  • 175,683
1

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: https://i.stack.imgur.com/LKK1m.png – Sam OT Jun 03 '19 at 12:51
  • @SamT Did you try \citeauthnum{citekey}#c or \citeauthnum{bibid}#c? (Cf. https://github.com/texstudio-org/texstudio/blob/master/completion/biblatex.cwl) – moewe Jun 08 '19 at 06:37
  • Making that change has fixed it, thank you! As you pointed out above, though, there is actually an in-built – Sam OT Jun 08 '19 at 15:25