2

I would like to show citations in text in the order I add them and in the reference table in alphabetical order. I have tried \newrefcontext but I get an error. Is there any other solution?

Here is the code:

\documentclass{article}
\usepackage[backend=bibtex,maxbibnames=5,maxcitenames=2,style=authoryear,citestyle=authoryear-comp,sorting=nyt,natbib=true,firstinits=true]{biblatex}

\begin{filecontents}{name.bib} @book{denhartog_mechanical_1956, title = {Mechanical {{Vibrations}}, {{Fourth Edition}}}, author = {Den Hartog, J. P}, year = {1956}, publisher = {{McGraw-Hill}} } @book{clough_dynamics_1975, title = {Dynamics of {{Structures}}}, author = {Clough, Ray W. and Penzien, Joseph}, year = {1975}, publisher = {{McGraw-Hill}} } \end{filecontents}

\addbibresource{name.bib} \begin{document} \section*{Body} Citations \autocite[e.g.,][]{denhartog_mechanical_1956,clough_dynamics_1975}.

\printbibliography[heading=bibintoc,title={References}]

\end{document}

Here is the result:

enter image description here

The reference table is fine but the citation order in the text is wrong. If I use sorting=none then I get the opposite result.

moewe
  • 175,683
jsp13
  • 23

1 Answers1

1

You want the option sortcites=false, to stop biblatex from sorting your citations. The option sortcites is set to true by (cite)style=authoryear-comp, because the -comp feature of the style only works well if the citations are sorted in a useful order.

There is no need for refcontexts here, which is good, because BibTeX doesn't really support them.

\documentclass{article}
\usepackage[backend=bibtex,
  style=authoryear-comp,
  sortcites=false,
  maxbibnames=5,maxcitenames=2,
  giveninits=true,
  natbib=true,
]{biblatex}

\begin{filecontents}{\jobname.bib} @book{denhartog_mechanical_1956, title = {Mechanical Vibrations}, author = {Den Hartog, J. P}, year = {1956}, publisher = {McGraw-Hill}, edition = {4}, } @book{clough_dynamics_1975, title = {Dynamics of Structures}, author = {Clough, Ray W. and Penzien, Joseph}, year = {1975}, publisher = {McGraw-Hill}, } \end{filecontents} \addbibresource{\jobname.bib}

\begin{document} Citations \autocite[e.g.,][]{denhartog_mechanical_1956,clough_dynamics_1975}.

\printbibliography[heading=bibintoc] \end{document}

Citations (e.g., Den Hartog, 1956; Clough and Penzien, 1975).

Note that I replaced style=authoryear,citestyle=authoryear-comp, with the shorter but equivalent

style=authoryear-comp,

I also removed the sorting=nyt, because that is already implied by the style.

The option firstinits is now called giveninits.

With the article class the default English bibliography heading is "References", so there is no need for ,title={References} in the \printbibliography call options.

You may want to consider switching from backend=bibtex, to backend=biber,. With BibTeX you can only use a limited subset of biblatex features, the full set of features is only available with Biber. In theory the switch should be as easy as replacing backend=bibtex, with backend=biber, and then running Biber instead of BibTeX in the compilation cycle (or telling your editor to run Biber instead of BibTeX, see Biblatex with Biber: Configuring my editor to avoid undefined citations).

moewe
  • 175,683