5

I am having an issue that randomly occurs while citing references.

When I type " \cite{ " in my file a list of references usually pops up and I can select any reference by selecting them, as such: \cite

However when I type " \citet " or " \citep ", this list does not appear most of the time. But the references appear on my PDF file as intended.

\citep

Moreover, after I manually type in the cite key and change \cite to \citep or \citet as required they become black and look like this:

Several times I have noticed that \citet and \citep both behave like \cite, however these occurences are random and I can not reproduce them. I am using \bibliographystyle{apalike}.

The editor I use is TeXstudio 2.12.10.

I am wondering if anyone can help me solve this. Many thanks for your help.

Mico
  • 506,678
J. Doe
  • 137
  • 2
    Hi, welcome. This lookup is a feature of whatever editor you're using, so you need to tell us which editor that is. – Torbjørn T. Sep 30 '18 at 12:34
  • The red highligting of \citet could also suggest that your editor does not recognise the command. If a command is not recognised by your editor it is natural to assume that the editor will not recognise that command as a citation command and will not display the cite-autcomplete list. Note that your editors failure to recognise the command has no bearing on LaTeX's recognising the command (or not recognising the command): Only the error messages in the .log file after running LaTeX are relevant for that. The behaviour is editor-dependent, so we need to know what editor you use. – moewe Sep 30 '18 at 12:42
  • @TorbjørnT. Many thanks for your reply. I am using TeXstudio 2.12.10. Hope this helps. – J. Doe Sep 30 '18 at 14:03
  • There is a deleted answer to another question which might be helpful for your problem: https://i.stack.imgur.com/zgwjm.png (from https://tex.stackexchange.com/a/116171/36296) Short summary: make sure command completion for natbib is activated, if this does not help you can create your own .cwl file. – samcarter_is_at_topanswers.xyz Sep 30 '18 at 14:33
  • @samcarter Thanks so much! That helped. I activated natbib.cwl and everything is working fine now. Thanks. – J. Doe Sep 30 '18 at 15:03

1 Answers1

7

Your problem is perfectly answered by an (unfortunately) deleted answer by @Chris. As you cannot yet see deleted answers, I'll quote it here in a community wiki post:

I think that your problem is that texstudio will not autocomplete citekeys when you use commands other than \cite? If you want to add \citep to the commands that are linked to your bibliography then you need to provide some extra information to texstudio.

From the manual, you need to create a .cwl file that lists the autocomplete macros. Create a file in ~/.config/texstudio called MacroList.cwl for example. Add \citep{keylist} to that file. Then in texstudio, select Options->Configure->Completion and select the file you just created. When you use \citep it should now provide a list of citekeys from your bibliography. It worked for me, anyway.

EDIT

I just realised that citep is part of natbib, which has a predefined cwl file. In the list of cwl files (in the Completion tab of the Configure window), select the natbib.cwl file. Then, all of the macros defined by natbib should be set up correctly.