Filter Question: APA Style Title Case Capitalization

Back to @Springer question here: on having more precise title case used in kookma Refnotes plugin and following the APA Style Guide, I started developing a wikitext solution. I would appreciate your input and your simpler solution here.

Trial 1
Giving a title (a sentence), produce the title capitalized according this two rules

  • In title case, major words are capitalized, and most minor words are lowercase.
    • major words: Nouns, verbs (including linking verbs), adjectives, adverbs, pronouns, and all words of four letters or more are considered major words.
    • minor words: Short (i.e., three letters or fewer) conjunctions, short prepositions, and all articles are considered minor words.
\define mytitle() Use it to keep your to-do list, to plan an essay or novel, or to organise your wedding. Record every thought that crosses your brain, or build a flexible and responsive website.

\define punc() . , ? ! ; :
\define major() [split[]]:except[enlist<punc>]:and[join[]length[]compare:number:gt[3]]


<$text text= {{{ 
[<mytitle>lowercase[]split[ ]first[]titlecase[]]
[<mytitle>lowercase[]split[ ]butfirst[]] :map[filter<major>titlecase[]else<currentTiddler>] :and[join[ ]]

}}} />

Produces:

Use it to Keep Your To-do List, to Plan an Essay or Novel, or to Organise Your Wedding. Record Every Thought That Crosses Your Brain, or Build a Flexible and Responsive Website.

Remarks

  • major is a filter to check the length of words excluding the punctuation attached to them, if the length is 4 and more, the word considered major and capitalized
  • The first word is always capitalized, so it is excluded from processing (see first and butfirst filter operator above)
  • The punc defines punctuations and can be completed

Todos - Need help
The above solution does not meet below requirements for capitalization, so give your solution! Consider simple to understand solutions please!

  • the first word of a subtitle
  • the first word after a colon, em dash, or end punctuation in a heading
  • major words, including the second part of hyphenated major words (e.g., “Self-Report,” not “Self-report”)

Trial 2

This version handles period when your title has two or three sentences. Still it does not support the “the first word after a colon, em dash, or end punctuation in a heading”

\define mytitle() Use it to keep your to-do list, to plan an essay or novel, or to organise your wedding. Record every thought that crosses your brain, or build a flexible and responsive website. 

\define punc() . , ? ! ; :
\define major() [split[]]:except[enlist<punc>]:and[join[]length[]compare:number:gt[3]]

\define handlewords()
[<currentTiddler>lowercase[]split[ ]first[]titlecase[]]
[<currentTiddler>lowercase[]split[ ]butfirst[]] :map[filter<major>titlecase[]else<currentTiddler>] :and[join[ ]]

\end


<$text text={{{

[<mytitle>split[.]] :map[subfilter<handlewords>] :and[join[.]]

}}}
/>

produces

Use it to Keep Your To-do List, to Plan an Essay or Novel, or to Organize Your Wedding. Record Every Thought That Crosses Your Brain, or Build a Flexible and Responsive Website.

Mohammad,

This is good progress towards a wikitext solution!

My first suggestion, if you go with a wikitext solution, is to break maintitle (the part before colon, usually) and subtitle into separate strings, and then recombine them as needed.

It might even be worth having an actual field for maintitle (or whatever you want to call it), set by a routine action (at time of import), but open to override. (And let the subtitle be whatever portion comes after that.) We don’t want to be stuck with confusion every time Refnotes deals with bibtex-titles like these (with multiple colons, or no colon):

Transfusion of plasma, platelets, and red blood cells in a 1:1:1 vs a 1:1:2 ratio and mortality in patients with severe trauma: The PROPPR randomized clinical trial

or

What do workers want? Employee interests, public interests, and freedom of expression under the National Labor Relations Act

Another reason to break out the maintitle as an available field is that there may be contexts in which we want to display (or concatenate) only the maintitle. Maybe I have a cascade for tiddler title area that displays the maintitle only (in Title Case), or that builds an automatic caption out of author, maintitle, and year.

I’d work with an actual list of the short words never to capitalize (except in first-word position):

a an the and but for if nor or so yet as* at by* for in of off* on per to up via

  • A few of these words sometimes function as adverbs, in which case they should remain capitalized in title case. But now we’re getting into the weeds, and even I wouldn’t worry much about it! Anything super-formal needs to be reviewed and tweaked anyway.

Although all the words above have fewer than four letters, there’s no point in checking the length, because some very short words are still capitalized in title case: Jupiter and His Red Spot; …: Where We Are and What Needs to Be Done?; It Seems As If… I Am Dead)

Sorry I’m not able to try tinkering with actual filters today. I appreciate that you’re going ahead full-steam with this!

Hi @Springer,

I think this is a complex WikiText project. I try to partially improve APA titlecase, but having wikitext to do all the job is absolutely time-consuming and tedious.

What is my own experience?
Actually, I do not manually enter bibliography data. I always get them from Mendeley, Google Scholar and Scopus. When exporting, I use the APA style. In simple words, I just try to store them in correct format. I know there is a big pitfall here: what if I want to use them in other style?

