Capitalizing texts in user interface
In English, generally titles have all words capitalised except for conjunctions (of, for, and etc.) and prepositions (like with.) User interface elements (buttons, titles, menu items) are formatted like titles.
I have a piece of software I'm using right now which has a "Tasks" menu and 3 items as follows:
- New task
- Delete Task
- Task Properties
The difference in capitalisation on "new task" stands out a mile for me - it just doesn't look "correct."
Any difference between str.capitalize() and str.title()?
title()
changes every word, but capitalize()
only the first word in a sentence:
>>> a = 'silly question'
>>> a.title()
'Silly Question'
>>> a.capitalize()
'Silly question'
>>>
Capitalize article title in latex
You can use the same format we used in your question yesterday for the title:
\documentclass[a4paper]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{lmodern}
\usepackage[english]{babel}
\usepackage{csquotes}
\usepackage[notes,backend=biber]{biblatex-chicago}
\addbibresource{sample.bib}
\usepackage{mfirstuc}
\DeclareFieldFormat{jtnoformat}{\capitalisewords{#1}}
\usepackage{xpatch}
\xpatchbibmacro{mag+news+title}{\printfield[noformat]{title}}{\printfield[jtnoformat]{title}}{}{}
\begin{document}
\title{The Chicago Citation Style with biblatex}
\author{WriteLaTeX}
\maketitle
\section{Demonstration}
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. \autocite{PP95} Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
\printbibliography
\end{document}
Or if you want to have proper title case:
\documentclass[a4paper]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{lmodern}
\usepackage[english]{babel}
\usepackage{csquotes}
\usepackage[notes,backend=biber]{biblatex-chicago}
\addbibresource{sample.bib}
\usepackage{mfirstuc}
\MFUnocap{a}
\MFUnocap{for}
\MFUnocap{the}
\MFUnocap{of}
\DeclareFieldFormat{jtnoformat}{\capitalisewords{#1}}
\usepackage{xpatch}
\xpatchbibmacro{mag+news+title}{\printfield[noformat]{title}}{\printfield[jtnoformat]{title}}{}{}
\begin{document}
\title{The Chicago Citation Style with biblatex}
\author{WriteLaTeX}
\maketitle
\section{Demonstration}
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. \autocite{PP95} Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
\printbibliography
\end{document}
How can I capitalize the first letter of each word in a string?
The .title()
method of a string (either ASCII or Unicode is fine) does this:
>>> "hello world".title()
'Hello World'
>>> u"hello world".title()
u'Hello World'
However, look out for strings with embedded apostrophes, as noted in the docs.
The algorithm uses a simple language-independent definition of a word as groups of consecutive letters. The definition works in many contexts but it means that apostrophes in contractions and possessives form word boundaries, which may not be the desired result:
>>> "they're bill's friends from the UK".title()
"They'Re Bill'S Friends From The Uk"
Capitalize HTML title tag
You can try this code it will work. I have tested this code.
<title><?php echo ucwords(strtolower(get_field('custompagetitle'))); ?>
Capitalizing titles
Building off of Josh Voigts comment:
def titleize(name)
lowercase_words = %w{a an the and but or for nor of}
name.split.each_with_index.map{|x, index| lowercase_words.include?(x) && index > 0 ? x : x.capitalize }.join(" ")
end
You might want make lowercase_words a constant and move it out of the function since they won't ever change.
Related Topics
More Concise Version of Max/Min Without the Block
Shortening Socket Timeout Using Timeout::Timeout(N) Does Not Seem to Work for Me
Does Anyone Have Parsing Rules for the Notepad++ Function List Plugin for Ruby and Rake
When to Use Keyword Arguments Aka Named Parameters in Ruby
How to Define a Simple Global Variable in an Rspec Test That Can Be Accesed by Helper Functions
Autoload Paths and Nested Services Classes Crash in Ruby
When Passing Objects as Parameters, Are They Passed by Reference
Why Won't Ruby Allow Me to Specify Self as a Receiver Inside a Private Method
Ruby + Tk Command Binding - Scope Issue
Activerecord User-Supplied Column Name
Rmagick Error After Installing Os X Mavericks
Ruby Regex to Capture Everything Between Two Strings (Inclusive)
Get All Keys in Hash with Same Value
Ruby on Rails: Converting "Somewordhere" to "Some Word Here"
Rake Test Very Slow in Windows
Transliteration with Iconv in Ruby