usebib:打印摘要(包括 \par)

usebib:打印摘要(包括 \par)
  • 灵感来自这个答案/问题,我想使用usebib包裹打印摘要。
  • 以下 MWE 给出错误,但我看不出明显的原因。
  • 观看它,摘要包含\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

抱歉,加载条目的命令不是\long

您可以修复它:

\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}

注意。我删除了它,biblatex因为它不需要。另一方面,我相信您可以使用biblatex方法提取字段。

或者,使用实验expl3版本。

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 }

现在你可以做

\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}

相关内容