Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make the first letter of each word uppercase in sentence #651

Closed
hushidong opened this issue Nov 12, 2017 · 4 comments
Closed

Make the first letter of each word uppercase in sentence #651

hushidong opened this issue Nov 12, 2017 · 4 comments
Labels

Comments

@hushidong
Copy link

Biblatex provides \MakeCapital and \MakeSentenceCase which can make the first letter uppercase.

But how to make the first letter of each word uppercase in sentence ?

I find \capitalisewords provided by pkg mfirstuc , it works in document , like:

\documentclass[twocolumn]{article}
\usepackage{etoolbox}
\usepackage[backend=biber,style=numeric]{biblatex}%
\usepackage{mfirstuc}
\usepackage{xstring}
\addbibresource[location=local]{egbib.bib}

\begin{document}
\capitalisewords{Electronic resources : selection and bibliographic control}

\mkbibemph{\capitalisewords{Electronic resources : selection and bibliographic control}}

\capitalisewords{\mkbibemph{electronic resources : selection and bibliographic control}}

\strtowdudfa{Electronic resources : selection and bibliographic control}

\strtowdudfa{\mkbibemph{Electronic resources : selection and bibliographic control}}

\mkbibemph{\strtowdudfa{Electronic resources : selection and bibliographic control}}
\end{document} 

but can not work when used in \DeclareFieldFormat in a bbx file, like:

\DeclareFieldFormat{booktitle}{\capitalisewords{#1}}%

and I write a simple macro to implement the same goal, but it has the same problem, like:

\newrobustcmd{\strtowdudfa}[1]{%
	\edef\coefone{#1 $}
	%\meaning\coefone
	\expandafter\stowparsea@udf\coefone%
}

\def\stowparsea@udf#1 #2${%
	\def\coefone{#1}\def\coeftwo{#2}%
	%\par\meaning\coefone \meaning\coeftwo
	\ifx\coeftwo\@empty%
		\MakeSentenceCase{#1 }%
	\else%
		\MakeSentenceCase{#1 }%
		\def\coeftwos{#2$}%
		\expandafter\stowparsea@udf\coeftwos%
	\fi%
	}

when used in \DeclareFieldFormat, the error info is:

! Missing \endcsname inserted.
<to be read again>
			\protect
1.41 \printbibliography[heading=bibliography]

is there any way to solve this problem ?
or is there a new command added in biblatex can make the first letter uppercase of each word in sentence ?

@moewew
Copy link
Collaborator

moewew commented Nov 12, 2017

Use

\DeclareFieldFormat{titlecase}{\capitalisewords{#1}}

titlecase is applied to the contents of the field directly. The booktitle format is actually used as

\printtext[booktitle]{%
  \printfield[titlecase]{booktitle}%
  \setunit{\subtitlepunct}%
  \printfield[titlecase]{booksubtitle}}%

and so will run into expansion troubles.

@hushidong
Copy link
Author

Thank you !

As your illustration, I define a new field format for booktitle, and both \capitalisewords and \strtowdudfa works. like:

\DeclareFieldFormat{bkttlcase}{\strtowdudfa{#1}}%\capitalisewords\strtowdudfa
{\printtext[booktitle]{%
	   \printfield[bkttlcase]{booktitle}%
	   \setunit{\subtitlepunct}%
	   \printfield[titlecase]{booksubtitle}}%
	 \newunit}%

Thanks again!

@hushidong hushidong reopened this Nov 12, 2017
@moewew
Copy link
Collaborator

moewew commented Nov 12, 2017

BTW: The reason that biblatex does not provide a 'capitalise all words' macro is not only that it has been implemented elsewhere and is quite complicated to pull off correctly, but also that is is unusual to capitalise all words in a title. Often the choice is between sentence case (capitalise only the first word and proper nouns) and title case (most words are capitalised, but articles, short prepositions, conjunctions, and other 'small words' remain lower cased, Wikipedia). A title casing macro is much, much harder to implement in TeX and so the normal approach since BibTeX has been to give the title in title case in the .bib file, protect proper nouns and other parts of the title that must always be capitalised from case change and let the style apply sentence casing automatically.

@plk plk closed this as completed Nov 12, 2017
@hushidong
Copy link
Author

thanks

learned a lot in your reply,especially the knowledge about sentence case and title case.

according to my test, the title case can be implemented by the combination of \capitalisewords and \MFUnocap provided by mfirstuc.

  • first, enumerate all the articles,prepositions,conjunctions with \MFUnocap
  • then, use \capitalisewords to uppercase the first letter of the sentence, and other first letters of words in sentence which are not defined in \MFUnocap

this may be an alternative to the handwritting in .bib source file.

@moewew moewew added the invalid label Nov 18, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants