hushidong / biblatex-gb7714-2015

A biblatex implementation of the GB/T7714-2015 bibliography style || GB/T 7714-2015 参考文献著录和标注的biblatex样式包
742 stars 83 forks source link

关于增加 `file` 域来链接本地文件的问题 #194

Closed xkwxdyy closed 2 months ago

xkwxdyy commented 2 months ago

需求描述

最近在写论文,由于我是先写框架再补充细节,所以一开始先在正文中用 \parencite 记录好定理命题的引用出处,最后写好框架之后再补充一些细节,这就需要我能方便地打开对应文献对应的 PDF,结合 hyperref 可以方便跳转到 \printbibliography 的对应位置,这个时候希望能在对应文献里加一个 file 域,能打开对应的PDF

尝试

在 tex.se 上找到一个方法, MWE 测试没问题,但是放到我的 cls 里遇到了点问题。

问题:打不开局部文件

因为我的 biblatex 不只有这一个设置需求,还有一些其它的设置,主要有

\RequirePackage
  [
    backend      = biber,
    bibstyle     = gb7714-2015,
    sorting      = nty,
    gbalign      = right,
    citestyle    = gb7714-WHU,
    gbnamefmt    = givenahead,
    gbpunctin    = false,
    doi          = false,
    backref      = true,
    gbtype       = false,
    gbstrict     = false,
  ]{biblatex}

对样式做一些基本的设置。

\setcounter { gbrefcompress } { 3 }
        \DeclareDelimFormat [ parencite ] { multicitedelimiter } { \addcomma\addthinspace }  % 太窄则用addspace
        % zepinglee 建议 \cite 的不加空格
        \DeclareDelimFormat [ cite ] { multicitedelimiter } { \addcomma }
        \RenewDocumentCommand \multicitedelim { } { \printdelim { multicitedelimiter } }

是前几天在 #137 里问关于 \parencite 的空格解决。

\renewbibmacro*{series+number}{%
    \printfield{series}%
    \setunit*{\addcolon\addspace}%
    \printfield{number}%
    \newunit%
    }
  \AtEveryBibitem{ \clearlist{language} }
  %   book条目类的驱动
  %
  \DeclareBibliographyDriver{book}{%源来自standard.bbx文件
    \usebibmacro{bibindex}%
    \usebibmacro{begentry}%
    \usebibmacro{author/editor+others/translator+others}%
    \ifnameundef{namea}{}{\setunit{\labelnamepunct}\newblock}%这一段用于去除作者不存在时多出的标点
    \usebibmacro{maintitle+title}%
    \iftoggle{bbx:gbstrict}{}{%
    \newunit
    \printlist{language}%
    \newunit\newblock%
    \usebibmacro{byauthor}%
    \newunit\newblock}%
    \usebibmacro{byeditor+others}%
    \newunit
    \printfield{edition}%
    \newunit\newblock%%
    \iftoggle{bbx:gbstrict}{}{%
    \iffieldundef{maintitle}%
    {%\printfield{volume}%
    \printfield{part}}%
    {}%
    \newunit%
    \printfield{volumes}%
    \newunit\newblock%
    \usebibmacro{series+number}}%
    \newunit\newblock%
    %\printfield{note}%
    %\newunit\newblock%
    \usebibmacro{publisher+location+date}%
    %\newunit\newblock %这里标点去掉
    \usebibmacro{chapter+pages}%
      \iffieldundef{url}{}{%当没有网址时也不输出
      \usebibmacro{modifydate}}%带括号的修改或更新日期,
    \usebibmacro{doi+eprint+url}%从下面移动到上面来,因为gbt2015的url需直接放在页码后面。
    \newunit\newblock%
    \printfield{pagetotal}%
    \newunit\newblock%
    \iftoggle{bbx:isbn}
      {\printfield{isbn}}
      {}%
    \newunit\newblock
    %\usebibmacro{doi+eprint+url}%
    %\newunit\newblock
    \usebibmacro{addendum+pubstate}%
    \setunit{\bibpagerefpunct}\newblock
    \usebibmacro{pageref}%
    \newunit\newblock
    \iftoggle{bbx:related}
      {\usebibmacro{related:init}%
      \usebibmacro{related}}
      {}%
    \usebibmacro{finentry}\usebibmacro{annotation}}

是我在 #172 里找到的办法,用来输出 book 类的 series

没有其它内容了。整理出 MWE:

