CTeX-org / forum

A temporarily alternate forum of `bbs.ctex.org`
https://t.me/chinesetex
Apache License 2.0
210 stars 16 forks source link

`xampl.bib` 无法用于 `gbt7714` 包和 `natbib` 的 `authoryear` 模式吗? #315

Open OsbertWang opened 5 months ago

OsbertWang commented 5 months ago

检查清单

操作系统

Windows 11

TeX 发行版

TeX Live 2024

描述问题

今天本意是用 xampl 制作一个示例,结果发现编译出现问题。一共做了4个示例,其中3个编译错误,1个编译通过,如下所示。 我的猜测是,xampl.bib 无法用于 gbt7714 包和 authoryear 模式吗?

最小工作示例(MWE)

\documentclass{ctexart}
\usepackage{gbt7714}
\bibliographystyle{gbt7714-author-year}
\citestyle{authoryear}

\begin{document}

\nocite{*}

\bibliography{xampl}
\end{document}

latexmk -pdfxe 编译后,日志文件输出:

Runaway argument?
Knuth({\)]{whole-set} KNUTH D~E, {\. \newblock Four volumes: The art \ETC.
! Paragraph ended before \@lbibitem was complete.
<to be read again>
                   \par
l.62

?

后又做了如下 MWE:

\documentclass{ctexart}
\usepackage{gbt7714}
\bibliographystyle{gbt7714-numerical}
\citestyle{numbers}

\begin{document}

\nocite{*}

\bibliography{xampl}
\end{document}

latexmk -pdfxe 编译后,日志文件输出:

Runaway argument?
Knuth({\noo )]{inbook-minimal} KNUTH D~E. \newblock Fundamental algor\ETC.
! Paragraph ended before \@lbibitem was complete.
<to be read again>
                   \par
l.40

?

其它尝试

最后我不用 gbt7714 试了试,MWE 如下:

\documentclass{article}
\usepackage[authoryear]{natbib}
\bibliographystyle{abbrvnat}

\begin{document}

\nocite{*}

\bibliography{xampl}
\end{document}

latexmk -pdf 编译后,日志文件输出:

! Missing = inserted for \ifnum.
<to be read again>
                   \def
l.34 ...3a}}{\switchargs{--90}{1968}})]{whole-set}

?

最后发现只有如下 MWE 可以编译通过:

\documentclass{article}
\usepackage[numbers]{natbib}
\bibliographystyle{abbrv}

\begin{document}

\nocite{*}

\bibliography{xampl}
\end{document}

链接

No response

其他信息

No response

附件

No response

muzimuzhi commented 5 months ago

生成的 .bbl 里也许有更直接的「为什么报错」的痕迹。这样还可以把 \nocite{*} 缩小到特定的 \cite.

严格来说,每一个 bst 对应一个 bib 规范,所以同一个 bib 在某些 bst 里报错是有可能的。

OsbertWang commented 5 months ago

gbt7714 时,我找了一下 .bbl 文件,问题出现在 Knuth({\) 这里的 { 符号,我还不清楚它怎么出现的,而且出现这种问题的条目还不止一个。 至于 natbib 的情况,问题出现在 \bibitem[Knuth({\noopsort{1973a}}{\switchargs{--90}{1968}})]{whole-set} 这里。

muzimuzhi commented 5 months ago

试试把相关 bib 条目抽出来,简化例子?

gbt7714 的问题可以反馈到 https://github.com/zepinglee/gbt7714-bibtex-style

zepinglee commented 5 months ago

我研究了一下,问题出在 extract.before.slash 函数中,这里想处理 1984/2024 这样的时间区间,需要找出 / 前的内容。

但是对于 whole-setyear = "{\noopsort{1973a}}{\switchargs{--90}{1968}}",bst 的 text.length$ 认为其长度为 2({\...} 算一个“特殊字符”),而 substring$ 操作又不处理“特殊字符”,导致最后输出的只有残缺的 {\

zepinglee commented 5 months ago

另外我发现只使用 natbib + xampl.bib 也会报错。感觉 xampl.bib 可能主要是测试 bibtex 用的,但不是很好的例子。使用纯 bibtex 生成的带方括号的名字也是十分怪异。

\documentclass{article}
\usepackage{natbib}
\bibliographystyle{plainnat}
\begin{document}
\nocite{*}
\bibliography{xampl}
\end{document}
./gbt7714-2015-examples.bbl:34: Missing = inserted for \ifnum.
<to be read again> 
                   \def 
l.34 ...3a}}{\switchargs{--90}{1968}})]{whole-set}
Screenshot 2024-04-27 at 15 22 11
OsbertWang commented 5 months ago

根据 tex.se 上提供的内容,如下代码用 latexmk -pdf 正常编译

\documentclass{article}
\usepackage[authoryear]{natbib}

\makeatletter
\let\NAT@bare@aux\NAT@bare
\def\NAT@bare#1(#2){%
 \begingroup\edef\x{\endgroup
   \unexpanded{\NAT@bare@aux#1}(\@firstofone#2)}\x}
\makeatother

\bibliographystyle{plainnat}

\begin{document}

\nocite{*}

\bibliography{xampl}
\end{document}
zepinglee commented 5 months ago

根据 tex.se 上提供的内容,如下代码用 latexmk -pdf 正常编译

嗯, 有个这个 patch 后 gbt7714 可以顺利编译 xampl.bib 了,见 https://github.com/zepinglee/gbt7714-bibtex-style/commit/0b1ae2c361d79294fcc86f4d151d4b91f8010ea0

muzimuzhi commented 5 months ago

使用 TeX Live 2019 添加的、l3kernel 2023-05-15 开始依赖的 primitive \expanded,对 \NAT@bare 的重定义可以改写为(我也评论在那个 TeX-SX 回答下了)

\documentclass{article}
\usepackage[authoryear]{natbib}

\makeatletter
% based on https://tex.stackexchange.com/a/39718
\let\NAT@bare@aux\NAT@bare
\def\NAT@bare#1(#2){%
  \expanded{\unexpanded{\NAT@bare@aux#1}(\@firstofone#2)}}
\makeatother

\bibliographystyle{plainnat}

\begin{document}

\nocite{*}

\bibliography{xampl}
\end{document}