Title Case
Title Case
Searching the web for an algorithm to convert text to Title Case, I discovered a Perl script written by John Gruber and Aristotle Pagaltzis:
https://github.com/ap/titlecase/blob/master/titlecase
I would like to embed this Perl script into a NWP macro so I can apply it to the current selection in a document. However, I don't know enough about Perl to figure out where the input variable is in this script. (I can see that the output variable is named $_.)
Martin, would it be too much trouble for you to provide the NWP macro steps that should surround this Perl script?
Thanks a million!
https://github.com/ap/titlecase/blob/master/titlecase
I would like to embed this Perl script into a NWP macro so I can apply it to the current selection in a document. However, I don't know enough about Perl to figure out where the input variable is in this script. (I can see that the output variable is named $_.)
Martin, would it be too much trouble for you to provide the NWP macro steps that should surround this Perl script?
Thanks a million!
- martin
- Official Nisus Person
- Posts: 5230
- Joined: 2002-07-11 17:14:10
- Location: San Diego, CA
- Contact:
Re: Title Case
EDIT: this macro was removed because it had shortcomings. See below for a fixed version of the macro.
- martin
- Official Nisus Person
- Posts: 5230
- Joined: 2002-07-11 17:14:10
- Location: San Diego, CA
- Contact:
Re: Title Case
Ah yes. That character \xC2 is a non-breaking space, introduced by the forum when you copy-paste code from the web. Perl doesn't like it. You can fix it by replacing all non-breaking spaces in the macro with regular spaces. Or download the macro I'll attach here.
...
EDIT: this macro was removed because it had shortcomings. See below for a fixed version of the macro.
...
EDIT: this macro was removed because it had shortcomings. See below for a fixed version of the macro.
Unicode
Perfect! Thanks!
Another question: How could I have figured out that \xC2 means non-breaking space?
I typed c2 or C2 or \xC2 in a NWP document, selected it, and attempted to use the menu command Edit > Convert > From Unicode Code Points, but the command was grayed out. I cannot figure out how to make this command active.
I also tried using the OS X Character Viewer to view the Unicode Code Table. I must be interpreting this incorrectly, because Unicode 00C2 appears to be "capital A with circumflex".
Another question: How could I have figured out that \xC2 means non-breaking space?
I typed c2 or C2 or \xC2 in a NWP document, selected it, and attempted to use the menu command Edit > Convert > From Unicode Code Points, but the command was grayed out. I cannot figure out how to make this command active.
I also tried using the OS X Character Viewer to view the Unicode Code Table. I must be interpreting this incorrectly, because Unicode 00C2 appears to be "capital A with circumflex".
- martin
- Official Nisus Person
- Posts: 5230
- Joined: 2002-07-11 17:14:10
- Location: San Diego, CA
- Contact:
Re: Title Case
Actually, you're correct Bob, U+00C2 is a capital A with circumflex. I didn't actually look up the character/code, I just knew Perl doesn't like non-breaking spaces and assumed the \xC2 mentioned in Perl's error message was the code for a non-breaking space.
Perl's error message should probably be clarified. When it says "unrecognized character", it really means unrecognized byte in the UTF-8 steam/data. A non-breaking space must be encoded in UTF-8 using a two byte sequence: 0xC2 0xA0. Perl's error only reports that leading byte, even though it's only the first half of the proper Unicode character. It may be that Perl doesn't really deal with full Unicode characters outside of string literals/data, even when declaring "use utf8;"
Perl's error message should probably be clarified. When it says "unrecognized character", it really means unrecognized byte in the UTF-8 steam/data. A non-breaking space must be encoded in UTF-8 using a two byte sequence: 0xC2 0xA0. Perl's error only reports that leading byte, even though it's only the first half of the proper Unicode character. It may be that Perl doesn't really deal with full Unicode characters outside of string literals/data, even when declaring "use utf8;"
Edit > Convert > From Unicode Code Points
Thanks for the clarification, Martin.
FYI, I just used the Feedback reporter to report as a bug that fact that "Edit > Convert > From Unicode Code Points" is always greyed out.
FYI, I just used the Feedback reporter to report as a bug that fact that "Edit > Convert > From Unicode Code Points" is always greyed out.
Re: Title Case
Bob. a string has to have the form U+xxxx for the "Edit > Convert > From Unicode Code Points" to work.
Of course I agree that they could make it more user-friendly.
Of course I agree that they could make it more user-friendly.
philip
Thanks, Philip!
The U+ prefix worked.
Nisus should add that to the user guide.
Nisus should add that to the user guide.
- martin
- Official Nisus Person
- Posts: 5230
- Joined: 2002-07-11 17:14:10
- Location: San Diego, CA
- Contact:
Re: Title Case
Thanks for the feedback report Bob, glad you have it working. I agree that it should be more lenient in what forms it accepts; being as liberal as possible would be best.
Re: Title Case
Hi,
I was excited to find this macro. I found a bug, which I thought I would report. (I'm not much of a scripter, so I can't fix the issue myself.)
The macro failed with a carriage return between lines.
Example- input text:
Yields this result:
i.e. just lopped off everything after the carriage return. Does the same thing when I change it to only 1 carriage return for the first blank space instead of 2.
When I turn on "View > Show Invisibles," it displays the blank lines with a paragraph symbol.
For now I can work around it just fine, but just thought I would mention it in case further development happens with this macro.
thanks
sb
I was excited to find this macro. I found a bug, which I thought I would report. (I'm not much of a scripter, so I can't fix the issue myself.)
The macro failed with a carriage return between lines.
Example- input text:
Code: Select all
journal of nervous and mental disease
psychotherapy and psychosomatics
journal of humanistic psychology
journal of transpersonal psychology
bipolar disorders
journal of affective disorders
Code: Select all
Journal of Nervous and Mental Disease
Psychotherapy and Psychosomatics
Journal of Humanistic Psychology
Journal of Transpersonal Psychology
When I turn on "View > Show Invisibles," it displays the blank lines with a paragraph symbol.
For now I can work around it just fine, but just thought I would mention it in case further development happens with this macro.
thanks
sb
- martin
- Official Nisus Person
- Posts: 5230
- Joined: 2002-07-11 17:14:10
- Location: San Diego, CA
- Contact:
Re: Title Case
Thanks for letting us know skyblue. Here's an amended macro that doesn't suffer from this problem.skyblue wrote:The macro failed with a carriage return between lines.
...
i.e. just lopped off everything after the carriage return.
- Attachments
-
TitleCase.nwm
- (21.16 KiB) Downloaded 1604 times
Re: Title Case
Much later... Thanks for this.
User since 1990
Most current NWp and MacOS
MacBookPro 16-inch 2023
Most current NWp and MacOS
MacBookPro 16-inch 2023