1

Having been using Author-Year apa style for a while. However, the numeric style references-list seems neat.

The issue is that the numeric \citep{} only shows [number] in bracket. So I wonder how to twist the numeric citation style like:

\cite[Johnson:2013] ----> Johnson et al. [19] (\textcite{} can do this job)

\citep[Johnson:2013] ----> (Johnson et al. [19])

how to make a new command \textcitep{} to achieve 2nd style?

\usepackage[
  style=numeric,
  backend=biber,
  refsection=chapter,
  uniquename=true,
  uniquelist=false,
  maxcitenames=2, 
  natbib=true ]{biblatex} 
lockstep
  • 250,273
KOF
  • 5,019

2 Answers2

2

Here you are:

\documentclass{report}
\usepackage[
  style=numeric,
  backend=biber,
  refsection=chapter,
  uniquename=true,
  uniquelist=false,
  maxcitenames=2,
  natbib=true ]{biblatex}

\addbibresource{biblatex-examples.bib}
\newcommand\textcitep[1]{\mkbibparens{\textcite{#1}}}
\newcommand\textcitesp[1]{\mkbibparens{\textcites{#1}}}

\begin{document}

Text \textcitesp{knuth:ct:c, companion}. See also \textcitep{knuth:ct:d}

\printbibliography

\end{document} 

enter image description here

Bernard
  • 271,350
  • Note that this approach severely inhibits biblatex's pre- and postnote abilities (as well as the \textcites approach). – moewe May 25 '15 at 19:49
  • I didn't try to see if there were side effects, I must say. In simple cases it works… – Bernard May 25 '15 at 20:01
  • Definitely, I tried it the usual way via \DeclareCiteCommand (that is: steal the definition of the macro that comes closest and modify it). But \textcite in its numeric.cbx definition is quite convoluted and was stubborn when I added \mkbibparens at first. The problem with postnotes and the like is a typical problem of approaches where one has to give the arguments explicitly in a \newcommand. It would require some more code to "recode" the argument structure of the macro. – moewe May 25 '15 at 20:03
  • Thanks for the answer. \cite{} also works fine for the 1st style. can I redefine the \citep{} for 2nd style? – KOF May 26 '15 at 13:55
  • I guess so, but check for side-effects, just in case. \citep is more or less an alias for biblatex's native \parencite. – Bernard May 26 '15 at 14:10
  • I think I might have found a side-effect free solution with slightly more code, feel free to have a look and comment! – moewe Aug 03 '15 at 06:43
1

We can redefine \textcite(s) to be wrapped in parentheses (quite) easily by

\makeatletter
\DeclareCiteCommand{\cbx@textcite}[\mkbibparens]
  {\usebibmacro{textcite:init}}
  {\usebibmacro{citeindex}%
   \usebibmacro{textcite}}
  {}
  {\usebibmacro{textcite:postnote}}
\DeclareMultiCiteCommand{\cbx@textcites}[\mkbibparens]{\cbx@textcite}{}
\makeatother

If you want a new command \textcitep for that we will also have to copy some more definitions from numeric.cbx and adapt that. Then we need

\makeatletter
\DeclareCiteCommand{\cbx@textcitep}[\mkbibparens]
  {\usebibmacro{textcite:init}}
  {\usebibmacro{citeindex}%
   \usebibmacro{textcite}}
  {}
  {\usebibmacro{textcite:postnote}}
\DeclareMultiCiteCommand{\cbx@textciteps}[\mkbibparens]{\cbx@textcitep}{}
\DeclareCiteCommand{\textcitep}[\cbx@textcite@init\cbx@textcitep]
  {\gdef\cbx@savedkeys{}%
   \citetrackerfalse%
   \pagetrackerfalse%
   \DeferNextCitekeyHook%
   \usebibmacro{textcite:init}}
  {\ifthenelse{\iffirstcitekey\AND\value{multicitetotal}>0}
     {\protected@xappto\cbx@savedcites{()(\thefield{multipostnote})}%
      \global\clearfield{multipostnote}}
     {}%
   \xappto\cbx@savedkeys{\thefield{entrykey},}%
   \iffieldequals{namehash}{\cbx@lasthash}
     {}
     {\stepcounter{textcitetotal}%
      \savefield{namehash}{\cbx@lasthash}}}
  {}
  {\protected@xappto\cbx@savedcites{%
     [\thefield{prenote}][\thefield{postnote}]{\cbx@savedkeys}}}
\DeclareMultiCiteCommand{\textciteps}[\cbx@textcites@init\cbx@textciteps]{\textcitep}{}
\makeatother

to create a new \textcitep and a new multicite \textciteps.

MWE

\documentclass{article}
\usepackage[
  style=numeric,
  backend=biber,
  uniquename=true,
  uniquelist=false,
  maxcitenames=2,
  natbib=true ]{biblatex}

\addbibresource{biblatex-examples.bib}

\makeatletter
\DeclareCiteCommand{\cbx@textcitep}[\mkbibparens]
  {\usebibmacro{textcite:init}}
  {\usebibmacro{citeindex}%
   \usebibmacro{textcite}}
  {}
  {\usebibmacro{textcite:postnote}}
\DeclareMultiCiteCommand{\cbx@textciteps}[\mkbibparens]{\cbx@textcitep}{}
\DeclareCiteCommand{\textcitep}[\cbx@textcite@init\cbx@textcitep]
  {\gdef\cbx@savedkeys{}%
   \citetrackerfalse%
   \pagetrackerfalse%
   \DeferNextCitekeyHook%
   \usebibmacro{textcite:init}}
  {\ifthenelse{\iffirstcitekey\AND\value{multicitetotal}>0}
     {\protected@xappto\cbx@savedcites{()(\thefield{multipostnote})}%
      \global\clearfield{multipostnote}}
     {}%
   \xappto\cbx@savedkeys{\thefield{entrykey},}%
   \iffieldequals{namehash}{\cbx@lasthash}
     {}
     {\stepcounter{textcitetotal}%
      \savefield{namehash}{\cbx@lasthash}}}
  {}
  {\protected@xappto\cbx@savedcites{%
     [\thefield{prenote}][\thefield{postnote}]{\cbx@savedkeys}}}
\DeclareMultiCiteCommand{\textciteps}[\cbx@textcites@init\cbx@textciteps]{\textcitep}{}
\makeatother

\begin{document}
Text \textcites{knuth:ct:c, companion}. See also \textcite{knuth:ct:d}.

Text \textciteps{knuth:ct:c, companion}. See also \textcitep{knuth:ct:d}

\printbibliography
\end{document} 

enter image description here

moewe
  • 175,683
  • (+1) Wow! I wouldn't have been able to conceive such an involved code. – Bernard Aug 03 '15 at 09:54
  • @Bernard Neither was I, this is just a copy of the relevant stuff from numeric.cbx with a few ps and \mkbibparens thrown in... – moewe Aug 03 '15 at 10:13
  • That's the way I most often patch default formatting of biblatex: follow the Ariadne's thread of a bib driver and going back through the bibmacros involved. Looks very much like a trail game (not sure it's the right wording in English…) – Bernard Aug 03 '15 at 10:24