\documentclass{ctexart}
\makeatletter
\ExplSyntaxOn
\usepackage
  [
    backend      = biber,
    bibstyle     = gb7714-2015,
    sorting      = nty,
    gbalign      = right,
    % citestyle    = gb7714-WHU,
    gbnamefmt    = givenahead,
    gbpunctin    = false,
    doi          = false,
    backref      = true,
    gbtype       = false,
    gbstrict     = false,
  ]{biblatex}
% https://tex.stackexchange.com/a/111851/246645
\DeclareFieldFormat{
  file}{\href{file:#1}{\color{red}\textbf{Open file}}}
\AtEveryBibitem{%
    \csappto{blx@bbx@\thefield{entrytype}}{% put at end of entry
        \iffieldundef{file}{\space \textbf{No file!}}{%
        \space \printfield{file}
      }
    }
  }
\DeclareDelimFormat [ parencite ] { multicitedelimiter } { \addcomma\addthinspace }  % 太窄则用addspace
% zepinglee 建议 \cite 的不加空格
\DeclareDelimFormat [ cite ] { multicitedelimiter } { \addcomma }
\RenewDocumentCommand \multicitedelim { } { \printdelim { multicitedelimiter } }
% \DefineBibliographyStrings{english}{in={}}
% \DefineBibliographyStrings{english}{incn={}}

% https://github.com/hushidong/biblatex-gb7714-2015/issues/172
\renewbibmacro*{series+number}{%
  \printfield{series}%
  \setunit*{\addcolon\addspace}%
  \printfield{number}%
  \newunit%
  }
\AtEveryBibitem{ \clearlist{language} }
%   book条目类的驱动
%
\DeclareBibliographyDriver{book}{%源来自standard.bbx文件
  \usebibmacro{bibindex}%
  \usebibmacro{begentry}%
  \usebibmacro{author/editor+others/translator+others}%
  \ifnameundef{namea}{}{\setunit{\labelnamepunct}\newblock}%这一段用于去除作者不存在时多出的标点
  \usebibmacro{maintitle+title}%
  \iftoggle{bbx:gbstrict}{}{%
  \newunit
  \printlist{language}%
  \newunit\newblock%
  \usebibmacro{byauthor}%
  \newunit\newblock}%
  \usebibmacro{byeditor+others}%
  \newunit
  \printfield{edition}%
  \newunit\newblock%%
  \iftoggle{bbx:gbstrict}{}{%
  \iffieldundef{maintitle}%
  {%\printfield{volume}%
  \printfield{part}}%
  {}%
  \newunit%
  \printfield{volumes}%
  \newunit\newblock%
  \usebibmacro{series+number}}%
  \newunit\newblock%
  %\printfield{note}%
  %\newunit\newblock%
  \usebibmacro{publisher+location+date}%
  %\newunit\newblock %这里标点去掉
  \usebibmacro{chapter+pages}%
    \iffieldundef{url}{}{%当没有网址时也不输出
    \usebibmacro{modifydate}}%带括号的修改或更新日期,
  \usebibmacro{doi+eprint+url}%从下面移动到上面来,因为gbt2015的url需直接放在页码后面。
  \newunit\newblock%
  \printfield{pagetotal}%
  \newunit\newblock%
  \iftoggle{bbx:isbn}
    {\printfield{isbn}}
    {}%
  \newunit\newblock
  %\usebibmacro{doi+eprint+url}%
  %\newunit\newblock
  \usebibmacro{addendum+pubstate}%
  \setunit{\bibpagerefpunct}\newblock
  \usebibmacro{pageref}%
  \newunit\newblock
  \iftoggle{bbx:related}
    {\usebibmacro{related:init}%
    \usebibmacro{related}}
    {}%
  \usebibmacro{finentry}\usebibmacro{annotation}}
\ExplSyntaxOff
\makeatother
\usepackage{filecontents}

\begin{filecontents*}{\jobname.bib}
@article{Padial:2010,
    title={The integrative future of taxonomy},
    author={José M.~Padial and Aurélien Miralles and Ignacio De la Riva and Miguel Vences},
    file={./MWE4.pdf},
}
\end{filecontents*}

\addbibresource{\jobname.bib}

\usepackage[%
  colorlinks,
  unicode,
  breaklinks,
]{hyperref}

\begin{document}

\nocite{*} % list all entries

\printbibliography

\end{document}

其中 ./MWE4.pdf 是我用于测试的,放在这个 MWE 的 tex 文件同级目录下。

使用 latexmk -xelatex 编译后发现 “open file” 的链接可以点,但是没有效果,也就是打不开 ./MWE4.pdf。我不知道是和上面的其它什么需求冲突了还是怎么样,这些需求有更好的解决办法吗,尤其是第二个,感觉加了比较长的代码,会更容易出问题。

问题:打不开全局文件

还有一个问题是,我的文献一般放在其它目录下统一管理,如果要移动到局部路径比较麻烦,所以想能否实现一个全局文件的打开

上面提到的 在 tex.se 上找到一个方法,我把其中文件的路径改成

/Users/xiakangwei/Nutstore/000 - Postgraduate - 研究生/140.00 - Postgraduate - 研究生 - 论文/文献库/sub-Hilbert/sub-Bergman/2006; Sub-Bergman Hilbert spaces - Saida Sultanic.pdf

发现就失效了,打不开,貌似不能在全局搜索,我不确定是不是不能搜索当前目录和 TEXMF 外的目录。

于是我想到了 mac 系统的一款软件叫做 Hookmark,它可以给每一个文件一个 hook 链接,可以 hook 两个文件等,我主要用的就是它这个 hook 链接可以点击打开这个文件的功能,而且是全局、且不受文件移动影响。hook 链接一般长这样:

hook://file/eVtzjmTJW?p=c3ViLUhpbGJlcnQvc3ViLUJlcmdtYW4=&n=2006%3B%20Sub%2DBergman%20Hilbert%20spaces%20%2D%20Saida%20Sultanic%2Epdf

我在 Markdown 里试了是可以点击打开的,所以我上面的需求综合起来就是能否增加一个域来打开形如上面这样的 hook 链接。

hushidong commented 2 months ago
  1. 不用加file:
  2. 不同的阅读器支持不一样,所以要根据你的阅读器来处理。

下面的例子中: 有4个链接,前两个是相对路径,后两个是绝对路径的。 1)在sumatrapdf,nitro软件中能打开同目录下的相对路径的文件,但不能打开绝对路径的。 2)在wps中能打开绝对路径的,但不能打开相对路径的。

