RAE 是确保西班牙语稳定性的机构。他们有规范规定在括号内引用时,所引用项目的出版年份必须放在方括号中,例如:
此引文(根据 Knuth[1986])
如何创建使用方括号而不是圆括号的引用命令?我必须使用apacite
引用管理包。
这是我的 MWE,它不能按需要工作。
\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}
下面是我当前 MWE 行为的图片:
答案1
我觉得有点奇怪,你必须\!\!
使用您的答案取消一些不需要的空间。 确实, 的定义中有一个不受保护的空间\setcitestyle
。
我不会修改冗长的定义,而是\setcitestyle
提供以下解决方案,仅在局部更改括号(这样就不需要“切换回”圆括号)。
\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}
请注意,我没有定义,\citeb
因为natbib
建议仅使用\citet
和\citep
并避免\cite
。例如,参见\citet 与 \cite 使用 natbib和cite 和 citep 对 acmart 包做同样的事情。
只是为了好玩,这里有一个解决方案,如果您使用它自己的命令而不是文字和,biblatex
它会自动跟踪括号。biblatex
(
)
\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}
答案2
我使用以下代码解决了我自己的问题:
\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}