如何使用 biblatex/biber 在参考书目中为 DOI 加下划线?(背景:继续进行 SAE 课程)

如何使用 biblatex/biber 在参考书目中为 DOI 加下划线?(背景:继续进行 SAE 课程)

我一直在继续开发现代 SAE 类,并发现此论坛上以前的帮助非常有用。我接下来要做的事情是在参考书目中强调 DOI,以符合 SAE 文章类的指导方针(对于初学者而言)。

这里针对之前的回答。为了便于理解,我想提供一个似乎对这个 SAE 类以及最新的 *.cls 文件运行良好的序言。这是我自己工作的成果,也是我基于许多其他人的工作成果。

\documentclass[letterpaper,9pt]{saeRyan}


% This package provides a handy way to deal with page number handling (fancy headers and footers)
\usepackage{fancyhdr}
\usepackage{lastpage}
\pagestyle{fancy}
\fancyhf{}
\lfoot{Page \thepage \hspace{1pt} of \pageref{LastPage}}
\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{0pt}
\widowpenalty 10000
\clubpenalty 10000

% This package allows for footnoting within tables
\usepackage{enumitem,booktabs,cfr-lm}
\usepackage{tabularx}
\usepackage[referable]{threeparttablex}
\renewlist{tablenotes}{enumerate}{1}
\makeatletter
\setlist[tablenotes]{label=\tnote{\alph*}, ref=\alph*, itemsep=\z@, topsep=\z@skip, partopsep=\z@skip,parsep=\z@,itemindent=\z@,labelindent=\tabcolsep,labelsep=.2em,leftmargin=*,align=left,before={\footnotesize}}
\makeatother

% This package is used for language localization. SAE uses American English!
\usepackage[american]{babel}

% This package is used for advanced context-sensitive quotes. It is strongly recommended by the biblatex package, especially for writing in languages other than American English.
\usepackage{csquotes}

% This package provides some more advanced formatting of DOI within the document and for the bibliography.
\usepackage{doi}

% This package allows detailed control over the usage of underscores within a document 
\usepackage{underscore}

% This package allows detailed control of spacing around other environments (i.e. enumitem, glossary, appendix)
\usepackage{atbeginend}

% This package allows the use of color within the document.
\usepackage{color}

% This package allows for detailed control of urls within the document and in the bibliography.
\usepackage{url}

% This package is the latest and greatest used for inserting graphics into your document.
\usepackage{graphicx}
\graphicspath{{figures/}} % Provide a path to the document's figures.

% This package is for multi-figure usage (deprecated, but still useful here)
\usepackage{subfigure} 

% This package is used to get more control over the positioning of floating objects (graphics, tables, etc.)
\usepackage{float} 

% This package is highly recommended by the biblatex package and extends the patching capability of the etoolbox package to biblatex macros, drivers, and formatting directives.
\usepackage{xpatch}

% For setting bibliography styles, this is the master package. Note: the following packages are NOT compatible with the biblatex package and should NOT be loaded: babelbib, backref, bibtopic, bibunits, chapterbib, cite, citeref, inlinebib, jurabib, mcite, mciteplus, multibib, natbib, splitbib, titlesec, ucs.
\usepackage[style=numeric, maxbibnames=4, minbibnames=3, sorting=none,firstinits=true, url=false, doi=true, backend=biber]{biblatex}

% This command will put a comma after the author list, before the title in the bibliography.
\renewcommand*{\newunitpunct}{\addcomma\space}

