1
  • Inspired by this answer/question, I wanted to use the usebib package to print the abstract.
  • The following MWE gives an error and I do not see an obvious reason.
  • Watch it, the abstract contains \par.

% Based on https://tex.stackexchange.com/questions/73678/
\documentclass{article}

\usepackage{biblatex}

\begin{filecontents}{\jobname.bib} @misc{key, title = {title}, year = {2000}, abstract = {abstract \par abstract}, } \end{filecontents} \addbibresource{\jobname.bib}

\usepackage[hidelinks]{hyperref}

% Load AFTER hyperref \usepackage{usebib}

% Use BEFORE \bibinput \newbibfield{abstract} \bibinput{\jobname}

\begin{document}

\usebibentry{key}{title} \usebibentry{key}{abstract}

\end{document}

See the usebib package documentation for explanation.
Type  H <return>  for immediate help.
 ...

l.28 \usebibentry{key}{abstract}

The key you used is wrong or the value to `abstract' has not been set

1 Answers1

2

The command that loads the entries is not \long, sorry.

You can fix it:

\begin{filecontents*}{\jobname.bib}
@misc{key,
  title = {title},
  year = {2000},
  abstract = {abstract \par abstract},
}
\end{filecontents*}

\documentclass{article} \usepackage{etoolbox} \usepackage[hidelinks]{hyperref} % Load AFTER hyperref \usepackage{usebib}

% Use BEFORE \bibinput \newbibfield{abstract}

\makeatletter \patchcmd[\long]{\reuse@extract}{}{}{}{} \makeatother

\bibinput{\jobname}

\begin{document}

\usebibentry{key}{title} \usebibentry{key}{abstract}

\end{document}

Note. I removed biblatex because it's not needed. On the other hand, I believe you can extract fields using biblatex methods.

Alternatively, use the experimental expl3 version.

usebib3.sty
\RequirePackage{expl3,xparse,url}
\ProvidesExplPackage{usebib3}{2020/10/11}{v. 0.2}{Use fields read in bib files}

\prop_new:N \l__usebib_temp_prop \prop_new:N \g__usebib_temp_prop \seq_new:N \g_usebib_discard_seq

\NewDocumentCommand{\bibinput}{m} { \clist_map_function:nN { #1 } \usebib_main:n } \NewExpandableDocumentCommand{\usebibentry}{mm} { \prop_item:cf { g_usebib_entry_#1_prop } { \str_lower_case:n { #2 } } } \NewExpandableDocumentCommand{\usebibentryurl}{O{|}m} { __usebib_url:nf { #1 } { \prop_item:cn { g_usebib_entry_#2_prop } { url } } } \NewDocumentCommand{\newbibfield}{m}{}

@ifpackageloaded{hyperref} { \cs_new_protected:Nn __usebib_url:nn { \url{ #2 } } } { \cs_new_protected:Nn __usebib_url:nn { \tl_rescan:nn { \url #1 #2 #1 } } } \cs_generate_variant:Nn __usebib_url:nn { nf } \cs_generate_variant:Nn \prop_item:Nn { cf }

\NewDocumentCommand{\newbibignore}{m} { \seq_gput_right:Nx \g_usebib_discard_seq { \str_lower_case:n { #1 } } }

\cs_new_protected:Nn \usebib_main:n { \group_begin: \char_set_active_eq:NN @ \usebib_read_entry:w \char_set_catcode_active:n { `@ } \file_input:n { #1.bib } \group_end: }

\cs_new_protected:Npn \usebib_read_entry:w #1# { \seq_if_in:NxTF \g_usebib_discard_seq { \str_lower_case:n { #1 } } { \use_none:n } { __usebib_read_entry:w } }

\cs_new_protected:Npn __usebib_read_entry:w { \group_begin: \char_set_catcode_other:n { @ } % may appear in text \char_set_catcode_other:n {% } % can be used in URLs \char_set_catcode_other:n { `# } % can be used in fields __usebib_read_entry:n }

\cs_new_protected:Nn __usebib_read_entry:n { \prop_gset_from_keyval:Nn \g__usebib_temp_prop { USEBIBREADKEY=#1 } \group_end: __usebib_save_entry: }

\cs_new_protected:Nn __usebib_save_entry: { \prop_clear:N \l__usebib_temp_prop \prop_map_inline:Nn \g__usebib_temp_prop { \str_if_eq:nnF { ##1 } { USEBIBREADKEY } { \prop_put:Nxn \l__usebib_temp_prop { \str_lower_case:n { ##1 } } { ##2 } } } \prop_new:c { g_usebib_entry_ \prop_item:Nn \g__usebib_temp_prop { USEBIBREADKEY } prop } \prop_gset_eq:cN { g_usebib_entry \prop_item:Nn \g__usebib_temp_prop { USEBIBREADKEY } _prop } \l__usebib_temp_prop } \cs_generate_variant:Nn \prop_put:Nnn { Nx }

Now you can do

\begin{filecontents*}{\jobname.bib}
@misc{key,
  title = {title},
  year = {2000},
  abstract = {abstract \par abstract},
}
\end{filecontents*}

\documentclass{article}

\usepackage[hidelinks]{hyperref} % Load AFTER hyperref \usepackage{usebib3}

% Use BEFORE \bibinput \newbibfield{abstract}

\bibinput{\jobname}

\begin{document}

\usebibentry{key}{title} \usebibentry{key}{abstract}

\end{document}

egreg
  • 1,121,712