1

Here is an MWE for a document I'm working on, based on code from here, modified with some titlesec options. My goal is to get the references title to appear as a runin title as in all the other sections.

\documentclass{article}
\usepackage[style=nature,backend=bibtex,maxnames=1,uniquelist=false]{biblatex}
\usepackage[colorlinks]{hyperref}

% Some field suppression via options
\ExecuteBibliographyOptions{isbn=false,url=false,doi=false,eprint=false}

% One-paragraph bibliography environment
\defbibenvironment{bibliography}
  {\list
     {\printtext[labelnumberwidth]{%
        \printfield{prefixnumber}%
        \printfield{labelnumber}}%
      \ifentrytype{article}{% Suppress remaining fields/names/lists here
        \clearfield{title}}{}}
     {\setlength{\leftmargin}{0pt}%
      \setlength{\topsep}{0pt}}%
      \renewcommand*{\makelabel}[1]{##1}}
  {\endlist}
  {\mkbibitem}

% \mkbibitem just prints item label and non-breakable space
\makeatletter
\newcommand{\mkbibitem}{\@itemlabel\addnbspace}
\makeatother

% Add breakable space between bibliography items
\renewcommand*{\finentrypunct}{\addperiod\space}

% et al. string upright (nature style applies \mkbibemph)
\renewbibmacro*{name:andothers}{%
  \ifboolexpr{
    test {\ifnumequal{\value{listcount}}{\value{liststop}}}
    and
    test \ifmorenames
  }
    {\ifnumgreater{\value{liststop}}{1}{\finalandcomma}{}%
     \andothersdelim
     \bibstring{andothers}}
    {}}

\addbibresource{biblatex-examples.bib}
\usepackage{titlesec}
\titlespacing{\section}{0pt}{3pt plus 3pt minus 3pt}{6pt plus 3pt minus 3pt}
\titlespacing{\subsection}{0pt}{0pt plus 0pt minus 0pt}{6pt plus 3pt minus 3pt}
\titlespacing{\subsubsection}{0pt}{0pt plus 0pt minus 0pt}{6pt plus 3pt minus 3pt}
\titleformat{\section}[runin]
    {\normalfont\bfseries\large}
    {\S\ \thesection.}{0.0cm}{}[:]
\titleformat{\subsection}[runin]
    {\normalfont\bfseries\small}
    {\S\ \thesubsection.}{0.0cm}{}[:]
\titleformat{\subsubsection}[runin]
    {\normalfont\bfseries\small}
    {\S\ \thesection.}{0.0cm}{}[.]
\titleformat{\bibliography}[runin]
    {\normalfont\bfseries}
    {\S\ \thebibliography.}{0.0cm}{}[:]


\begin{document}
\section*{Section title}
Filler text \parencite{bertram,glashow,aksin}.
\printbibliography
\section*{Section title}
Filler text.
\end{document}

Condensed Bib. MWE

As you can see, I tried to apply some titlesec options to make this work, but haven't been able to.

1 Answer 1

1

In biblatex, \printbibliography starts a list, and lists cause a line break even with your section definition (you can check that using itemize after a \section command).

I suggest you use the following redefinition of the bibliography environment which does not start a list, but just a normal paragraph.

\defbibenvironment{bibliography}
  {}
  {\unspace}
  {\printtext[labelnumberwidth]{%
     \printfield{prefixnumber}%
     \printfield{labelnumber}}%
   \addspace}

As in Removing Line Breaks in Bibliography compiled with Biblatex

If you want to delete the titles for @articles the more idiomatic solution would be

\AtEveryBibitem{%
  \ifentrytype{article}
    {\clearfield{title}}
    {}%
}

MWE

\documentclass{article}
\usepackage[style=nature,backend=bibtex,maxnames=1,uniquelist=false]{biblatex}
\usepackage[colorlinks]{hyperref}

\ExecuteBibliographyOptions{isbn=false,url=false,doi=false,eprint=false}

\defbibenvironment{bibliography}
  {}
  {\unspace}
  {\printtext[labelnumberwidth]{%
     \printfield{prefixnumber}%
     \printfield{labelnumber}}%
   \addspace}

\AtEveryBibitem{%
  \ifentrytype{article}
    {\clearfield{title}}
    {}%
}

\renewcommand*{\finentrypunct}{\addperiod\space}

\renewbibmacro*{name:andothers}{%
  \ifboolexpr{
    test {\ifnumequal{\value{listcount}}{\value{liststop}}}
    and
    test \ifmorenames
  }
    {\ifnumgreater{\value{liststop}}{1}{\finalandcomma}{}%
     \andothersdelim
     \bibstring{andothers}}
    {}}

\addbibresource{biblatex-examples.bib}
\usepackage{titlesec}
\titlespacing{\section}{0pt}{3pt plus 3pt minus 3pt}{6pt plus 3pt minus 3pt}
\titleformat{\section}[runin]
    {\normalfont\bfseries\large}
    {\S\ \thesection.}{0.0cm}{}[:]


\begin{document}
\section*{Section title}
Filler text \parencite{bertram,glashow,aksin}.
\printbibliography
\end{document}
4
  • I got what I needed with by adding ` \ifentrytype{article}{% Suppress remaining fields/names/lists here \clearfield{title}}{}` back in. Thanks! edit: Apparently you can't code-format in comments.
    – Mark
    Commented Oct 22, 2015 at 15:37
  • @Mark Have a look at the extended answer. I would not add the \ifentrytype{article} directly into the \defbibenvironment{bibliography}, the hook \AtEveryBibitem is normally used to achieve such a thing.
    – moewe
    Commented Oct 23, 2015 at 7:25
  • Is this just a convention/good practice thing? I'm not a programmer, at least not a real one, so I usually get confused pretty quickly when people start talking about 'hook' and things like that.
    – Mark
    Commented Oct 23, 2015 at 13:38
  • @Mark It is the way I usually do it and see it done. Of course you might put the code into \defbibenvironment{bibliography} if you feel more comfortable with that, but if you have a look at questions on this site where people ask about getting rid of fields in the bibliography the solution almost always employs \AtEveryBibitem.
    – moewe
    Commented Oct 23, 2015 at 13:42

You must log in to answer this question.

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