There was some discussion previously on Bibliography style in Refnotes. It seems a better solution is to use one of the existing JS libraries for styling bibliography. I will add reference to those discussion and library later on.

By the way I welcome any volunteer work on adding wikitext solution or JS solution to Refnotes.

See BibTeX and APA style with more flexibility - #4 by Zheng_Bangyou

1 Like

See:

Juris-M/citeproc-js: A JavaScript implementation of the Citation Style Language (CSL) https://citeproc-js.readthedocs.io (github.com)

Citation Style Language - Citation Style Language (citationstyles.org)

I hope some day TiddlyWiki can have a simple citation manager like this:

Demo: Editor — citeproc-js 1.1.73 documentation. See how simple you can add/edit citation.

Trial 3

\define mytitle() Use it to keep your to-do list, to plan an essay or novel, or to organise your wedding. Record every thought that crosses your brain, or build a flexible and responsive website. 


\define punc() . , ? ! ; :
\define major()  [split[]]:except[enlist<punc>]:and[join[]length[]compare:number:gt[3]]

\define pat() \w+[-]+\w+(-\w*)?
\define hyphenated-major()  [split[-]last[]split[]]:except[enlist<punc>]:and[join[]length[]compare:number:gt[3]]

\define hyphen()
[regexp<pat>filter<hyphenated-major>split[-]titlecase[]join[-]else{!!title}]
\end


\define handlewords()
[<currentTiddler>split[ ]first[]titlecase[]]
[<currentTiddler>split[ ]butfirst[]] :map[filter<major>titlecase[]else<currentTiddler>]
:map:flat[subfilter<hyphen>]
:and[join[ ]]
\end

\define apa-titlecase(title)
<!-- 
step 1: convert to lowercase
step 2: split on sentences (based on period)
step 3: handle words (based on major and minor and hyphen)
-->
<$text text={{{

[<__title__>lowercase[]split[.]] 
:map[subfilter<handlewords>]
:and[join[.]]

}}}
/>
\end

!! Example
<$macrocall $name=apa-titlecase title=<<mytitle>> />

Lessons to learn: TiddlyWiki :map filter run prefix allows to run sequence of filter expressions and build pipeline (see Is it the Time to Have Pipeline in TiddlyWiki Filter Language? - Discussion - Talk TW)

Candidate solution
This version handles most cases in APA title style. Still there are some cases have not been covered.

step 1: convert to lowercase
step 2: split on sentences (based on period)
step 3: handle words (based on major and minor and hyphen)
step 4: handle colon (any word after colon major or minor is titlecase)

\define mytitle() Use it to keep your to-do list, to plan an essay or novel, or to organise your wedding. Record every thought that crosses your brain, or build a flexible and responsive website.


\define punc() . , ? ! ; :
\define major()  [split[]]:except[enlist<punc>]:and[join[]length[]compare:number:gt[3]]

\define pat() \w+[-]+\w+(-\w*)?
\define hyphenated-major()  [split[-]last[]split[]]:except[enlist<punc>]:and[join[]length[]compare:number:gt[3]]

\define hyphen()
[regexp<pat>filter<hyphenated-major>split[-]titlecase[]join[-]else{!!title}]
\end


\define handlewords()
[split[ ]first[]titlecase[]]
[split[ ]butfirst[]] :map[filter<major>titlecase[]else<currentTiddler>]
:map:flat[subfilter<hyphen>]
:and[join[ ]]
\end

\define colon-parts() [split[ ]first[]titlecase[]] [split[ ]rest[]] :and[join[ ]]

\define handlecolon()
[regexp[:]split[: ]]
:map[subfilter<colon-parts>]
:and[join[: ]]
:else[<currentTiddler>]
\end

\define apa-titlecase(title)
<!-- 
step 1: convert to lowercase
step 2: split on sentences (based on period)
step 3: handle words (based on major and minor and hyphen)
step 4: handle colon (any word after colon major or minor is titlecase)
-->
<$text text={{{

[<__title__>lowercase[]split[.]] 
:map[subfilter<handlewords>]
:and[join[.]]
:map[subfilter<handlecolon>]
}}}
/>
\end

!! Example
<$macrocall $name=apa-titlecase title=<<mytitle>> />


!! Other tests

<$macrocall src="""

<$let mytitle="example of hyphenated words with puct. hey-moh, call-me.">
<$macrocall $name=apa-titlecase title=<<mytitle>> />
</$let>

"""$name=wikitext-example/>

<$macrocall src="""

<$let mytitle="example of colon: a test, brown: is color.">
<$macrocall $name=apa-titlecase title=<<mytitle>> />
</$let>

"""$name=wikitext-example/>


@@.todo
[ ] The word after colun shall be titlecase. This code does not handle it
@@

That seems at odds with @springer’s initial example:

It looks to me like the part after the colon should be sentence case (first word capitalized, others lower.) Am I missing something?

Scott, I think I was just wrong on that one. :zipper_mouth_face: The title casing should be consistent all the way through the subtitle.