[Tex/LaTex] Define a bibliography environment

biblatex

I'm trying to have two different styles for two different bibliographies in a same document using biblatex. I'm using the keyword procedure two create those two bibliography and I found a way to define a new bibenvironement with the command \defbibenvironment and then use the command \printbibliography[env=newenvrionment, keyword=blabla].

I'm using the authoryear style for the main bibliography so I'm using those options when I charge the package:

\usepackage[language=auto,backend=biber,sorting=nyt,bibstyle=authoryear,citestyle=authortitle-icomp]{biblatex}

The propose if to define a "primary sources" environment, similar to the first one but instead of showing:

author (year) title, in journal,

I want to have:

journal (year) title, author.

I am very new in using biblatex and I don't understand how to do such a thing by using \defbibenvironment.

Otherwise, if there is another solution to use here is a compilable MWE:

\documentclass[a4paper,12pt]{book}




\usepackage[utf8]{inputenc}
\usepackage{xcolor}
\usepackage[main=french,english]{babel}
\usepackage{csquotes}
\usepackage[T1]{fontenc}
\usepackage[pdftex]{graphicx}
\usepackage[top=2.5cm, bottom=2.5cm, right=2cm, left=2cm, headheight = 20pt]{geometry}
\usepackage{pifont}
\usepackage{xspace}
\usepackage{setspace}
\usepackage{mathptmx}
\usepackage{parskip}
\usepackage{titlesec}
\usepackage[titletoc]{appendix}
\usepackage[hidelinks]{hyperref}
\usepackage{tocloft}
\usepackage{calc}
\usepackage{tocbibind}
\usepackage[vskip=0pt]{quoting}
\usepackage{pdfpages}



\usepackage[language=auto,backend=biber,sorting=nyt,bibstyle=authoryear,citestyle=authortitle-icomp]{biblatex}


%citer le titre du journal pour les citations 
\DeclareCiteCommand{\citejournal}
  {\usebibmacro{prenote}}
  {\usebibmacro{citeindex}%
    \usebibmacro{journal}
     \usebibmacro{date}
       \usebibmacro{title}}
  {\multicitedelim}
  {\usebibmacro{postnote}}

\DeclareCiteCommand{\footcitejournal}[\mkbibfootnote]
  {\usebibmacro{prenote}}
  {\usebibmacro{citeindex}%
    \usebibmacro{journal}
     \usebibmacro{date}
       \usebibmacro{title}}
  {\multicitedelim}
  {\usebibmacro{postnote}}  

\DeclareCiteCommand{\citerevue}
  {\usebibmacro{prenote}}
  {\usebibmacro{citeindex}%
    \usebibmacro{title}
     \usebibmacro{journal+issuetitle}
     \usebibmacro{date}}
  {\multicitedelim}
  {\usebibmacro{postnote}}

\DeclareCiteCommand{\footciterevue}[\mkbibfootnote]
  {\usebibmacro{prenote}}
  {\usebibmacro{citeindex}%
    \usebibmacro{title}
     \usebibmacro{journal+issuetitle}
     \usebibmacro{date}}
  {\multicitedelim}
  {\usebibmacro{postnote}}  


