如何在BibLaTeX中实现编辑书籍主标题大写并保留斜体
问题
参考@samcarter的方法后,已在BibLaTeX参考文献中实现文章、期刊及书籍标题的大写处理。但使用@InBook/@InCollection类型的bib条目时,章节标题大写正常,书籍主标题却未按需求大写。参考chicago-authordate.bbx代码添加\DeclareFieldFormat{booktitle}{\capitalisewords{#1}}后,书籍主标题虽实现大写,却丢失了原本的斜体格式。现需解决如何在保留斜体的同时实现书籍主标题的大写。
测试代码如下:
\documentclass{scrbook} \usepackage[utf8]{inputenc} \usepackage[T1]{fontenc} % Bibliography \usepackage[backend=biber, style=chicago-authordate, hyperref=auto, bibencoding=inputenc, refsection=chapter, doi=false, url=false, isbn=false, eprint=false]{biblatex} \usepackage[babel,autostyle=true]{csquotes} % Capitalize article titles and journal names \usepackage{mfirstuc} \MFUnocap{a} \MFUnocap{for} \MFUnocap{the} \MFUnocap{of} \MFUnocap{and} \MFUnocap{con} \MFUnocap{il} \DeclareFieldFormat{jtnoformat}{\capitalisewords{#1}} \DeclareFieldFormat{stnoformat}{\capitalisewords{#1}} \DeclareFieldFormat{booktitle}{\capitalisewords{#1}} \usepackage{xpatch} \xpatchbibmacro{mag+news+title}{\printfield[noformat]{title}}{\printfield[jtnoformat]{title}}{}{} \xpatchbibmacro{italtitle+stitle}{\printfield[tnoformat]{title}}{\printfield[jtnoformat]{title}}{}{} \begin{filecontents*}[overwrite]{sample.bib} @InBook{Goldthorpe1969, title = "herbert spencer", date = 1969, author = "John H. Goldthorpe", booktitle = "The founding fathers of social science", editor = "Timothy Raison", publisher = "Penguin Books", location = "Harmondsworth, UK"} @InCollection{Turner1999, author = "Bryan S. Turner and Ron Eyerman", title = "The sociology of generations", date = 1999, booktitle = "Classical sociology", publisher = "Sage", location = "London", chapter = 14, pages = "246--261"} \end{filecontents*} \addbibresource{sample.bib} \begin{document} \nocite{Goldthorpe1969}. \nocite{Turner1999}. \printbibliography \end{document}
解决方法
问题出在直接重新定义booktitle字段格式时,覆盖了chicago-authordate样式默认的斜体设置。要同时保留斜体和实现大写,有两种稳妥的方式:
方式一:在斜体命令内包裹大写处理
将原来的\DeclareFieldFormat{booktitle}{\capitalisewords{#1}}替换为:
\DeclareFieldFormat{booktitle}{\mkbibitalic{\capitalisewords{#1}}}
直接用BibLaTeX标准斜体命令\mkbibitalic包裹大写后的标题内容,还原默认的斜体格式。
方式二:用补丁修改原有格式(更推荐)
如果不确定样式默认的booktitle格式是否包含其他设置,使用xpatch包的\xpatchfieldformat命令修改原有格式,避免完全覆盖:
\usepackage{xpatch} \xpatchfieldformat{booktitle}{#1}{\capitalisewords{#1}}{}{}
这个命令会在保留原有格式的基础上,仅将字段内容替换为大写后的版本,兼容性更好。
修改后的完整代码示例:
\documentclass{scrbook} \usepackage[utf8]{inputenc} \usepackage[T1]{fontenc} % Bibliography \usepackage[backend=biber, style=chicago-authordate, hyperref=auto, bibencoding=inputenc, refsection=chapter, doi=false, url=false, isbn=false, eprint=false]{biblatex} \usepackage[babel,autostyle=true]{csquotes} % Capitalize article titles and journal names \usepackage{mfirstuc} \MFUnocap{a} \MFUnocap{for} \MFUnocap{the} \MFUnocap{of} \MFUnocap{and} \MFUnocap{con} \MFUnocap{il} \DeclareFieldFormat{jtnoformat}{\capitalisewords{#1}} \DeclareFieldFormat{stnoformat}{\capitalisewords{#1}} % 替换原来的booktitle定义,二选一即可 \DeclareFieldFormat{booktitle}{\mkbibitalic{\capitalisewords{#1}}} % 或者用方式二: % \xpatchfieldformat{booktitle}{#1}{\capitalisewords{#1}}{}{} \usepackage{xpatch} \xpatchbibmacro{mag+news+title}{\printfield[noformat]{title}}{\printfield[jtnoformat]{title}}{}{} \xpatchbibmacro{italtitle+stitle}{\printfield[tnoformat]{title}}{\printfield[jtnoformat]{title}}{}{} \begin{filecontents*}[overwrite]{sample.bib} @InBook{Goldthorpe1969, title = "herbert spencer", date = 1969, author = "John H. Goldthorpe", booktitle = "The founding fathers of social science", editor = "Timothy Raison", publisher = "Penguin Books", location = "Harmondsworth, UK"} @InCollection{Turner1999, author = "Bryan S. Turner and Ron Eyerman", title = "The sociology of generations", date = 1999, booktitle = "Classical sociology", publisher = "Sage", location = "London", chapter = 14, pages = "246--261"} \end{filecontents*} \addbibresource{sample.bib} \begin{document} \nocite{Goldthorpe1969}. \nocite{Turner1999}. \printbibliography \end{document}
内容的提问来源于stack exchange,提问作者Daniel
相关产品推荐
相关产品推荐

