Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6126439
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T16:22:26+00:00 2026-05-23T16:22:26+00:00

How can I format text in a natural language taking punctuation into account? The

  • 0

How can I format text in a natural language taking punctuation into account? The built-in gq command of Vim, or command line tools, such as fmt or par break lines without regard to punctuation. Let me give you an example,

fmt -w 40 gives not what I want:

we had everything before us, we had
nothing before us, we were all going
direct to Heaven, we were all going
direct the other way

smart_formatter -w 40 would give:

we had everything before us,
we had nothing before us,
we were all going direct to Heaven,
we were all going direct the other way

Of course, there are cases when no punctuation mark is found within the given text width, then it can fallback to the standard text formatting behavior.

The reason why I want this is to get a meaningful diff of text where I can spot which sentence or subsentence changed.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T16:22:27+00:00Added an answer on May 23, 2026 at 4:22 pm

    Here is a not very elegant, but working method I finally came up with. Suppose, a line break at a punctuation mark is worth 6 characters. It means, I’ll accept a result which is more ragged but contains more lines ending in a punctuation mark if the “raggedness” is less than 6 characters long. For example, this is OK (“raggedness” is 3 characters).

    Wait!
    He said.
    

    This is not OK (“raggedness” is more than 6 characters)

    Wait!
    He said to them.
    

    The method is to add 6 dummy characters after each punctuation mark, format the text, then remove the dummy characters.

    Here is the code for this

    sed -e 's/\([.?!,]\)/\1 _ _ _/g' | fmt -w 34 | sed -e 's/ _//g' -e 's/_ //g'
    

    I used _ (space + underscore) as a pair of dummy characters, supposing they’re not contained in the text. The result looks quite good,

    we had everything before us,
    we had nothing before us,
    we were all going direct to
    Heaven, we were all going
    direct the other way
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can I format a users text field input as they type and insert
Or, to be more clear, how can I format a block of text (in
I want to build a site where the user can enter text and format
How can I format the following line to eliminate StyleCop warnings: this.BeginInvoke(this.updateHandler,new object[]{this.tmpbuf}); Now,
In the TextBlock object you can format the text in the XAML like this:
Can anyone tell me ow to format the text/document before I send it to
For some reason i can not format the text of my date in a
I can't find documentation about how to format text in Bugzilla. Does Bugzilla support
I know that you can use boost serialization to serialize to a text format
I've got a RichTextBox in which I can format the text.. I can save

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.