% Put editor string in parentheses
\DeclareFieldFormat{editortype}{\mkbibparens{#1}}

% Obtenir le nom de l'éditeur pour les @incollection entre le 'in' et le titre
\renewbibmacro*{in:}{%
  \printtext{\bibstring{in}\intitlepunct}%
 \ifentrytype{article}{}{}%
 \ifentrytype{incollection}{%
  \ifnameundef{bookauthor}
    {\ifnameundef{editor}
       {\printnames{translator}%
        \setunit{\addcomma\space}%
        \usebibmacro{translator+othersstrg}%
        \clearname{translator}}
       {\printnames{editor}%
        \setunit{\addcomma\space}%
        \usebibmacro{editor+othersstrg}%
        \clearname{editor}}}
    {\ifnamesequal{author}{bookauthor}
       {}
       {\printnames{bookauthor}%
        \clearname{bookauthor}}}}%
  \newunit\newblock}

% mettre entre parenthèses le numéro de la revue dans un volume en comportant plusieurs 
 \renewbibmacro*{volume+number+eid}{%
  \printfield{volume}%
  \setunit*{\addnbspace}% 
  \printfield{number}%
  \setunit{\addcomma\space}%
  \printfield{eid}}
\DeclareFieldFormat[article]{number}{\mkbibparens{#1}}



\renewbibmacro*{date}{\printdate}

\DeclareCiteCommand{\citejournal}
      {\usebibmacro{prenote}}
      {\usebibmacro{citeindex}%
        \usebibmacro{journal}
        \setunit{\addspace} % space delimiter
        \usebibmacro{date}
        \setunit{\addspace} % space delimiter
           \usebibmacro{title}}
      {\multicitedelim}
      {\usebibmacro{postnote}}


\defbibenvironment{nolabelbib}%this is the bib envirionment I found in the other topic 
  {\list
     {}
     {\setlength{\leftmargin}{\bibhang}%
      \setlength{\itemindent}{-\leftmargin}%
      \setlength{\itemsep}{\bibitemsep}%
      \setlength{\parsep}{\bibparsep}}}
  {\endlist}
  {\item}


\usepackage{filecontents}

\begin{filecontents}{\jobname.bib}
@article{test,
  author = {Author, A.},
  date = {2011-06-12},
  title = {Some relevant article},
  journal = {Test journal},
  keywords = {primaires_articles},
},

@incollection{mhone_crossroads_1992,
     title = {The Political Economy of Malawi - An Overview},
     chapter = {1},
     author = {Guy Mhone},
     year = {1992},
     booktitle = {Malawi At The Crossroads. The Post-Colonial Political Economy},
     publisher = {\textsc{SAPES} Books},
     address = {Harare},
     pages = {1--34},
     keywords = {malawi_histoire},
},

@article{momba_peasant_1985,
author = {Momba, Jotham C.},
title = {Peasant differentiation and rural party politics in colonial Zambia},
journal = {Journal of Southern African Studies},
volume = {11},
number = {2},
pages = {281-294},
year = {1985},
keywords = {malawi_histoire},
},


\end{filecontents}

\bibliography{\jobname}

\begin{document}

Some text~\citejournal{test}.\\




Some other\cite{momba_peasant_1985}\\

and other\cite{mhone_crossroads_1992}

\printbibliography[keyword=malawi_histoire,heading=subbibliography,title={Malawi: histoire sociale}]

\printbibliography[env=nolabelbib, keyword=primaires_articles,heading=subbibliography,title={Artiles de presse et revues}]

\end{document}

I want the second bibliography to be with the journal (date) title environment. It's using only articles.

Best Answer

As I wrote in the comment it's not possible to use a bibenvironment for your purpose, since bibenvironments are ment to format the bibliography list.

Also biblatex doesn't provide an implemented solution to mix different bibliography styles (as far as I know), so you have to try to find a way on your own to achieve what you want.

My solution:

  1. Choose a default bibliography style (authoryear in your case)
  2. Create drivers and macros which will differ from the default bibliography style (bibdriver for article and author-macro in your case)
  3. Create and implement a toggle, with which you can switch between the default bibliography style and your new macros.

This solution will (adapted) also work for more than 2 bibliography styles.

However, the weak point is, you have to take care of every difference to your default bibliography style – and in the case you want to change your default bibliography style you have to start over...


Here is your updated and commented MWE. I've deleted a lot of unnecessary (for our issue) macros / packages. It should show you the idea of my solution.

In addition to the MWE you may modify the new macros and also set up a sorting option in the \printbibliography command etc.

\documentclass[a4paper,12pt]{book}

\usepackage[utf8]{inputenc}
\usepackage[main=french,english]{babel}
\usepackage{csquotes}
\usepackage[T1]{fontenc}
\usepackage[top=2.5cm, bottom=2.5cm, right=2cm, left=2cm, headheight = 20pt]{geometry}
\usepackage{xspace}
\usepackage{setspace}
\usepackage[hidelinks]{hyperref}
\usepackage[language=auto,backend=biber,sorting=nyt,bibstyle=authoryear,citestyle=authortitle-icomp]{biblatex}

\usepackage{etoolbox}%added


\usepackage{filecontents}

\begin{filecontents}{\jobname.bib}
@article{test,
  author = {Author, A.},
  date = {2011-06-12},
  title = {Some relevant article},
  journal = {Test journal},
  keywords = {primaires_articles},
},

@incollection{mhone_crossroads_1992,
     title = {The Political Economy of Malawi - An Overview},
     chapter = {1},
     author = {Guy Mhone},
     year = {1992},
     booktitle = {Malawi At The Crossroads. The Post-Colonial Political Economy},
     publisher = {\textsc{SAPES} Books},
     address = {Harare},
     pages = {1--34},
     keywords = {malawi_histoire},
},

@article{momba_peasant_1985,
author = {Momba, Jotham C.},
title = {Peasant differentiation and rural party politics in colonial Zambia},
journal = {Journal of Southern African Studies},
volume = {11},
number = {2},
pages = {281-294},
year = {1985},
keywords = {malawi_histoire},
},


\end{filecontents}


%new toggle
\newtoggle{blx@bibdriver@article:journalyear}%new toggle to set which driver is to use
\togglefalse{blx@bibdriver@article:journalyear}


% Put editor string in parentheses
\DeclareFieldFormat{editortype}{\mkbibparens{#1}}

% Obtenir le nom de l'éditeur pour les @incollection entre le 'in' et le titre
\renewbibmacro*{in:}{%
  \printtext{\bibstring{in}\intitlepunct}%
 \ifentrytype{article}{}{}%
 \ifentrytype{incollection}{%
  \ifnameundef{bookauthor}
    {\ifnameundef{editor}
       {\printnames{translator}%
        \setunit{\addcomma\space}%
        \usebibmacro{translator+othersstrg}%
        \clearname{translator}}
       {\printnames{editor}%
        \setunit{\addcomma\space}%
        \usebibmacro{editor+othersstrg}%
        \clearname{editor}}}
    {\ifnamesequal{author}{bookauthor}
       {}
       {\printnames{bookauthor}%
        \clearname{bookauthor}}}}%
  \newunit\newblock}

% mettre entre parenthèses le numéro de la revue dans un volume en comportant plusieurs 
 \renewbibmacro*{volume+number+eid}{%
  \printfield{volume}%
  \setunit*{\addnbspace}% 
  \printfield{number}%
  \setunit{\addcomma\space}%
  \printfield{eid}}
\DeclareFieldFormat[article]{number}{\mkbibparens{#1}}


%redefine author-macro so it only prints the year in the default bibdriver
\renewbibmacro*{author}{%also modified
  \ifboolexpr{
    test \ifuseauthor
    and
    not test {\ifnameundef{author}}
  }
    {\usebibmacro{bbx:dashcheck}
       {\bibnamedash}
       {\usebibmacro{bbx:savehash}%
        \printnames{author}%
        \iffieldundef{authortype}
          {\setunit{\addspace}}
          {\setunit{\addcomma\space}}}%
     \iffieldundef{authortype}
       {}
       {\usebibmacro{authorstrg}%
        \setunit{\addspace}}}%
    {\global\undef\bbx@lasthash
     \usebibmacro{labeltitle}%
     \setunit*{\addspace}}%
  \iftoggle{blx@bibdriver@article:journalyear}{}{%added
  \usebibmacro{date+extrayear}}}%modified

%new bibdriver for article in the second bibliography
\newbibmacro*{article:journalyear}{%modified bibdriver for article
  \usebibmacro{bibindex}%
  \usebibmacro{begentry}%
  \usebibmacro{journal+issuetitle}%
  \newunit
  \usebibmacro{date+extrayear}
  \newunit
  \usebibmacro{title}%
  \newunit
  \usebibmacro{author/translator+others}%
  \newunit
  \usebibmacro{note+pages}%
  \setunit{\bibpagerefpunct}\newblock
  \usebibmacro{pageref}%
  \newunit\newblock
  \iftoggle{bbx:related}
    {\usebibmacro{related:init}%
     \usebibmacro{related}}
    {}%
  \usebibmacro{finentry}}


%redeclare the existing bibdriver for article
\DeclareBibliographyDriver{article}{%from standard.bbx
\iftoggle{blx@bibdriver@article:journalyear}{\usebibmacro{article:journalyear}}{%added
  \usebibmacro{bibindex}%
  \usebibmacro{begentry}%
  \usebibmacro{author/translator+others}%
  \setunit{\labelnamepunct}\newblock
  \usebibmacro{title}%
  \newunit
  \printlist{language}%
  \newunit\newblock
  \usebibmacro{byauthor}%
  \newunit\newblock
  \usebibmacro{bytranslator+others}%
  \newunit\newblock
  \printfield{version}%
  \newunit\newblock
  \usebibmacro{in:}%
  \usebibmacro{journal+issuetitle}%
  \newunit
  \usebibmacro{byeditor+others}%
  \newunit
  \usebibmacro{note+pages}%
  \newunit\newblock
  \iftoggle{bbx:isbn}
    {\printfield{issn}}
    {}%
  \newunit\newblock
  \usebibmacro{doi+eprint+url}%
  \newunit\newblock
  \usebibmacro{addendum+pubstate}%
  \setunit{\bibpagerefpunct}\newblock
  \usebibmacro{pageref}%
  \newunit\newblock
  \iftoggle{bbx:related}
    {\usebibmacro{related:init}%
     \usebibmacro{related}}
    {}%
  \usebibmacro{finentry}}
}



\bibliography{\jobname}


\begin{document}

\nocite{*}

\printbibliography[keyword=malawi_histoire,heading=subbibliography,title={Malawi: histoire sociale}]

\toggletrue{blx@bibdriver@article:journalyear}

\printbibliography[keyword=primaires_articles,heading=subbibliography,title={Artiles de presse et revues}]

\printbibliography[type=article,heading=subbibliography,title={All articles}]

\end{document}


OUTPUT:

enter image description here

Related Question