% This command will reformat the pages field to remove the "pp." prior to the pages listing in the bibliography.
\DeclareFieldFormat{pages}{#1}

% This command will remove the ", " prior to pages, and replace it with a colon.
\renewcommand*{\bibpagespunct}{\addcolon}

% Show author names by last name for all classes.
\DeclareNameAlias{default}{last-first}
\DeclareNameAlias{sortname}{last-first}

%\DeclareFieldFormat*{title}{\mkbibquote{#1\isdot}}

% Remove the "in:" text prior to the "journaltitle" field in the bibliography
\renewbibmacro*{in:}{}


\renewbibmacro*{journal+issuetitle}{%
  \usebibmacro{journal}%
  \setunit*{\addspace}%
  \iffieldundef{series}
    {}
    {\newunit
     \printfield{series}%
     \setunit{\addspace}}%
  \usebibmacro{volume+number+eid}%
  \setunit{\addcomma\space}%
  \usebibmacro{issue}%
  \newunit}

\DeclareFieldFormat[article,periodical]{number}{\mkbibparens{#1}}
\renewbibmacro*{volume+number+eid}{%
  \printfield{volume}%
  %\setunit*{\adddot}%
  \printfield{number}%
  \setunit{\addcomma\space}%
  \printfield{eid}}

\renewbibmacro*{note+pages}{%
  \printfield{note}%
  \setunit{\bibpagespunct}%
  \printfield{pages}%
  \newunit
  \usebibmacro{date}}

\renewbibmacro*{publisher+location+date}{%
  \printtext[parens]{%
    \printlist{location}%
    \setunit*{\addcomma\space}%
    \printlist{publisher}%
    \setunit*{\addcomma\space}%
    \usebibmacro{date}}%
    \newunit}

\DeclareFieldFormat{url}{\url{#1}}
\DeclareFieldFormat{urldate}{\bibstring{urlseen}\space#1}
\renewbibmacro*{url+urldate}{%
  \usebibmacro{url}%
  \iffieldundef{urlyear}
    {}
    {\setunit*{\addcomma\space}%
     \usebibmacro{urldate}}}

\DefineBibliographyStrings{american}{urlseen = {accessed}}

% Remove the default italics in the "journaltitle" field in the bibliography
\DeclareFieldFormat[article]{journaltitle}{#1}

% This block will help with the formatting of the DOI in the references. It will put the DOI on a new line (rather than split across two lines), and makes a lowercase "doi:" rather than "DOI:"
\DeclareFieldFormat{doi}{%
    \newline
    \mkbibacro{doi}\addcolon\space
    \ifhyperref
        {\href{http://dx.doi.org/#1}{\nolinkurl{#1}}}
        {\nolinkurl{#1}}}
\renewcommand*{\mkbibacro}[1]{%
    {\MakeLowercase{#1}}}

% This block will prevent biblatex from showing issns and other fields in the output for the article class. SAE prefers using DOI over ISSN. This code is cleaner than having to remove these things from your *.bib file(s). The lower block removes the publisher and editor in all classes except for books.
\AtEveryBibitem{% Clean up the bibtex rather than editing it
\ifentrytype{article}{
 \clearlist{address}
 \clearfield{date}
 \clearfield{eprint}
 \clearfield{isbn}
 \clearfield{issn}
 \clearlist{location}
 \clearfield{month}
 \clearfield{series}
 }{}

\ifentrytype{book}{}{% Remove publisher and editor except for books
  \clearlist{publisher}
  \clearname{editor}
 }
}

% Typesets the URL (and DOI) in the same font as the document  
\urlstyle{same}

% This line defines which file(s) bibtex will look for your bib entries. 
\bibliography{library}

% This package is used for hyperlinks within the document and to manage external hyperlinks in a final pdf. The biblatex package recommends loading this package after biblatex.
\usepackage{hyperref}

% Subfigure label control
\setlength{\subfigcapskip}{-0.5cm}
\setlength{\subfigcapmargin}{-0.15cm}
\renewcommand*{\thesubfigure}{\alph{subfigure})}

% This should give a pretty decent compromise with hyphenation (as in reduce the amount of hyphenation in the paper without making things look bad).
\tolerance=1
\emergencystretch=1.4in%\maxdimen % Using \maxdim can cause too much spacing between the bibliography entries.
\hyphenpenalty=1000
\hbadness=1000

\PaperTitle{Title}
\PaperNumber{2000-00-00}
\AddAuthor{Author, co-author list ({\color{red}Do NOT enter this information. It will be pulled from participant tab in MyTechZone})}{Affiliation ({\color{red}Do NOT enter this information. It will be pulled from participant tab in MyTechZone})}
\SAECopyright{2016} 

以下是当前的 SAE 类(正在进行中,测试版,基于最初由 Axel Franke 编写的类,后来由其他人修改,在此示例中称为 SAERyan.cls):

%%
%% LaTeX document style `sae', for use with LaTeX2e
%% This is a style for typesetting an SAE technical paper.
%%
%% COPYRIGHT 1999,2000 by Axel Franke, [email protected]
%%
%% Copying of part or all of any file in the sae.cls style
%% is allowed under the following conditions only:
%% (1) You may freely distribute unchanged copies of the files. Please
%%     include the documentation when you do so.
%% (2) You may modify a renamed copy of any file, but only for personal
%%     use or use within an organization.
%% (3) You may copy fragments from the files, for personal use or for use
%%     in a macro package for distribution, as long as credit is given
%%     where credit is due.
%%
%% You are NOT ALLOWED to take money for the distribution or use of
%% these files or modified versions or fragments thereof, except for
%% a nominal charge for copying etc.
%%

% Identification
\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{saeRyan}[2000/06/28 SAE Technical paper format^^J
Copyright 1999,2000 Axel Franke ([email protected])^^J]


\DeclareOption{times}{%
  \renewcommand{\familydefault}{ptm}%
  \typeout{^^JSetting document font to Times^^J}%
  }
\DeclareOption{helvetica}{%
  \renewcommand{\familydefault}{phv}%
  \typeout{^^JSetting document font to Helvetica^^J}%
  }
\DeclareOption{a4paper}{%

\PassOptionsToPackage{a4paper,nohead,left=15mm,top=15mm,right=15mm,textheight=240mm}{geometry}%
  \typeout{^^JPaper size: A4^^J}%
  \AtBeginDocument{ \columnsep 15mm }
  }
\DeclareOption{letterpaper}{%
  \PassOptionsToPackage{letterpaper,nohead,left=.5in,top=.5in,right=.5in,textheight=10in}{geometry}%
  \typeout{^^JPaper size: Letter^^J}%
  \AtBeginDocument{ \columnsep .5in }
  }

\DeclareOption{pdftex}{%
  \PassOptionsToClass{\CurrentOption}{article}%
  \PassOptionsToPackage{\CurrentOption}{geometry}
  }

\DeclareOption{nonumber}{%
  \pagestyle{empty}%
  }

%% What we do not understand:
\DeclareOption*{\typeout{^^JOption [\CurrentOption] not %
supported by this style.^^J}}

%% default otions
\ExecuteOptions{times,letter,9pt}
\ProcessOptions

% Using classes and packages
%\LoadClass[]{article}
\LoadClass[twocolumn]{article}
\RequirePackage{geometry}

\RequirePackage{colortbl} % colored tables
\RequirePackage{color}
\RequirePackage{xcolor}

% SAE color palette
%\definecolor{SAEblue}{cmyk}{0.86, 0.08, 0.04, 0.20}
\definecolor{SAEblue}{rgb}{0, .62, .91}
\definecolor{SAEdarkblue}{cmyk}{1.0, 0.6, 0.04, 0.19}
\definecolor{SAElightgreen}{cmyk}{0.69, 0, 0.97, 0}
\definecolor{SAEdarkgreen}{cmyk}{1.00, 0.02, 1.00, 0.1}
\definecolor{SAEyellow}{cmyk}{0, 0.31, 0.95, 0}
\definecolor{SAEorange}{cmyk}{0, 0.62, 0.95, 0}
\definecolor{SAEred}{cmyk}{0, 0.95, 1.00, 0}
\definecolor{SAElightgray}{cmyk}{0, 0, 0, 0.2}
\definecolor{SAEmediumgray}{cmyk}{0, 0, 0, 0.45}
\definecolor{SAEdarkgray}{cmyk}{0, 0, 0, 0.8}


% TexShop
\RequirePackage{graphicx}
% caption font
\RequirePackage{caption}
%\renewcommand\captionfont{\color{SAEblue}\small}
\renewcommand\captionfont{\color{SAEblue}\small}
%\renewcommand\captionlabelfont{\bfseries}

\renewcommand\@biblabel[1]{#1.}

%% Declarations

% sections etc. not numbered
\setcounter{secnumdepth}{-2}

% LaTeX uses rubber length for \parskip
% SAE style seems to use fixed length
\setlength{\parskip}{\baselineskip}
%\setlength{\parskip}{0 pt}

% distance between the preceding text and a list item (description
% list, enumerated list, etc.) was too large
\setlength{\topsep}{-\parskip}
%  This places floats where they should go (suggested by Ross Pursifull,
%  "Pursifull, Ross (R.)" <[email protected]>, 19991207)
\renewcommand{\bottomfraction}{1}
\renewcommand{\textfraction}{0}
\setcounter{topnumber}{10}
\setcounter{bottomnumber}{10}
\setlength{\parindent}{0pt}

%% Heading formats
%\renewcommand{\section}{\@startsection
%  {section}%
%  {1}%
%  {0mm}%
%  {-.1\baselineskip}%
%  {.1\baselineskip}%
%  {\large\bfseries\uppercase}%
%}


%% Heading formats
\renewcommand{\section}{\@startsection
  {section}%
  {1}%
  {0mm}%
  {-.1\baselineskip}%
  {.1\baselineskip}%
  {\Large\bfseries}%
}


%\renewcommand\section{\@startsection
%{section}
%{1}
%{\z@}
%{-10\p@ \@plus -4\p@ \@minus -4\p@}
%{1\p@ \@plus 1\p@ \@minus 1\p@}
%{\normalfont\large}
%}


\renewcommand{\subsection}{\@startsection
  {subsection}%
  {2}%
  {0mm}%
  {-\baselineskip}%
  {.1\baselineskip}%
  {\bfseries\large\itshape}%
}

\renewcommand{\subsubsection}{\@startsection
  {subsubsection}%
  {3}%
  {0mm}%
  {-\baselineskip}%
  {-\baselineskip}%
  {\flushleft\normalsize}%
}

\renewcommand{\paragraph}{\@startsection
  {paragraph}%
  {4}%
  {0mm}%
  {-\baselineskip}%
  {-\baselineskip}%
  {\flushleft\normalsize}%
}

\renewcommand{\refname}{\flushleft\uppercase\bfseries REFERENCES}


%% Build title page
\def\@maketitle{%
  \null
  \parbox[t][70mm][t]{\textwidth}{%
    \begin{flushright}%
      \fontsize{14}{18}\selectfont%
      \usebox{\numberbox}\\
      \usebox{\titlebox}\\
      \vskip 1 cm
      \usebox{\authorbox}\\[2ex]%
    \end{flushright}%
    \vfill
    \begin{flushleft}%
        \raisebox{1cm}{\usebox{\saecopyrightbox}}\\%
    \end{flushleft}
}%b
}

% Boxes for the title
\newsavebox{\authorbox}
\savebox{\authorbox}{}
\newsavebox{\titlebox}
\newsavebox{\numberbox}
\newsavebox{\saecopyrightbox}

\newcommand{\AddAuthor}[2]{%
  \savebox{\authorbox}{%
    \parbox[t]{\textwidth}{%
      \flushright%
      \usebox{\authorbox}\\%
      \fontfamily{\familydefault}\fontsize{12}{14}%
        \fontseries{b}\fontshape{n}\selectfont%
        #1\\%
      {\fontfamily{\familydefault}\fontsize{10}{11}%
        \fontseries{m}\fontshape{n}\selectfont%
        #2}\fontsize{12}{12}\selectfont\\[2ex]%
      }%
    }
  }
\newcommand{\PaperTitle}[1]{%
  \savebox{\titlebox}{%
    \parbox[t]{\textwidth}%
    {\flushright%
      \fontfamily{\familydefault}\fontsize{18}{22}%
      \fontseries{b}\fontshape{n}\selectfont%
      #1}%
    }%
  }
\newcommand{\PaperNumber}[1]{%
  \savebox{\numberbox}{
    \fontfamily{\familydefault}\fontsize{14}{18}%
    \fontseries{b}\fontshape{n}\selectfont%
    #1}%
  }

\newcommand{\SAECopyright}[1]{%
  \savebox{\saecopyrightbox}{%
    {\fontfamily{\familydefault}\fontsize{8}{10}%
      \fontseries{m}\fontshape{n}\selectfont%
      Copyright {\copyright} #1 SAE International}%
    }%
  }

答案1

您可以使用的解决方案来自我无法获得(正确)带蓝色下划线的超链接

\usepackage[normalem]{ulem}

\makeatletter
\DeclareUrlCommand\ULurl@@{%
  \def\UrlLeft{\uline\bgroup}%
  \def\UrlRight{\egroup}}
\def\ULurl@#1{\hyper@linkurl{\ULurl@@{#1}}{#1}}
\DeclareRobustCommand*\ULurl{\hyper@normalise\ULurl@}
\makeatother

\DeclareFieldFormat{doi}{%
    \newline
    \mkbibacro{doi}\addcolon\space
    \ifhyperref
        {\href{http://dx.doi.org/#1}{\ULurl{#1}}}
        {\ULurl{#1}}}

或者不带包

\DeclareFieldFormat{doi}{%
    \newline
    \mkbibacro{doi}\addcolon\space
    \underline{\ifhyperref
        {\href{http://dx.doi.org/#1}{\nolinkurl{#1}}}
        {\nolinkurl{#1}}}}

相关内容