1

I have managed to get biblatex and biber to include a QR code for bibliography items that contain a URL -- like so:

\documentclass{scrartcl}

\begin{filecontents}[overwrite]{\jobname.bib} @book { texlive-home, shorthand = {TLD1}, author = {The TeX User Group}, title = {TeX Live}, note = {some text to make the entry appear more voluminous}, url = {https://www.tug.org/texlive/} } \end{filecontents}

\begin{filecontents}[overwrite]{biblatex.cfg} \DeclareFieldFormat [book] {url}{\par{\scriptsize\ttfamily\url{#1}}\par\vspace{1.5mm}\qrcode{#1}\vspace{3mm}} \end{filecontents}

\usepackage{qrcode} \usepackage[style=alphabetic]{biblatex} \appto{\biburlsetup}{\renewcommand*{\UrlFont}{\scriptsize\ttfamily}} \addbibresource{\jobname.bib}

\begin{document} \nocite{*} \printbibliography \end{document}

This works, but it wastes a lot of space:

example above

I would like for the QR code to be positioned to the right of the entry like so:

what I actually want, badly cut and glued together

Within a document I would probably use a simple tabular environment for this, but all I've managed to create are impressive error messages. Could anybody point me in the right direction?

vwegert
  • 2,875
  • Maybe the package hvqrurl is what you are looking for? – schtandard Jul 26 '22 at 09:30
  • See my previous answer here: https://tex.stackexchange.com/questions/622192/is-there-a-standard-way-of-associating-an-image-with-a-biblatex-entry/622199#622199

    It's easy to get images and other material into entries, and positioned

    – Aubrey Blumsohn Jul 26 '22 at 09:51
  • @AubreyBlumsohn In this case, I want to change the layout of the entire entry - wrap the existing text (which I'm mostly happy with) and place another element next to it. The fact that the thing I want to place to the right us a graphical element is mostly a coincidence. Unless I'm missing something entirely, your answer does not go into layouting a bib entry...? – vwegert Jul 26 '22 at 09:56
  • @schtandard Interesting idea, but if possible, I'd like to stay within the main text boundaries. The actual page is relatively narrow, and I can't easily increase the margin width to make the QR codes usable. Also, if the entries get too short, the QR codes will start to overlap. – vwegert Jul 26 '22 at 10:00

2 Answers2

2

You will have to adapt the sizes, but something like this should work.

\documentclass{scrartcl}

\usepackage{qrcode} \usepackage[style=alphabetic,url=false]{biblatex} \appto{\biburlsetup}{\renewcommand*{\UrlFont}{\scriptsize\ttfamily}} \addbibresource{biblatex-examples.bib} \usepackage{lipsum} \DeclareFieldFormat {qrurl}{\qrcode{#1}}

\renewbibmacro{begentry}{\makebox[0pt][l]{\hspace*{\linewidth}\quad\raisebox{\dimeval{-\height+\ht\strutbox}}[0pt][0pt]{\printfield[qrurl]{url}}}}

\defbibenvironment{bibliography} {\list {\printtext[labelalphawidth]{% \printfield{labelprefix}% \printfield{labelalpha}% \printfield{extraalpha}}} {\setlength{\labelwidth}{\labelalphawidth}% \setlength\rightmargin{3cm}% %<------- adapt ... \setlength{\leftmargin}{\labelwidth}% \setlength{\labelsep}{\biblabelsep}% \addtolength{\leftmargin}{\labelsep}% \setlength{\itemsep}{\bibitemsep}% \setlength{\parsep}{\bibparsep}}% \renewcommand*{\makelabel}[1]{##1\hss}} {\endlist} {\item}
\begin{document} \lipsum[1]

\cite{ctan,doody} \printbibliography \end{document}

enter image description here

Ulrike Fischer
  • 327,261
1

If you prefer a real tabular bibliography, you may want to have a look at biblatex-ext-tabular from my biblatex-ext bundle.

The advantage of using a table is that you'll always have enough space for the QR code.

\documentclass{scrartcl}

\usepackage{qrcode} \usepackage[style=alphabetic]{biblatex} \usepackage{biblatex-ext-tabular}

\usepackage{longtable} \usepackage{array} \newcolumntype{L}[1]{% >{\raggedright\let\newline\\arraybackslash\hspace{0pt}}p{#1}}

\DeclareFieldFormat{qrurl}{% \raisebox{\dimeval{-\height+\ht\strutbox}}{\qrcode{#1}}}

\defbibtabular{bibtabular} {\setlength{\LTpre}{0pt}% \setlength{\LTpost}{0pt}% \renewcommand*{\arraystretch}{2}% \begin{longtable}{% @{} L{\labelalphawidth} L{\dimexpr0.7\textwidth-0.7\labelalphawidth\relax} L{\dimexpr0.3\textwidth-0.3\labelalphawidth\relax} @{}}} {\end{longtable}} {\anchorlang{% \printtext[labelalphawidth]{% \printfield{labelprefix}% \printfield{labelalpha}% \printfield{extraalpha}}} & \driver{} & \plain{\printfield[qrurl]{url}} \}

\begin{filecontents}{\jobname.bib} @book{texlive-home, shorthand = {TLD1}, author = {The TeX User Group}, title = {TeX Live}, note = {some text to make the entry appear more voluminous}, url = {https://www.tug.org/texlive/} } \end{filecontents} \addbibresource{\jobname.bib} \addbibresource{biblatex-examples.bib}

\begin{document} \nocite{texlive-home,sigfridsson,worman,geer,nussbaum,ctan} \printbibtabular \end{document}

Bibliography with QR code in left column.

moewe
  • 175,683
  • I decided to use this approach because most of my entries have a URL, but little other text, so I appreciate the "auto-spacing" very much. – vwegert Jul 26 '22 at 20:52