Skip to content

Instantly share code, notes, and snippets.

@jmclawson
Last active June 16, 2021 16:03
Show Gist options
  • Save jmclawson/6b04d45ca5f5e05d021586b4da508760 to your computer and use it in GitHub Desktop.
Save jmclawson/6b04d45ca5f5e05d021586b4da508760 to your computer and use it in GitHub Desktop.
Introduce .bib-file data directly into Latex documentation using \bibcitem{citekey}
\usepackage{listings}
\usepackage{xcolor}
\let\oldaddbibresource\addbibresource
\renewcommand{\addbibresource}[1]{%
\oldaddbibresource{#1}%
\expandafter\newcommand\csname thebibfile\endcsname{#1}%
}
% \makeatletter
% \patchcmd{\lst@Init}{\par\penalty -50\relax}{\relax}
% \makeatother
% adapted from the impressive biblatex-sbl package
\lstdefinelanguage{BibTeX}{%
% keywordsprefix={@}%
keywords={%
@ancienttext,@article,@book,@bookinbook,@classictext,@collection,%
@commentary,@conferencepaper,@inbook,@incollection,@incommentary,%
@inlexicon,@inreference,@lexicon,@manual,@misc,@mlasource,@mvbook,%
@mvcollection,@mvcommentary,@mvlexicon,@mvreference,@online,@reference,%
@review,@seminarpaper,@series,@suppbook,@thesis,@unpublished
},
emph={%
addendum,address,author,bookauthor,bookeditor,booktitle,chapter,crossref,%
date,datea,doi,edition,editor,editora,editoratype,editorb,editorbtype,%
editorc,editorctype,editortype,entrysubtype,eprint,eprintclass,eprintdate,%
eprinttype,eventdate,eventtitle,institution,issue,issuetitle,journal,%
journaltitle,location,maineditor,maintitle,maintranslator,nameaddon,note,%
number,options,origdate,origlanguage,origlocation,origpublisher,origyear,%
pages,part,preface,publisher,publishera,pubstate,related,relatedoptions,%
relatedtype,revdauthor,revdeditor,revdtitle,series,seriesseries,%
shortauthor,shorthand,shortjournal,shortmaintitle,shortseries,shorttitle,%
sorttitle,subtitle,supplemental,title,titlea,titleaddon,titletype,%
translator,type,type,url,urldate,venue,version,versiona,versionb,volume,%
volumes,witheditor,witheditortype,withtranslator,withtranslatortype,xref,%
year%
},
sensitive=false,
breaklines=true,
breakatwhitespace=true,
morecomment=[l][basicstyle]{=\ \{}
}
\lstset{%
language=BibTeX,
backgroundcolor=\color{gray!5},
basicstyle=\ttfamily\small,
keywordstyle=\color{teal},
emphstyle=\color{purple}
}
\lstset{rangeprefix=\%\[\[\ ,% percent + double left square brace + space
rangesuffix=\ \]\]}% space + double right square bracket
\newcommand{\bibcitem}[1]{\lstinputlisting[linerange=#1-end,includerangemarker=false,breaklines=true,postbreak=\mbox{\textcolor{gray}{$\hookrightarrow$}\space} ]{\thebibfile}\nocite{#1}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment