1

The RAE is the institution that ensures the stability of the Spanish language. They have a norm that states that when making citations inside parenthesis, the publication year of the cited item must be in square brackets, like in:

This citation (according to Knuth[1986])

How can I create a citation command that employs brackets instead of parentheses? I must use the apacite citation management package.

Here my MWE, that does not work as needed.

\documentclass{article}

\usepackage{filecontents}

\usepackage[natbibapa]{apacite}

\begin{filecontents}{\jobname.bib}
  @book{Knu86,
    author = {Knuth, Donald E.},
    year = 1986,
    title = {The {\TeX{ book},
  }}}
\end{filecontents}

% \cite using square brackets:
\newcommand{\citesb}[1]{%
    \renewcommand{\BBOP}{[}%
    \renewcommand{\BBCP}{]}%
    \cite{#1}
}

\begin{document}
\section{Demonstration}
This citation (according to \cite{Knu86}).
% It should print:
% This citation (according to Knuth(1986)).

This citation (according to \citesb{Knu86}).
% It should print:
% This citation (according to Knuth[1986]).

This citation (according to \cite{Knu86}).
% It should print:
% This citation (according to Knuth(1986)).

\bibliographystyle{apacite}
\bibliography{\jobname}
% It should print
% Knuth, D. E. (1986). The TEX book, .
\end{document}

Here a picture of the current behaviour of my MWE:

enter image description here

2
  • Is omitting the parentheses/brackets around the year field an option?
    – Mico
    Commented Jul 17, 2023 at 18:38
  • No, the Spanish style does not allow it. Commented Jul 17, 2023 at 22:33

2 Answers 2

1

I found it a bit odd that you had to use \!\! in your answer to cancel some unwanted space. Indeed there is an unprotected space in the definition of \setcitestyle.

Instead of fixing the lengthy definition of \setcitestyle I'd like to offer the following solution that changes the brackets only locally (so that there is no need to "switch back" to round brackets).

\documentclass{article}
\usepackage[natbibapa]{apacite}

\makeatletter
\newcommand*{\mkciteusesquarebrackets}{%
  \renewcommand\NAT@open{[}%
  \renewcommand\NAT@close{]}}

\newcommand{\citepb}[2][]{{\mkciteusesquarebrackets\citep[#1]{#2}}}
\newcommand{\citetb}[2][]{{\mkciteusesquarebrackets\citet[#1]{#2}}}
\makeatother


\begin{filecontents}{\jobname.bib}
@book{Knu86,
  author = {Knuth, Donald E.},
  year   = 1986,
  title  = {The {\TeX}book},
}
\end{filecontents}

\begin{document}
\section{Demonstration}
This citation (according to \citep{Knu86}).

This citation (according to \citepb{Knu86}).

This citation (according to \citet{Knu86}).

This citation (according to \citetb{Knu86}).

This citation (according to \citep[section 10]{Knu86}).

This citation (according to \citepb[section 10]{Knu86}).

This citation (according to \citet[section 10]{Knu86}).

This citation (according to \citetb[section 10]{Knu86}).

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

This citation (according to (Knuth, 1986)).
This citation (according to [Knuth, 1986]).
This citation (according to Knuth (1986)).
This citation (according to Knuth [1986]).
This citation (according to (Knuth, 1986, section 10)).
This citation (according to [Knuth, 1986, section 10]).
This citation (according to Knuth (1986, section 10)).
This citation (according to Knuth [1986, section 10]).

Note that I did not define a \citeb since natbib recommends to use only \citet and \citep and avoid \cite. See for example \citet vs \cite using natbib and cite and citep do the same thing for the acmart package.


Just for fun, here is a solution for biblatex that uses that biblatex automatically tracks parentheses if you use its own commands instead of literal ( and ).

\documentclass{article}
\usepackage[backend=biber, style=apa]{biblatex}
\addbibresource{biblatex-examples.bib}

\begin{document}
\section{Demonstration}
This citation \mkbibparens{according to \parencite{sigfridsson}}.

This citation \mkbibparens{according to \parencite{sigfridsson}}.

This citation \mkbibparens{according to \textcite{sigfridsson}}.

This citation \mkbibparens{according to \textcite{sigfridsson}}.

This citation \mkbibparens{according to \parencite[section 10]{sigfridsson}}.

This citation \mkbibparens{according to \parencite[section 10]{sigfridsson}}.

This citation \mkbibparens{according to \textcite[section 10]{sigfridsson}}.

This citation \mkbibparens{according to \textcite[section 10]{sigfridsson}}.

\printbibliography
\end{document}

This citation (according to [Sigfridsson & Ryde, 1998]).
This citation (according to [Sigfridsson & Ryde, 1998]).
This citation (according to Sigfridsson and Ryde [1998]).
This citation (according to Sigfridsson and Ryde [1998]).
This citation (according to [Sigfridsson & Ryde, 1998, section 10]).
This citation (according to [Sigfridsson & Ryde, 1998, section 10]).
This citation (according to Sigfridsson and Ryde [1998, section 10]).
This citation (according to Sigfridsson and Ryde [1998, section 10]).

1
1

I solved my own question with the following code:

\documentclass{article}
\usepackage{parskip}

\usepackage{filecontents}

\usepackage[natbibapa]{apacite}

\begin{filecontents}{\jobname.bib}
  @book{Knu86,
    author = {Knuth, Donald E.},
    year = 1986,
    title = {The {\TeX{ book},
  }}}
\end{filecontents}

\newcommand{\citeb}[2][]{\!\!\setcitestyle{square}\citet[#1]{#2}\setcitestyle{round}\!\!}
\newcommand{\citepb}[2][]{\!\!\setcitestyle{square}\citep[#1]{#2}\setcitestyle{round}\!\!}
\newcommand{\citetb}[2][]{\!\!\setcitestyle{square}\citet[#1]{#2}\setcitestyle{round}\!\!}

\begin{document}
\section{Demonstration}
This citation (according to \citeb{Knu86}).

This citation (according to \citep{Knu86}).

This citation (according to \citepb{Knu86}).

This citation (according to \citet{Knu86}).

This citation (according to \citetb{Knu86}).

This citation (according to \citeb[section 10]{Knu86}).

This citation (according to \citep[section 10]{Knu86}).

This citation (according to \citepb[section 10]{Knu86}).

This citation (according to \citet[section 10]{Knu86}).

This citation (according to \citetb[section 10]{Knu86}).

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

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .