我想使用宏将文本中标题的第一个单词大写\citetitle
,或者至少能够使用首字母大写的参考文献标题。
在参考书目条目中,标题的第一个单词是小写的,因此在文本中需要时可以将其引用为小写。因此,我借助重新定义,titlecase
以便\MakeSentenceCase
参考书目条目可以正确打印在参考文献部分。如果需要,单词可以用括号保护(参见:biblatex
手册,MakeSentenceCase
定义)。
我尝试过\Citetitle
但没有成功,但我不确定它到底起了什么作用。
我的目标是能够在法语标题开头处理大写问题(参见:J.-P. Lacroux,Orthotypographie 第 II 卷),但我故意把问题简单化了。
MWE,将使用 `(pdf)latex file.tex; biber file; (pdf)latex file.tex 生成:
\documentclass{article}
\usepackage[english]{babel}
\begin{filecontents*}{bib.bib}
@book{
mybook,
title= {title of the book},
author= {Author Name},
date= {2021-04-12},
}
@article{
myarticle,
title= {title of the article},
author= {Author Name},
date= {2021-04-12},
}
\end{filecontents*}
\usepackage[backend=biber]{biblatex}
\addbibresource{bib.bib}
\DeclareFieldFormat{titlecase}{\MakeSentenceCase*{#1}}
\begin{document}
\citetitle{mybook} ; \Citetitle{mybook}
\citetitle{myarticle} ; \Citetitle{myarticle}
\printbibliography
\end{document}
答案1
字段titlecase
格式不适用于。我们可以通过以下重新定义\citetitle
使其适用于citetitle
\documentclass{article}
\usepackage[english]{babel}
\usepackage[backend=biber]{biblatex}
\DeclareCiteCommand{\citetitle}
{\boolfalse{citetracker}%
\boolfalse{pagetracker}%
\usebibmacro{prenote}}
{\ifciteindex
{\indexfield{indextitle}}
{}%
\printtext[citetitle]{%
\printfield[titlecase]{labeltitle}}}
{\multicitedelim}
{\usebibmacro{postnote}}
\DeclareFieldFormat{titlecase}{\MakeSentenceCase*{#1}}
\begin{filecontents*}{\jobname.bib}
@book{mybook,
title = {title of the book},
author = {Author Name},
date = {2021-04-12},
}
@article{myarticle,
title = {title of the article},
author = {Author Name},
date = {2021-04-12},
}
\end{filecontents*}
\addbibresource{\jobname.bib}
\begin{document}
\citetitle{mybook}
\Citetitle{mybook}
\citetitle{myarticle}
\Citetitle{myarticle}
\printbibliography
\end{document}
如果您只想将第一个单词大写,\Citetitle
事情会更棘手一些。在这种情况下,我建议使用以下方法,它基于\MakeCapital
而不是\MakeSentenceCase
,这意味着它不会改变后续字母,也不会响应语言设置。
\documentclass{article}
\usepackage[english]{babel}
\usepackage[backend=biber]{biblatex}
\DeclareCiteCommand{\citetitle}
{\boolfalse{citetracker}%
\boolfalse{pagetracker}%
\usebibmacro{prenote}}
{\ifciteindex
{\indexfield{indextitle}}
{}%
\printtext[citetitle]{%
\printfield[ifcap]{labeltitle}}}
{\multicitedelim}
{\usebibmacro{postnote}}
\DeclareFieldFormat{ifcap}{\ifcapital{\MakeCapital{#1}}{#1}}
\begin{filecontents*}{\jobname.bib}
@book{mybook,
title = {title of the book},
author = {Author Name},
date = {2021-04-12},
}
@article{myarticle,
title = {title of the article},
author = {Author Name},
date = {2021-04-12},
}
\end{filecontents*}
\addbibresource{\jobname.bib}
\begin{document}
\citetitle{mybook}
\Citetitle{mybook}
\citetitle{myarticle}
\Citetitle{myarticle}
\printbibliography
\end{document}