Skip to content

Commit

Permalink
Fix undefined \printbibliography error (fix #882)
Browse files Browse the repository at this point in the history
  • Loading branch information
zepinglee committed Jun 12, 2023
1 parent 87b667f commit 195aab5
Show file tree
Hide file tree
Showing 6 changed files with 116 additions and 60 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@
### Changed

- 不再插入 PDF 版书脊,改为编译生成([#551](https://github.com/tuna/thuthesis/issues/551))。
- 本科生附录的参考文献编译方式改为 `bibtex thuthesis-appendix-{a,b,c...}`,同研究生一致。

### Fixed

- 修正封面的职称字距问题([#879](https://github.com/tuna/thuthesis/discussions/879))。
- 解决了本科生附录的 `\printbibliography` 报错的问题([#882](https://github.com/tuna/thuthesis/discussions/882))。

## [v7.4.0] - 2023-05-15

Expand Down
14 changes: 9 additions & 5 deletions data/appendix-survey.tex
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,17 @@ \section{Equations}

\section{Citations}

Example citations in appendix.
\cite{abrahams99tex}
\cite{salomon1995advanced}
\cite{abrahams99tex,salomon1995advanced}
Example\cite{dupont1974bone} citations\cite{merkt1995rotational} in appendix
\cite{dupont1974bone,merkt1995rotational}.


% 默认使用正文的参考文献样式;
% 如果使用 BibTeX,可以切换为其他兼容 natbib 的 BibTeX 样式。
\bibliographystyle{unsrtnat}
\bibliography{ref/appendix}
% \bibliographystyle{IEEEtranN}

% 默认使用正文的参考文献 .bib 数据库;
% 如果使用 BibTeX,可以改为指定数据库,如 \bibliography{ref/refs}。
\printbibliography

\end{survey}
17 changes: 13 additions & 4 deletions data/appendix-translation.tex
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ \section{数学公式}

\section{文献引用}

文献引用示例\cite{abrahams99tex}。
附录\cite{dupont1974bone}中的参考文献引用\cite{merkt1995rotational}示例
\cite{dupont1974bone,merkt1995rotational}。


\appendix
Expand All @@ -70,14 +71,22 @@ \section{附录}


% 书面翻译的参考文献
% 默认使用正文的参考文献样式;
% 如果使用 BibTeX,可以切换为其他兼容 natbib 的 BibTeX 样式。
\bibliographystyle{unsrtnat}
\bibliography{ref/appendix}
% \bibliographystyle{IEEEtranN}

% 默认使用正文的参考文献 .bib 数据库;
% 如果使用 BibTeX,可以改为指定数据库,如 \bibliography{ref/refs}。
\printbibliography

% 书面翻译对应的原文索引
\begin{translation-index}
\nocite{salomon1995advanced}
\nocite{mellinger1996laser}
\nocite{bixon1996dynamics}
\nocite{carlson1981two}
\bibliographystyle{unsrtnat}
\bibliography{ref/appendix}
\printbibliography
\end{translation-index}

\end{translation}
5 changes: 3 additions & 2 deletions data/appendix.tex
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,9 @@ \section{数学表达式}
\end{equation}


\section{参考文献}
\section{文献引用}

附录中的参考文献示例(\cite{carlson1981two} 和 \cite{carlson1981two,taylor1983scanning,taylor1981study})。
附录\cite{dupont1974bone}中的参考文献引用\cite{zhengkaiqing1987}示例
\cite{dupont1974bone,zhengkaiqing1987}。

\printbibliography
14 changes: 0 additions & 14 deletions ref/appendix.bib

This file was deleted.

124 changes: 89 additions & 35 deletions thuthesis.dtx
Original file line number Diff line number Diff line change
Expand Up @@ -250,8 +250,8 @@
% \begin{shell}
% $ xelatex thuthesis-example.tex
% $ bibtex thuthesis-example.aux # 生成 bbl 文件
% $ bibtex thuthesis-example-survey.aux # 本科生的调研报告的参考文献
% $ bibtex thuthesis-example-translation.aux # 本科生的外文资料翻译的参考文献
% $ bibtex thuthesis-example-appendix-a.aux # 附录 A 的的参考文献
% $ bibtex thuthesis-example-appendix-b.aux # 附录 B 的的参考文献……
% $ bibtex thuthesis-example-index.aux # 本科生的书面翻译对应的原文索引
% $ xelatex thuthesis-example.tex # 解决引用
% $ xelatex thuthesis-example.tex # 生成论文 PDF
Expand Down Expand Up @@ -6312,38 +6312,96 @@
\newcommand\thu@end@appendix@ref@section{}
% \end{macrocode}
%
% 如果正文和附录引用了同一文献,\pkg{bibunits} 会给出无意义的警告,这里消除警告。
% \begin{macrocode}
% \end{macrocode}
%
% \pkg{bibunits} 在载入时会保存 \cs{bibliography} 和 \cs{bibliographystyle},
% 所以在载入宏包前修改定义。
% \begin{macrocode}
\AtBeginOfPackageFile*{bibunits}{
\def\bibliography#1{%
\if@filesw
\immediate\write\@auxout{\string\bibdata{\zap@space#1 \@empty}}%
% \end{macrocode}
%
% 正文的 \cs{bibliography} 同时设置附录参考文献的默认 \file{.bib} 数据库。
% \begin{macrocode}
\immediate\write\@auxout{\string\gdef\string\bu@bibdata{#1}}%
\fi
\@input@{\jobname.bbl}%
\gdef\bu@bibdata{#1}%
}
\def\bibliographystyle#1{%
\ifx\@begindocumenthook\@undefined\else
\expandafter\AtBeginDocument
\fi
{\if@filesw
\immediate\write\@auxout{\string\bibstyle{#1}}%
% \end{macrocode}
%
% 正文的 \cs{bibliographystyle} 同时设置附录参考文献的默认 \file{.bst} 样式。
% \begin{macrocode}
\immediate\write\@auxout{\string\gdef\string\bu@bibstyle{#1}}%
\fi}%
\gdef\bu@bibstyle{#1}%
}
}
\AtEndOfPackageFile*{bibunits}{
\ifthu@degree@graduate
\newcommand\thu@appendix@bib@num@format[1]{[\@Alph\c@chapter.#1]\hfill}
\g@addto@macro\appendix{%
\renewcommand\@bibunitname{\jobname-appendix-\@alph\c@chapter}%
\bibliographyunit[\chapter]%
\def\@startbibunit{%
\global\let\@startbibunitorrelax\relax
\global\let\@finishbibunit\@finishstartedbibunit
\global\advance\@bibunitauxcnt 1
\if@filesw
{\endlinechar-1
% \end{macrocode}
%
% 使附录 aux 文件的 \cs{gdef}\cs{@localbibstyle} 能够生效。
% \begin{macrocode}
\makeatletter
\@input{\@bibunitname.aux}}%
\immediate\openout\@bibunitaux\@bibunitname.aux
\immediate\write\@bibunitaux{\string\bibstyle{\@localbibstyle}}%
\fi
}
\def\bu@bibliography#1{%
\putbib[#1]%
}
\def\bu@bibliographystyle#1{%
\if@filesw
\immediate\write\@bibunitaux{\string\gdef\string\@localbibstyle{#1}}%
\fi
\gdef\@localbibstyle{#1}%
}
\providecommand\printbibliography{\putbib\relax}%
\g@addto@macro\appendix{%
\renewcommand\@bibunitname{\jobname-appendix-\@alph\c@chapter}%
\bibliographyunit[\chapter]%
\renewcommand\bibsection{%
\ctexset{section/numbering = false}%
\section{\bibname}%
\ctexset{section/numbering = true}%
}%
% \end{macrocode}
%
% 研究生附录的引用编号加前缀,如附录 A 的引用 [1] 为 [A.1]。
% \begin{macrocode}
\ifthu@degree@graduate
\renewcommand\citenumfont{\@Alph\c@chapter.}%
\renewcommand\bibsection{%
\ctexset{section/numbering = false}%
\section{\bibname}%
\ctexset{section/numbering = true}%
}%
\renewcommand\@extra@binfo{@-\@alph\c@chapter}%
\renewcommand\@extra@b@citeb{@-\@alph\c@chapter}%
\let\bibnumfmt\thu@appendix@bib@num@format
\let\bibliographystyle\defaultbibliographystyle
\let\bibliography\thu@appendix@bibliography
}
\renewcommand\thu@end@appendix@ref@section{%
\bibliographyunit\relax
}
\providecommand\printbibliography{\putbib\relax}%
\AtEndDocument{\thu@end@appendix@ref@section}
\renewcommand\bibnumfmt[1]{[\@Alph\c@chapter.#1]\hfill}%
\fi
}
\renewcommand\thu@end@appendix@ref@section{%
\bibliographyunit\relax
}
\AtEndDocument{\thu@end@appendix@ref@section}
% \end{macrocode}
%
% 如果正文和附录引用了同一文献,\pkg{bibunits} 会给出无意义的警告,这里消除警告。
% \begin{macrocode}
% \let\@xtestdef\@gobbletwo % This doesn't work
\def\bibunits@rerun@warning{\relax}
\fi
% \let\@xtestdef\@gobbletwo % This doesn't work
\def\bibunits@rerun@warning{\relax}
}
\PassOptionsToPackage{defernumbers = true}{biblatex}
\AtEndOfPackageFile*{biblatex}{
Expand All @@ -6366,6 +6424,9 @@
% \endrefsection
% }
\fi
\def\bibliographystyle#1{%
\thu@warning{'bibliographystyle' invalid for 'biblatex'.}%
}
}
% \end{macrocode}
%
Expand Down Expand Up @@ -6406,14 +6467,9 @@
\let\appendix\thu@appendix@appendix
\renewcommand\bibname{参考文献}%
\let\bibsection\thu@appendix@bibsection
\renewcommand\@bibunitname{\jobname-survey}%
\let\bibliographystyle\defaultbibliographystyle
\let\bibliography\thu@appendix@bibliography
\begin{bibunit}%
\startcontents[survey]%
}{%
\stopcontents[survey]%
\end{bibunit}%
\thu@reset@main@language % restore language
}
% \end{macrocode}
Expand Down Expand Up @@ -6455,14 +6511,12 @@
\section{\bibname}%
\endgroup
}%
\renewcommand\@bibunitname{\jobname-translation}%
\let\bibliographystyle\defaultbibliographystyle
\let\bibliography\thu@appendix@bibliography
\begin{bibunit}%
% \renewcommand\@bibunitname{\jobname-translation}%
% \let\bibliographystyle\defaultbibliographystyle
% \let\bibliography\thu@appendix@bibliography
\startcontents[translation]%
}{%
\stopcontents[translation]%
\end{bibunit}%
\thu@reset@main@language % restore language
}
% \end{macrocode}
Expand Down

0 comments on commit 195aab5

Please sign in to comment.