使用bst自动模式引入参考文献,如何实现文献的连续引用

发布于 2025-03-02 12:21:18

OP(Original Problem):

main中使用bst自动模式的参考文献引用方式如下:

% 两种文献导入方式。如果开启bst自动模式,在format.cls中bibcontrol部分无效
\ifx \refstyle \auto
    % bst自动
    \addcontentsline{toc}{chapter}{参考文献}
    \bibliographystyle{references/gbt7714-2005}
    \bibliography{references/paper.bib}
format文件中参考文献控制如下:
%============================= Bibitem control ================================% 
\def \auto {auto}
\ifx \refstyle \auto

\else

\usepackage{etoolbox} % Required, for availablility changing the latex env.
% \usepackage{hyperref} % Show a green-border box on each \cite label?

% Pre-define list variables
\makeatletter
\newcommand*{\lodbib@citeorder}{} % Catch normal entries
\newcommand*{\lodbib@notcited}{} % Catch entries that were not cited

% Macro in aux file
\def\citation{%
  \forcsvlist{\citation@i}}

\def\citation@i#1{%
  \ifinlist{#1}{\lodbib@citeorder}
    {}
    {\listxadd{\lodbib@citeorder}{#1}}}

\let\ltxorig@lbibitem\@lbibitem
\let\ltxorig@bibitem\@bibitem

% Save bibitems into lists
\def\@lbibitem[#1]#2#3{%
  \csdef{lodbib@savedlabel@#2}{#1}%
  \@bibitem{#2}{#3}}

\def\@bibitem#1#2{%
  \xifinlist{#1}{\lodbib@citeorder}
    {}
    {\listadd{\lodbib@notcited}{#1}}%
  \csdef{lodbib@savedentry@#1}{#2}}

% Re-define \thebibiography command.
\renewenvironment{thebibliography}[1]
     {\settowidth\labelwidth{\@biblabel{#1}}}
     {\def\@noitemerr
       {\@latex@warning{Empty `thebibliography' environment}}%
      \chapter*{参考文献} % chapter title
       \@mkboth{参考文献}{参考文献} % left page header / right page header
      \list{\@biblabel{\@arabic\c@enumiv}}%
           {\leftmargin\labelwidth\parsep=0pt
            \advance\leftmargin\labelsep
            \@openbib@code
            \usecounter{enumiv}%
            \let\p@enumiv\@empty
            \renewcommand\theenumiv{\@arabic\c@enumiv}}%
      \sloppy
      \clubpenalty4000
      \@clubpenalty \clubpenalty
      \widowpenalty4000%
      \sfcode`\.\@m
      \lodbib@biblistloop
      \endlist}
      
% Output the bib list.
\def\lodbib@biblistloop{%
  \forlistloop{\lodbib@bibitem}{\lodbib@citeorder}%
  \ifdefvoid{\lodbib@notcited}
    {}
    {\forlistloop{
    \lodbib@bibitem 
    }{
    %\lodbib@notcited % Whether listing uncited bib at the end of the references?
    }}}
    
% Modify the \cite num. in the book.
\def\lodbib@bibitem#1{%
  \ifcsundef{lodbib@savedlabel@#1}
    {\ltxorig@bibitem{#1}}
    {\ltxorig@lbibitem[\csuse{lodbib@savedlabel@#1}]{#1}}%
  \csuse{lodbib@savedentry@#1}}
\fi

例如我有三条参考文献在paper.bib中:

@article{1966Calculation,
  ...
}

@article{1972Influence,
  ...
}

@article{2000The,
  ...
}

我在章节中使用:

\cite{1966Calculation,1972Influence,2000The}

这样的引用方式编译只能实现[1,2,3]的效果,如果我想实现[1-3]这样连续引用的效果要怎么做?

Edit by Sagittarius Rover

main中使用bst自动模式的参考文献引用方式

这句话实际上只是模板作者的口水话,指的就是令\refstyle\auto,此时默认的bibitem设置实际上仅有:

\bibliographystyle{references/gbt7714-2005}
\bibliography{references/paper.bib}
\addcontentsline{toc}{chapter}{参考文献}

因此,原问题如果只想要使用\auto方式进行设置的话,那么一个最小工作示例如下(这一步的简化本就应该由提问者给出,因此需要有一定的LaTeX使用经验才建议使用模板,切忌在项目期少于三个月的情况下作为新手从零开始套用模板):

\documentclass[12pt,a4paper,openany,twoside]{ctexbook}
\usepackage{geometry}
\begin{filecontents*}[overwrite]{paper.bib}
  @article{1966Calculation,
      author = {AAAA},
      year = {1966},
      title = {Calculation of the Influence of the Earth's Magnetic Field on the Magnetic Field of the Moon},
  }
  
  @article{1972Influence,
      author = {BBBB},
      year = {1972},
      title = {The Influence of Earth's Magnetic Field in Exploring the world},
  }
  @article{2000The,
      author = {CCCC},
      year = {2000},
      title = {The The The The paper named The The The},
  }
\end{filecontents*}
\begin{document}
\tableofcontents
\chapter{绪\quad 论}
\section{标题}
\subsection{副标题}
这是引用\cite{1966Calculation,1972Influence,2000The}的结果——我想我能吞下玻璃而不伤身体。

\bibliographystyle{gbt7714-2005}
\bibliography{paper.bib}
\addcontentsline{toc}{chapter}{参考文献}
\end{document}

其中\bibliographystyle{gbt7714-2005}使用的.bst文件来自:https://github.com/Haixing-Hu/GBT7714-2005-BibTeX-Style/commit/fd23fb5868fb7766a47d290ee513ca5cca547695
当有官方文件时,务必提供其来源方便追溯

编译效果如下:

image.png

查看更多

关注者
0
被浏览
138
Sagittarius Rover
我要成为Typst糕手/(ㄒoㄒ)/~~

请提供一个完整的可编译的文档例子,例如format.cls具体是什么,只提供一个切片很难回答这一问题。

由于你没有给完整的模板,相当于给了本回答很大的自由度

一个基于natbib的例子如下,需要使用pdf-bibtex-pdf-pdf或者latexmk -pdf命令编译:

\documentclass{article}
\begin{filecontents*}[overwrite]{reference.bib}
@article{1966Calculation,
    author = {AAAA},
    year = {1966},
    title = {Calculation of the Influence of the Earth's Magnetic Field on the Magnetic Field of the Moon},
}

@article{1972Influence,
    author = {BBBB},
    year = {1972},
    title = {The Influence of Earth's Magnetic Field in Exploring the world},
}
@article{2000The,
    author = {CCCC},
    year = {2000},
    title = {The The The The paper named The The The},
}
\end{filecontents*}
\usepackage[numbers,sort&compress]{natbib}
\bibliographystyle{unsrtnat}
\begin{document}
I want to cite these papaer at here\cite{1966Calculation,1972Influence,2000The} but not there!

\bibliography{reference}
\end{document}

image.png


Updated20250306

根据我自己给自己做的MWE(真是有够好笑了呢

\documentclass[12pt,a4paper,openany,twoside]{ctexbook}
\usepackage{geometry}
\begin{filecontents*}[overwrite]{paper.bib}
  @article{1966Calculation,
      author = {AAAA},
      year = {1966},
      title = {Calculation of the Influence of the Earth's Magnetic Field on the Magnetic Field of the Moon},
  }
  @article{1972Influence,
      author = {BBBB},
      year = {1972},
      title = {The Influence of Earth's Magnetic Field in Exploring the world},
  }
  @article{2000The,
      author = {CCCC},
      year = {2000},
      title = {The The The The paper named The The The},
  }
\end{filecontents*}
\usepackage[numbers,sort&compress]{natbib}%加上这一行即可...
\paperheight=15cm % 只是为了截图在同一张图内
\begin{document}

\tableofcontents
\chapter{绪\quad 论}
\section{标题}
\subsection{副标题}
这是引用\cite{1966Calculation,1972Influence,2000The}的结果——我想我能吞下玻璃而不伤身体。
\bibliographystyle{gbt7714-2005}
\bibliography{paper.bib}
\addcontentsline{toc}{chapter}{参考文献}
\end{document}

image.png

遇到模板给定了一大段设置的同时,在不确定很具体的依赖关系的时候,要给出上面的MWE实际上是相对困难而且花时间的,所以,最好不要修改模板,模板这样的设置"应该"是符合贵校规范的。

在看不懂模板设置的前提下,把这个问题定位并且抽象出来对直接套用模板(使用时间尚短)的用户来说简直就是一场灾难,基本上无解。

但是上面的简化又是必要的,不要期望有人会帮你看大段的模板,提问必须提供完整的可编译的代码(MWE),不然不应该提问

BTW,你是否看过基础教程lshort-zh-cn的6.1节....

1 个回答

撰写答案

请登录后再发布答案,点击登录

发布
问题

分享
好友

手机
浏览

扫码手机浏览