[Tex/LaTex] Use either square brackets or round parentheses with \cite

citingnatbib

I'd like to be able to choose either square brackets or round parentheses around the year of my citation call-outs, because my teacher wants to have square brackets only if the citation call-out is inside parentheses, and otherwise parentheses.

Example :
"We would like to cite Hock (1986), Antilla (1989) and Fox (1995) in this chapter (and Rankin [2003] and Ringe [2013]), […]"

Is there a way in doing this ?

Best Answer

Certainly a strange request by your teachers. I can only think of defining your own \cite command to use when you're inside a parenthesis.

I assume you would require the square versions less, so I pass a default round option to natbib, then define respective commands: \sqcitet and \sqcitep which are just wrappers to change (locally) the cite style.

\begin{filecontents}{\jobname.bib}
@ARTICLE{feyn54,
    title = {Testing},
    author = {R. P. Feynman},
    journal = {Phys. Rev.},
    year = {1954},
    volume = {94},
    pages = {262}
}
\end{filecontents}

\documentclass{article}
\usepackage[round]{natbib}

\makeatletter
\newcommand{\bianca}{\renewcommand\NAT@open{[}\renewcommand\NAT@close{]}}
\makeatother

\newcommand*\sqcitet[1]{{\bianca\citet{#1}}}
\newcommand*\sqcitep[1]{{\bianca\citep{#1}}}

\begin{document}    
    We would like to cite some in-line \citet{feyn54} and \citep{feyn54}, and of course in brackets as well:
    (with \sqcitet{feyn54} and \sqcitep{feyn54}) 

    We would like to cite some in-line \citet{feyn54} and \citep{feyn54}

    \bibliographystyle{plainnat}
    \bibliography{\jobname}
\end{document}

enter image description here

Extra Note

The documentation offers two ways to change the citation style, viz. (i) \setcitestyle{square} and (ii) creating a new \bibstyle@xxx and calling it with \citestyle{xxx}.

Method (i) is simple enough to implement, while implementation of Method (ii) can be seen in my previous edit of this answer. But..

The first method adds spurious spacings, while the second method sets the style globally. (and so both are unsatisfactory).

And so instead, I've gone for the option of explicitly setting the open and close parenthesis with \renewcommand\NAT@open{[} and \renewcommand\NAT@close{]} for the time being.