我用sumatrapdf打开没有问题的。

示例如下:

\documentclass{ctexart}
\makeatletter
\ExplSyntaxOn
\usepackage
  [
    backend      = biber,
    bibstyle     = gb7714-2015,
    sorting      = nty,
    gbalign      = right,
    % citestyle    = gb7714-WHU,
    gbnamefmt    = givenahead,
    gbpunctin    = false,
    doi          = false,
    backref      = true,
    gbtype       = false,
    gbstrict     = false,
    gbannote=true,
  ]{biblatex}
% https://tex.stackexchange.com/a/111851/246645
\DeclareFieldFormat{file}{\href{#1}{\color{red}\textbf{Open file}}}

\renewbibmacro*{annotation}{%
    \iftoggle{bbx:gbannote}%
    {\iffieldundef{annotation}%
        {\printfile[annotation]{\bibannotationprefix\thefield{entrykey}.tex}}%
        {\printfield{annotation}}}%
    {}%
    \iffieldundef{file}{\space\textbf{No file!}}{%
    \space \printfield{file}}
    }

\DeclareDelimFormat [ parencite ] { multicitedelimiter } { \addcomma\addthinspace }  % 太窄则用addspace
% zepinglee 建议 \cite 的不加空格
\DeclareDelimFormat [ cite ] { multicitedelimiter } { \addcomma }
\RenewDocumentCommand \multicitedelim { } { \printdelim { multicitedelimiter } }
% \DefineBibliographyStrings{english}{in={}}
% \DefineBibliographyStrings{english}{incn={}}

% https://github.com/hushidong/biblatex-gb7714-2015/issues/172
\renewbibmacro*{series+number}{%
  \printfield{series}%
  \setunit*{\addcolon\addspace}%
  \printfield{number}%
  \newunit%
  }
\AtEveryBibitem{ \clearlist{language} }
%   book条目类的驱动
%
\DeclareBibliographyDriver{book}{%源来自standard.bbx文件
  \usebibmacro{bibindex}%
  \usebibmacro{begentry}%
  \usebibmacro{author/editor+others/translator+others}%
  \ifnameundef{namea}{}{\setunit{\labelnamepunct}\newblock}%这一段用于去除作者不存在时多出的标点
  \usebibmacro{maintitle+title}%
  \iftoggle{bbx:gbstrict}{}{%
  \newunit
  \printlist{language}%
  \newunit\newblock%
  \usebibmacro{byauthor}%
  \newunit\newblock}%
  \usebibmacro{byeditor+others}%
  \newunit
  \printfield{edition}%
  \newunit\newblock%%
  \iftoggle{bbx:gbstrict}{}{%
  \iffieldundef{maintitle}%
  {%\printfield{volume}%
  \printfield{part}}%
  {}%
  \newunit%
  \printfield{volumes}%
  \newunit\newblock%
  \usebibmacro{series+number}}%
  \newunit\newblock%
  %\printfield{note}%
  %\newunit\newblock%
  \usebibmacro{publisher+location+date}%
  %\newunit\newblock %这里标点去掉
  \usebibmacro{chapter+pages}%
    \iffieldundef{url}{}{%当没有网址时也不输出
    \usebibmacro{modifydate}}%带括号的修改或更新日期,
  \usebibmacro{doi+eprint+url}%从下面移动到上面来,因为gbt2015的url需直接放在页码后面。
  \newunit\newblock%
  \printfield{pagetotal}%
  \newunit\newblock%
  \iftoggle{bbx:isbn}
    {\printfield{isbn}}
    {}%
  \newunit\newblock
  %\usebibmacro{doi+eprint+url}%
  %\newunit\newblock
  \usebibmacro{addendum+pubstate}%
  \setunit{\bibpagerefpunct}\newblock
  \usebibmacro{pageref}%
  \newunit\newblock
  \iftoggle{bbx:related}
    {\usebibmacro{related:init}%
    \usebibmacro{related}}
    {}%
  \usebibmacro{finentry}\usebibmacro{annotation}}
\ExplSyntaxOff
\makeatother

\begin{filecontents}[force]{\jobname.bib}
@article{Padial:2010,
    title={The integrative future of taxonomy},
    author={José M.~Padial and Aurélien Miralles and Ignacio De la Riva and Miguel Vences},
    file={g.pdf},
}

@article{Padial:2012,
    title={The integrative future of taxonomy},
    author={José M.~Padial and Aurélien Miralles and Ignacio De la Riva and Miguel Vences},
    file={test/g.pdf},
}

@article{Padial:2013,
    title={The integrative future of taxonomy},
    author={José M.~Padial and Aurélien Miralles and Ignacio De la Riva and Miguel Vences},
    file={C:\Users\hzzma\Desktop\bib\test\g.pdf},
}

@article{Padial:2014,
    title={The integrative future of taxonomy},
    author={José M.~Padial and Aurélien Miralles and Ignacio De la Riva and Miguel Vences},
    file={C:/Users/hzzma/Desktop/bib/test/g.pdf},
}

@article{Padial:2011,
    title={The integrative future of taxonomy},
    author={José M.~Padial and Aurélien Miralles and Ignacio De la Riva and Miguel Vences},
}
\end{filecontents}

\addbibresource{\jobname.bib}

\usepackage[%
  colorlinks,
  unicode,
  breaklinks,
]{hyperref}

\begin{document}

\nocite{*} % list all entries

\printbibliography

\end{document} 

结果为:

点击即可。

图片

xkwxdyy commented 2 months ago

那如果我想描述里说那样调用

hook://file/eVtzjmTJW?p=c3ViLUhpbGJlcnQvc3ViLUJlcmdtYW4=&n=2006%3B%20Sub%2DBergman%20Hilbert%20spaces%20%2D%20Saida%20Sultanic%2Epdf

这种链接也是上面这样的设置吗?

xkwxdyy commented 2 months ago

那如果我想描述里说那样调用

hook://file/eVtzjmTJW?p=c3ViLUhpbGJlcnQvc3ViLUJlcmdtYW4=&n=2006%3B%20Sub%2DBergman%20Hilbert%20spaces%20%2D%20Saida%20Sultanic%2Epdf

这种链接也是上面这样的设置吗?

好像不行,输入都成问题,% 不能正确识别,然后我用了 \url{hook://xxxx} 也不行,好像这类的链接处理不了

xkwxdyy commented 2 months ago

看来只能复制一份文献到当前目录下了

hushidong commented 2 months ago

那如果我想描述里说那样调用

hook://file/eVtzjmTJW?p=c3ViLUhpbGJlcnQvc3ViLUJlcmdtYW4=&n=2006%3B%20Sub%2DBergman%20Hilbert%20spaces%20%2D%20Saida%20Sultanic%2Epdf

这种链接也是上面这样的设置吗?

好像不行,输入都成问题,% 不能正确识别,然后我用了 \url{hook://xxxx} 也不行,好像这类的链接处理不了

没有差别啊,直接用就行了,只是看阅读器支不支持hook。

\documentclass{ctexart}
\makeatletter
\ExplSyntaxOn
\usepackage
  [
    backend      = biber,
    bibstyle     = gb7714-2015,
    sorting      = nty,
    gbalign      = right,
    % citestyle    = gb7714-WHU,
    gbnamefmt    = givenahead,
    gbpunctin    = false,
    doi          = false,
    backref      = true,
    gbtype       = false,
    gbstrict     = false,
    gbannote=true,
  ]{biblatex}
% https://tex.stackexchange.com/a/111851/246645
\DeclareFieldFormat{file}{\href{#1}{\color{red}\textbf{Open file}}}

\renewbibmacro*{annotation}{%
    \iftoggle{bbx:gbannote}%
    {\iffieldundef{annotation}%
        {\printfile[annotation]{\bibannotationprefix\thefield{entrykey}.tex}}%
        {\printfield{annotation}}}%
    {}%
    \iffieldundef{file}{\space\textbf{No file!}}{%
    \space \printfield{file}}
    }

\DeclareDelimFormat [ parencite ] { multicitedelimiter } { \addcomma\addthinspace }  % 太窄则用addspace
% zepinglee 建议 \cite 的不加空格
\DeclareDelimFormat [ cite ] { multicitedelimiter } { \addcomma }
\RenewDocumentCommand \multicitedelim { } { \printdelim { multicitedelimiter } }
% \DefineBibliographyStrings{english}{in={}}
% \DefineBibliographyStrings{english}{incn={}}

% https://github.com/hushidong/biblatex-gb7714-2015/issues/172
\renewbibmacro*{series+number}{%
  \printfield{series}%
  \setunit*{\addcolon\addspace}%
  \printfield{number}%
  \newunit%
  }
\AtEveryBibitem{ \clearlist{language} }
%   book条目类的驱动
%
\DeclareBibliographyDriver{book}{%源来自standard.bbx文件
  \usebibmacro{bibindex}%
  \usebibmacro{begentry}%
  \usebibmacro{author/editor+others/translator+others}%
  \ifnameundef{namea}{}{\setunit{\labelnamepunct}\newblock}%这一段用于去除作者不存在时多出的标点
  \usebibmacro{maintitle+title}%
  \iftoggle{bbx:gbstrict}{}{%
  \newunit
  \printlist{language}%
  \newunit\newblock%
  \usebibmacro{byauthor}%
  \newunit\newblock}%
  \usebibmacro{byeditor+others}%
  \newunit
  \printfield{edition}%
  \newunit\newblock%%
  \iftoggle{bbx:gbstrict}{}{%
  \iffieldundef{maintitle}%
  {%\printfield{volume}%
  \printfield{part}}%
  {}%
  \newunit%
  \printfield{volumes}%
  \newunit\newblock%
  \usebibmacro{series+number}}%
  \newunit\newblock%
  %\printfield{note}%
  %\newunit\newblock%
  \usebibmacro{publisher+location+date}%
  %\newunit\newblock %这里标点去掉
  \usebibmacro{chapter+pages}%
    \iffieldundef{url}{}{%当没有网址时也不输出
    \usebibmacro{modifydate}}%带括号的修改或更新日期,
  \usebibmacro{doi+eprint+url}%从下面移动到上面来,因为gbt2015的url需直接放在页码后面。
  \newunit\newblock%
  \printfield{pagetotal}%
  \newunit\newblock%
  \iftoggle{bbx:isbn}
    {\printfield{isbn}}
    {}%
  \newunit\newblock
  %\usebibmacro{doi+eprint+url}%
  %\newunit\newblock
  \usebibmacro{addendum+pubstate}%
  \setunit{\bibpagerefpunct}\newblock
  \usebibmacro{pageref}%
  \newunit\newblock
  \iftoggle{bbx:related}
    {\usebibmacro{related:init}%
    \usebibmacro{related}}
    {}%
  \usebibmacro{finentry}\usebibmacro{annotation}}
\ExplSyntaxOff
\makeatother

\begin{filecontents}[force]{\jobname.bib}
@article{Padial:2010,
    title={The integrative future of taxonomy},
    author={José M.~Padial and Aurélien Miralles and Ignacio De la Riva and Miguel Vences},
    file={g.pdf},
}

@article{Padial:2012,
    title={The integrative future of taxonomy},
    author={José M.~Padial and Aurélien Miralles and Ignacio De la Riva and Miguel Vences},
    file={test/g.pdf},
}

@article{Padial:2013,
    title={The integrative future of taxonomy},
    author={José M.~Padial and Aurélien Miralles and Ignacio De la Riva and Miguel Vences},
    file={C:\Users\hzzma\Desktop\bib\test\g.pdf},
}

@article{Padial:2014,
    title={The integrative future of taxonomy},
    author={José M.~Padial and Aurélien Miralles and Ignacio De la Riva and Miguel Vences},
    file={C:/Users/hzzma/Desktop/bib/test/g.pdf},
}

@article{Padial:2015,
    title={The integrative future of taxonomy},
    author={José M.~Padial and Aurélien Miralles and Ignacio De la Riva and Miguel Vences},
    file={hook://file/eVtzjmTJW?p=c3ViLUhpbGJlcnQvc3ViLUJlcmdtYW4=&n=2006%3B%20Sub%2Epdf},
}

@article{Padial:2011,
    title={The integrative future of taxonomy},
    author={José M.~Padial and Aurélien Miralles and Ignacio De la Riva and Miguel Vences},
}
\end{filecontents}

\addbibresource{\jobname.bib}

\usepackage[%
  colorlinks,
  unicode,
  breaklinks,
]{hyperref}

\begin{document}

\nocite{*} % list all entries

\printbibliography

\end{document} 

结果为: 图片

图中圈起来的就是file中给出的链接。

xkwxdyy commented 2 months ago

没有差别啊,直接用就行了,只是看阅读器支不支持hook。

我忘了高亮是在 tex 文件了,以为会影响。太感谢您了胡老师,我试了一下,在mac 的 skim 阅读器里可以打开这个 hook!这样就太方便了。

对了还有一个点,如果我想去掉 file 域的显示,除了把整个 declare 去掉,请问有没有类似于 gbfile = false 的接口设置?我又不想把 bib 文件的 file 去掉,因为以后可能还有用,直接去掉 declare 怕有一些警告之类的。

hushidong commented 2 months ago

在bbx中定义一个选项就可以,要使用就打开选项:

\newtoggle{bbx:gbfile}
\DeclareBibliographyOption{gbfile}[false]{%biblatex低版本
  \settoggle{bbx:gbfile}{#1}}
\ExecuteBibliographyOptions{gbfile}

\renewbibmacro*{annotation}{%
    \iftoggle{bbx:gbannote}%
    {\iffieldundef{annotation}%
        {\printfile[annotation]{\bibannotationprefix\thefield{entrykey}.tex}}%
        {\printfield{annotation}}}%
    {}%
    \iftoggle{bbx:gbfile}{%
    \iffieldundef{file}{\space\textbf{No file!}}{%
    \space \printfield{file}}}{}%
    }
xkwxdyy commented 2 months ago

在bbx中定义一个选项就可以,要使用就打开选项:

\newtoggle{bbx:gbfile}
\DeclareBibliographyOption{gbfile}[false]{%biblatex低版本
  \settoggle{bbx:gbfile}{#1}}
\ExecuteBibliographyOptions{gbfile}

\renewbibmacro*{annotation}{%
  \iftoggle{bbx:gbannote}%
  {\iffieldundef{annotation}%
      {\printfile[annotation]{\bibannotationprefix\thefield{entrykey}.tex}}%
      {\printfield{annotation}}}%
    {}%
    \iftoggle{bbx:gbfile}{%
    \iffieldundef{file}{\space\textbf{No file!}}{%
    \space \printfield{file}}}{}%
    }

感谢,不过测试了一下,这样会把 hook 链接直接显示。

我把第二行改成了

\DeclareBibliographyOption{gbfile}[false]{%biblatex低版本
  \settoggle{bbx:gbfile}{\href{#1}{\textcolor{red}{Open file.}}}}

但是报错

! Undefined control sequence.
<argument> etb@toggle\href 
                           {false}{\textcolor {red}{Open file.}}
l.53 \ExecuteBibliographyOptions{gbfile}

? 

看上去是 \href 没定义,但是按理来说参考文献都放在这么后面加载了,应该是在 hyperref 包后加载的。还是说 bbx 里不能出现这种命令呢?

xkwxdyy commented 2 months ago

看上去是 \href 没定义,但是按理来说参考文献都放在这么后面加载了,应该是在 hyperref 包后加载的。还是说 bbx 里不能出现这种命令呢?

应该是加载的时候 biblatex 在 hyperref 后面加载了。 我改成了

% .cls
\AtBeginDocument
  {
    \RequirePackage
      [
        backend      = biber,
        bibstyle     = gb7714-WHU,
        citestyle    = gb7714-WHU,
        gbfile       = true
      ]{biblatex}
    \setcounter { gbrefcompress } { 3 }
    \NewCommandCopy { \whuprintbibliography } { \printbibliography }
    \RenewDocumentCommand { \printbibliography } { }
      {
        \sloppy
        \__whu_bib_printbibliography_preset:
        \whuprintbibliography [ heading = bibintoc ]
      }
  }
% main.tex
\AtBeginDocument{ 
  \addbibresource{../MasterThesis.bib}
}

然后关于 hyperref 的设置是

\AtEndPreamble
  {
    \RequirePackage { hyperref }
    \hypersetup 
      { 
        pdfencoding = auto,
        citecolor   = magenta,
        linkcolor   = blue,
        hidelinks
      }
  }

这样报错变成了

! Undefined control sequence.
l.2 \abx@aux@refcontext
                       {nty/global//global/global/global}
? 
hushidong commented 2 months ago

尽量不要在选项里面直接做细节操作,选项提供toggle就行了。

你再测试一下,上面的处理是可以的,因为除了一些特殊的选项外,biblatex中的大部分选项都采用这种方式定义的。

你加入这个选项后,然后在引入biblatex包时,测试一下gbfile选项选true和false时的差异看看。

xkwxdyy commented 2 months ago

尽量不要在选项里面直接做细节操作,选项提供toggle就行了。

你再测试一下,上面的处理是可以的,因为除了一些特殊的选项外,biblatex中的大部分选项都采用这种方式定义的。

你加入这个选项后,然后在引入biblatex包时,测试一下gbfile选项选true和false时的差异看看。

嗯嗯胡老师,测试效果其实没问题,只是 true 的时候链接会这样显示

image
xkwxdyy commented 2 months ago

我 tex.se 查到的问题都是在 .tex 文件的导言区进行这些设置,他们用 \href 没问题。

不过问题不大,毕竟这个最终交上去的时候肯定设置成 false,其实还是给自己看的,效果已经很好了

hushidong commented 2 months ago

你是说链接不要显式的给出吧?那需要一个点链接的标签,之前用的是\DeclareFieldFormat{file}{\href{#1}{\color{red}\textbf{Open file}}}

你可以用一个其他的符号做链接的标签的,把这个格式和\renewbibmacro*{annotation}都改一下好了。

比如:

\DeclareFieldFormat{file}{\href{#1}{\color{red}$\blacktriangleright$}}
\renewbibmacro*{annotation}{%
    \iftoggle{bbx:gbannote}%
    {\iffieldundef{annotation}%
        {\printfile[annotation]{\bibannotationprefix\thefield{entrykey}.tex}}%
        {\printfield{annotation}}}%
    {}%
    \iftoggle{bbx:gbfile}{%
    \iffieldundef{file}{}{\printfield{file}}}{}%
    }
xkwxdyy commented 2 months ago

你是说链接不要显式的给出吧?那需要一个点链接的标签,之前用的是\DeclareFieldFormat{file}{\href{#1}{\color{red}\textbf{Open file}}}

你可以用一个其他的符号做链接的标签的,把这个格式和\renewbibmacro*{annotation}都改一下好了。

效果很棒!非常感谢胡老师!

hushidong commented 2 months ago

@xkwxdyy 你这英文字体用的什么啊?看起来不错呢,我学习一下。

xkwxdyy commented 2 months ago

@xkwxdyy 你这英文字体用的什么啊?看起来不错呢,我学习一下。

胡老师,我印象里没有配置字体诶(捂脸),代码主要来自我的 whuthesis 项目

我的电脑是 mac 的,可能调用了一些 mac 的字体?

SwitWu commented 2 months ago

字体不就是 latin modern roman 吗

hushidong commented 2 months ago

好的。