One paragraph style bibliography with numbers

I am writing a document that has a two page limit. I am trying to find a way to make it so that each citation in the bibliography does not start on a new line. This would be sufficient to fit into my page limit.

I am using natbib and bibtex with the "super" (nature-style) citation option. I tried a version of the solution presented in

One paragraph style bibliography

to get this behavior. It works fine when used with author-year style citations, but produces awkward indentation when used with the super (numeric) option (see non-uniform spacing between entries below):

Does anyone know how to configure things so that the entries in the bibliography look flush like this:

but with the dots replaced by the numbers used to refer to each reference in the text?

Thanks!

EDIT:

I invoke natbib with:

\usepackage[super,sort&compress]{natbib}

Then call:

\bibliographystyle{apj_w_etal_3auth}

\usepackage{paralist}

\renewenvironment{thebibliography}[1]{%
\textsc{\textbf{References:}}
\let\par\relax\let\newblock\relax%
\inparaitem[{[}1{]}]}{\endinparaitem}


And here is the style file:

https://gist.github.com/dannygoldstein/b8f77d3e4853ec983209aa8850898fb2

NB that this is a slightly modified version of https://github.com/keflavich/tex_compact_bib. I deleted the "SORT" commands from the original bst file to get the citations to appear non-alphabetically.

• Please provide us the complete source code which does not produce your intended results. That gives us more time to experiment and find the solution for you rather than typing all the codes from scratch. And welcome to TeX.SE. – Masroor Mar 7 '18 at 6:05
• I just edited it. Hopefully that clarifies things... – user3001196 Mar 7 '18 at 15:22

Solution in Brief

The \hfil in the arguments of \items which actually render the bibitems is responsible for the horizontal white spaces.

Rendering of bibitems is done by the \@lbibitem command. So, we need to redefine it. One way for this will be to use \renewcommand. But definitely, a smarter way will be to use \patchcmd.

\usepackage{etoolbox}
\makeatletter
\patchcmd{\@lbibitem}{\item[\hfil\NAT@anchor{#2}{\NAT@num}]}{\item[\NAT@anchor{#2}{\NAT@num}]}{}{}
\makeatother


The Full Code

\documentclass{article}

\bibliographystyle{apj_w_etal_3auth}

\usepackage[super,sort&compress]{natbib}

\usepackage{paralist}

\renewenvironment{thebibliography}[1]{%
\textsc{\textbf{References:}}
\let\par\relax\let\newblock\relax%
\inparaitem[{[}1{]}]}{\endinparaitem}

\usepackage{times}

\usepackage{etoolbox}
\makeatletter
\patchcmd{\@lbibitem}{\item[\hfil\NAT@anchor{#2}{\NAT@num}]}{\item[\NAT@anchor{#2}{\NAT@num}]}{}{}
\makeatother

\usepackage{filecontents}

\begin{filecontents}{\jobname.bib}
@article{einstein,
author =       "Albert Einstein",
title =        "{Zur Elektrodynamik bewegter K{\"o}rper}. ({German})
[{On} the electrodynamics of moving bodies]",
journal =      "Annalen der Physik",
volume =       "322",
number =       "10",
pages =        "891--921",
year =         "1905",
DOI =          "http://dx.doi.org/10.1002/andp.19053221004"
}

@book{latexcompanion,
author    = "Michel Goossens and Frank Mittelbach and Alexander Samarin",
title     = "The \LaTeX\ Companion",
year      = "1993",
}

@article{belloche2014detection,
title={Detection of a branched alkyl molecule in the interstellar medium: iso-propyl cyanide},
author={Belloche, Arnaud and Garrod, Robin T and M{\"u}ller, Holger SP and Menten, Karl M},
journal={Science},
volume={345},
number={6204},
pages={1584--1587},
year={2014},
publisher={American Association for the Advancement of Science}
}

@article{mcnally1989anxiety,
title={Is anxiety sensitivity distinguishable from trait anxiety? Reply to Lilienfeld, Jacob, and Turner (1989).},
author={McNally, Richard J},
year={1989},
publisher={American Psychological Association}
}

\end{filecontents}

\begin{document}

\nocite{*}

\bibliography{\jobname}

% \show\bibitem

% \makeatletter
% \show\@lbibitem
% \makeatother

\end{document}


The Output

The Sleuthing Activity

An inspection of the .bbl file shows that each bibliographic entry is rendered by a \bibitem.

So, we issue a \show\bibitem inside our source. This gives:

\bibitem=\long macro: ->\@ifnextchar [{\@lbibitem }{\@lbibitem []}.

We delve deeper and look inside \@lbibitem.

\makeatletter
\show\@lbibitem
\makeatother


gives:

\@lbibitem=macro:
[#1]#2->\if \relax \@extra@b@citeb \relax \else \@ifundefined {br@#2\@extra@b@c
iteb }{}{\@namedef {br@#2}{\@nameuse {br@#2\@extra@b@citeb }}}\fi \@ifundefined
{b@#2\@extra@b@citeb }{\def \NAT@num {}}{\NAT@parse {#2}}\def \NAT@tmp {#1}\ex
pandafter \let \expandafter \bibitemOpen \csname NAT@b@open@#2\endcsname \expan
dafter \let \expandafter \bibitemShut \csname NAT@b@shut@#2\endcsname \@ifnum {
\NAT@merge >\@ne }{\NAT@bibitem@first@sw {\@firstoftwo }{\@ifundefined {NAT@b*@
#2}{\@firstoftwo }{\expandafter \def \expandafter \NAT@num \expandafter {\the \
c@NAT@ctr }\@secondoftwo }}}{\@firstoftwo }{\global \advance \c@NAT@ctr \@ne \@
ifx {\NAT@tmp \@empty }{\@firstoftwo }{\@secondoftwo }{\expandafter \def \expan
dafter \NAT@num \expandafter {\the \c@NAT@ctr }\global \NAT@stdbsttrue }{}\bibi
tem@fin \item [\hfil \NAT@anchor {#2}{\NAT@num }]\global \let \NAT@bibitem@firs
t@sw \@secondoftwo \NAT@bibitem@init }{\NAT@anchor {#2}{}\NAT@bibitem@cont \bib
item@fin }\@ifx {\NAT@tmp \@empty }{\NAT@wrout {\the \c@NAT@ctr }{}{}{}{#2}}{\e
xpandafter \NAT@ifcmd \NAT@tmp (@)(@)\@nil {#2}}.


Which, I must say, is a mouthful and somewhat difficult to perceive. So, we open the natbib.sty file in an editor and search for \@lbibitem.

The subsequent lines show how the bibliographic entry is being rendered. The line,

\item[\hfil\NAT@anchor{#2}{\NAT@num}]


raises our suspicion and tweaking with this confirms that we have hit the right point.

If you want to know more about \patchcmd, please take a look at this wonderful answer.