Search Unity

TextMesh Pro Text Line Break also is a Page Break.

Discussion in 'UGUI & TextMesh Pro' started by vhman, Jul 10, 2019.

  1. vhman

    vhman

    Joined:
    Aug 13, 2018
    Posts:
    355
    Hi,

    According to my understanding (and https://www.w3schools.com/tags/tag_br.asp)
    "Line Break" - force line break, not to separate paragraph.

    I have an issue with "Line Break". Both \n and <br> give paragraph break. I'm using TMP 2.0.1
    How a can break line without paragraph break (similar to SHIFT+ENTER in rich text editors)
    upload_2019-7-10_17-43-30.png
     
  2. MSplitz-PsychoK

    MSplitz-PsychoK

    Joined:
    May 16, 2015
    Posts:
    1,278
    Unfortunately I'm pretty sure the only thing TextMesh counts as a "new line" instead of a "new paragraph" is a newline caused by word wrapping.

    This is a quote from the documentation "Paragraphs are defined by explicit line breaks".
    You can find the quote here under "Spacing Options" http://digitalnativestudios.com/textmeshpro/docs/textmeshpro-component/

    Side note: "\r" seems to draw a new line of text over the current line of text, and isn't affected by spacing. Doesn't seem very helpful. o_O
     
    vhman likes this.
  3. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    The escape character \n or Line Feed indicate the end of a line of text and start of a new one. It also represents the end of a paragraph or hard line break.

    The <br> tag is an html convention used to introduce a line break or new line which is the same as \n.

    The escape character \r or Carriage Return simply return the carriage back to the start of the line but without adding a new line. This is the purpose of that control character.

    The following text "This is the first line of text.\nThis is the second line of text." produces the following results.

    upload_2019-7-10_18-3-5.png

    As you can see the use of \n does not introduce an additional line.

    Perhaps in your original text, the text already contained a line feed + the extra \n resulting in the extra line.

    P.S. In the Inspector text input box, it is easier to simply press Enter to insert a line feed rather than using \n. In strings however, \n is the way to go.
     
    Last edited: Jul 11, 2019
  4. vhman

    vhman

    Joined:
    Aug 13, 2018
    Posts:
    355
    Hi, @Stephan_B

    "As you can see the use of \n does not introduce an additional line." - Yes, it does not introduce an additional line.
    But as you can see from the picture, I have SpacingOption/Paragraph=50.
    In conventional rich text editor I can control "line break" and "paragraph break".
    Seems @Gambit-MSplitz is right, in TextMesh Pro "Paragraphs are defined by explicit line breaks."
    upload_2019-7-11_13-10-28.png
     
  5. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    I just looked into this briefly and ran into the following challenge.

    Here is an image from Microsoft Word with Paragraph and delimiters set to visible.

    upload_2019-7-11_12-43-2.png

    Selecting this text to check the ASCII values produces "65, 66, 67" which is as expected.

    Next pressing Enter after the letter B produces the following image.

    upload_2019-7-11_12-44-56.png
    Checking the ASCII values of the result produces the following ASCII sequence "65, 66, 13, 10, 67" which is also as expected.

    Next instead of pressing Enter after the B, this time I pressed Shift Enter to insert a soft line break.

    upload_2019-7-11_12-48-36.png
    Checking the ASCII values again produced the following ASCII sequence "65, 66, 13, 10, 67" which is identical to the previous sequence.

    The challenge here is the fact there is no differentiation between these two.

    Looking like \v which is a vertical tab does insert a soft line break just like using Shift Enter in word. So I could certainly consider adding support for \v.

    Thoughts?

    P.S. Shift Enter is not currently supported in text fields in the Unity editor which could be explored to make it easier to enter the equivalent to \v.
     
    Last edited: Jul 11, 2019
  6. vhman

    vhman

    Joined:
    Aug 13, 2018
    Posts:
    355
  7. Wappenull

    Wappenull

    Joined:
    Oct 29, 2013
    Posts:
    51
    Pardon me to dig an old thread.

    I'm surprised that I'm not aware of \v exist despite I'm using Unity and TMP for ~8 years! And it is working in 2022!
    Along side with useful secret tags <nbsp> <zwsp> <nobr></nobr> which appear briefly only in Stephan_B's thread or in TMP change note.

    Which the <zwsp> one is super important for some Asian language to manually insert word break point like Thai. (like "สวัสดี<zwsp>ครับ") I saw newcomers in our community always ask how to manually insert word break point all the time, because they don't aware of these secret tags at all.

    I suggest @Stephan_B to maybe update those well known landing pages from Google search like:
    http://digitalnativestudios.com/textmeshpro/docs/rich-text/
    https://docs.unity3d.com/Packages/com.unity.textmeshpro@4.0/manual/RichText.html

    I don't know if you still have control to content in these links or they already obsolete, but yeah I it was from my experience as user and I think 70% of users will land on above pages for reference from search result most of the time. (which did not contain info for valuable \v or secret tags secret tags <nbsp> <zwsp> <nobr></nobr> at all)

    The first link is where I landed and use for reference the most.
     
    zhaozony likes this.
  8. zhaozony

    zhaozony

    Joined:
    Jan 7, 2020
    Posts:
    29
    agree! Same thing here!