• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Avoid underline at the end of a line

Community Beginner ,
Dec 02, 2016 Dec 02, 2016

Copy link to clipboard

Copied

How can I avoid underlined spaces at the end of a line?

Screen Shot 2016-12-02 at 11.12.02.png

Views

2.0K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Mentor ,
Dec 02, 2016 Dec 02, 2016

Copy link to clipboard

Copied

You should be wayyy more specific... I bet that's the reason you didn't get any reply yet.

Right now the short answer could be "just don't apply your underline to unwanted characters".

If this occurs at the end of the story, you may try to trim unwanted trailing spaces with this GREP: \s+$

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Dec 02, 2016 Dec 02, 2016

Copy link to clipboard

Copied

Thank you for your reply.

It's not on the end of the story, it's a paragraph that has multiple lines. I want when the line breaks, the space that is at the end of the line is not underlined. It would be easier to do it through a grep code, than doing it manually.Screen-Shot-2016-12-02-at-12.03.54.png

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Mentor ,
Dec 02, 2016 Dec 02, 2016

Copy link to clipboard

Copied

Ah, I see your point now. It's multiline paragraph, right?

Unfortunately, there's no such code to find these specific spaces.

However, I'd be happy to stand corrected

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 02, 2016 Dec 02, 2016

Copy link to clipboard

Copied

It is built-in behavior of InDesign. I wrote a script to apply a temporary fix to this years ago: http://indesignsecrets.com/topic/removing-end-of-line-underlines-83 (which I didn't remember but actually found by typing in your question into a well-known internet search engine).

The script contains a few characters that did not survive the translation to forum-formatted HTML, so I'll repeat it below for convenience:

//DESCRIPTION: Begone, Ugly End Of Line Underlining!
// (c) Jongware 16-Dec-2009

var blankStyle = app.activeDocument.characterStyles.item("NoUnderline");

try { blankStyle.index; } catch(_)
{
blankStyle = undefined;
}

if (blankStyle == undefined)
{
blankStyle = app.activeDocument.characterStyles.add();
blankStyle.name = "NoUnderline";
blankStyle.underline = false;
} else
{
blankStyle.underline = false;
}

for (a=0; a<app.selection[0].lines.length; a++)
{
if (app.selection[0].lines.characters.item(-1).contents == " ")
app.selection[0].lines
.characters.item(-1).appliedCharacterStyle = blankStyle;
}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Mentor ,
Dec 02, 2016 Dec 02, 2016

Copy link to clipboard

Copied

Ah, marvelous! Especially I like the Description

Maybe it might be mentioned the changes are permanent (not live), so you should run this nice piece of code only once, right before Final Output...

Edit: ups, there's ChStyle created, so it's possible to "revert back" after reflow and repeat the whole procedure... Even nicier

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Dec 02, 2016 Dec 02, 2016

Copy link to clipboard

Copied

Thank you. I tried looking at InDesign Secrets forum, but I didn't see your reply.

Great, it works! Thank you.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 29, 2017 Mar 29, 2017

Copy link to clipboard

Copied

This script works. However, if you edit the text or adjust the width of the text box and wind up with different line breaks, where script fixed the underlined space now results in unintended gaps (without underlines) between words, which would require additional editing.

Essentially an example of text would look like this:

Original:

The quick brown fox

jumped over the lazy

dog.

After script and then line length adjustment:

The quick brown fox jumped over the lazy dog.

Notice the space between "fox" and "jumped" and "lazy" and "dog"?

Try it and you will see.

This issue is not present in Quark XPress.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Oct 09, 2023 Oct 09, 2023

Copy link to clipboard

Copied

I'm looking to do the same thing, except:

1. The customer wants to remove the unerline from spaces AND punctuation at the end of a line of text. See example below:

Aaroen22174073q6db_1-1696881788811.pngThe raw text.

Aaroen22174073q6db_2-1696881909097.pngWhat the customer wants.

 

2. Some lines and paragraphs will contain a varaible. Thus those lines will change during the VDP output.

I have used ChatGPT to write JavaScript to get me halfway there (remove underlines from spaces at the end of lines of text) but doesn't work on any punctuation.

Here is the code:

function removeUnderlinesAtEndOfParagraphs() {
  var doc = app.activeDocument;

  // Check if there is at least one story in the document
  if (doc.stories.length > 0) {
    for (var i = 0; i < doc.stories.length; i++) {
      var curStory = doc.stories[i];

      // Iterate through paragraphs in the story
      for (var p = 0; p < curStory.paragraphs.length; p++) {
        var paragraph = curStory.paragraphs[p];

        // Split the paragraph into lines
        var lines = paragraph.lines.everyItem().getElements();

        // Iterate through lines in the paragraph
        for (var l = 0; l < lines.length; l++) {
          var line = lines[l];

          // Get the last character in the line
          var lastCharIndex = line.characters.length - 1;

          // Check if lastCharIndex is valid (not negative)
          if (lastCharIndex >= 0) {
            var lastChar = line.characters[lastCharIndex];

            // Check if the last character is underlined and is either a space or a punctuation mark followed by a space
            if (lastChar.underline && /^[.,;!? ]+$/.test(lastChar.contents)) {
              lastChar.underline = false;
            }
          }
        }
      }
    }
  }
}

removeUnderlinesAtEndOfParagraphs(); // Call the function to remove underlines from spaces and punctuation at the end of lines

First: Is it even possible to do this through scripting?

Second: What do I need to change to get this code to work the way I need it to?

Any suggestions wouldbe greatly appreciated.

Thanks in advance.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 09, 2023 Oct 09, 2023

Copy link to clipboard

Copied

One possibility is to do two tests: whether a line ends in punctuation and a space and whether it ends in just a space. Like this:

 

lines = app.documents[0].
  stories.everyItem().
  lines.everyItem().getElements();

re1 = /[.,;:\x20]\s$/;
re2 = /[.,;:\x20]$/;

for (i = 0; i < lines.length; i++) {
  if (re1.test (lines[i].contents)) {
    lines[i].characters.itemByRange(-2,-1).underline = false;
  } else if (re2.test (lines[i].contents)) {
    lines[i].characters[-1].underline = false;
  }
}

 

A problem is that you can't remove underline from automatically inserted hyphens.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Oct 10, 2023 Oct 10, 2023

Copy link to clipboard

Copied

LATEST

Thanks! I think in those rare cases where there is a hyphen, we'll just go with it. Thank you so much!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines