Non-breaking slash?

Discuss how to use the Ren'Py engine to create visual novels and story-based games. New releases are announced in this section.
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
Post Reply
Message
Author
User avatar
zmook
Veteran
Posts: 421
Joined: Wed Aug 26, 2020 6:44 pm
Contact:

Non-breaking slash?

#1 Post by zmook » Wed Aug 03, 2022 5:26 pm

Does renpy have markup for *preventing* line breaks at unwanted locations? In particular, I want to make renpy treat phrases like "km/h" and "AC/DC" as single words, not breakable at the slash.

Unicode has official non-breaking space and non-breaking hyphen characters, but apparently no non-breaking slash.

It looks like I can make it work by typing "A\uFEFF/\uFEFFC" instead of "A/C", but man, is that ugly.
colin r
➔ if you're an artist and need a bit of help coding your game, feel free to send me a PM

User avatar
m_from_space
Veteran
Posts: 302
Joined: Sun Feb 21, 2021 3:36 am
Contact:

Re: Non-breaking slash?

#2 Post by m_from_space » Thu Aug 04, 2022 12:59 am

You could write your own text tag.
https://www.renpy.org/doc/html/custom_text_tags.html

User avatar
zmook
Veteran
Posts: 421
Joined: Wed Aug 26, 2020 6:44 pm
Contact:

Re: Non-breaking slash?

#3 Post by zmook » Thu Aug 04, 2022 10:07 am

All right then. This works as long as there's no nested markup within the {nb}…{/nb} tags, which is good enough for my current purposes.

Code: Select all

    def non_breaking_tag(tag, argument, contents):
        """Insert unicode non-breaking zero-width code point between every content character."""
        rv = []
        for txi in contents:
            if txi[0] == renpy.TEXT_TEXT:
                rv.append((txi[0], "\uFEFF".join(txi[1])))
            else:
                rv.append(txi)
        return tuple(rv)
        
    config.custom_text_tags["nb"] = non_breaking_tag
colin r
➔ if you're an artist and need a bit of help coding your game, feel free to send me a PM

User avatar
Ocelot
Eileen-Class Veteran
Posts: 1882
Joined: Tue Aug 23, 2016 10:35 am
Github: MiiNiPaa
Discord: MiiNiPaa#4384
Contact:

Re: Non-breaking slash?

#4 Post by Ocelot » Thu Aug 04, 2022 10:35 am

zmook wrote:
Thu Aug 04, 2022 10:07 am
All right then. This works as long as there's no nested markup within the {nb}…{/nb} tags, which is good enough for my current purposes.
Be aware, that this wrecks autovoicing, and, as a consequence, reduces accessebility. It is fine if you are just using on abbreviations, just don't use it on actual words.

EDIT: I think, you can try WORD JOINER instead of ZERO-WIDTH NON-BREAKING SPACE. It might work better with automated readers.
< < insert Rick Cook quote here > >

User avatar
zmook
Veteran
Posts: 421
Joined: Wed Aug 26, 2020 6:44 pm
Contact:

Re: Non-breaking slash?

#5 Post by zmook » Thu Aug 04, 2022 6:31 pm

WORD JOINER, ok.

Code: Select all

                rv.append((txi[0], "\u2060".join(txi[1])))
colin r
➔ if you're an artist and need a bit of help coding your game, feel free to send me a PM

User avatar
Mihara
Regular
Posts: 119
Joined: Thu Mar 11, 2010 2:52 pm
Contact:

Re: Non-breaking slash?

#6 Post by Mihara » Sun Aug 28, 2022 5:33 am

Why not

Code: Select all

renpy.language_tailor('/',"WJ")
Where the '/' is whichever symbol that should be a non-breaking slash?

User avatar
Imperf3kt
Lemma-Class Veteran
Posts: 3636
Joined: Mon Dec 14, 2015 5:05 am
Location: Your monitor
Contact:

Re: Non-breaking slash?

#7 Post by Imperf3kt » Sun Aug 28, 2022 5:16 pm

What if you used a backward slash instead of a forward slash?

Code: Select all

    "AC\\DC"
    

https://www.renpy.org/doc/html/text.htm ... characters
Warning: May contain trace amounts of gratuitous plot.
pro·gram·mer (noun) An organism capable of converting caffeine into code.

Current project: GGD Mentor
Free Android GUI - Updated occasionally
Twitter
Imperf3kt Blackjack - a WIP blackjack game for Android made using Ren'Py

Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot], Majestic-12 [Bot]