No hyphenation in hyphenated block

latex no hyphenation in paragraph
css hyphens not working
word-break with hyphen css
css hyphens not working in chrome
css prevent word-break hyphen
latex prevent hyphenation in table
@hyphenation-resource
hyphenate-character

Is there a possibility to disable hyphenation for a text snippet inside a fo:block? My problem is That it’s not possible to set hyphenate="false" on fo:inline because it’s not a property. And fo:block inside fo:block creates a new line...

Fo-Example:

<fo:block hyphenate="true">
This text should be hyphenated <fo:inline hyphenate="false">This text shouldn’t be hyphenated</fo:inline>
</fo:block>

UPDATE:

I tried the soulution Posted by @DanielNorberg because none of all solutions worked properly. It seems to be kind of a workaround but still not delivering the output i would like to get.

I use this template:

<xsl:template match="text()[ancestor::span[@class='nobreak']]">
    <xsl:param name="text"><xsl:value-of select="." /></xsl:param>
    <fo:inline hyphenate="false" color="red">
        <xsl:for-each select="tokenize(replace(replace($text,'(.)','$1\\n'),'\\n$',''),'\\n')">
        <fo:inline keep-with-next.within-line="always">
            <xsl:value-of select="."/>
            <fo:character font-size="0pt">
                <xsl:value-of select="' '" />
            </fo:character>
        </fo:inline>
        </xsl:for-each>
    </fo:inline>
</xsl:template>

The fo part looks like this

<fo:block xmlns:fn="http://www.w3.org/2005/xpath-functions" space-after="14pt">
    <fo:block text-align-last="left" font-size="10pt" color="black" text-align="justify"
        font-family="ITCFranklinGothicStd-Book" line-height="14pt" wrap-option="wrap">
        <fo:block hyphenate="true" xml:lang="de">
            <fo:block>Die Entwicklung der folgenden Jahre bestätigte unsere Auffassung. Nicht nur erwiesen
                sich die <fo:inline hyphenate="false" color="red">
                    <fo:inline keep-with-next.within-line="always">T<fo:character font-size="0pt"> </fo:character></fo:inline>
                    <fo:inline keep-with-next.within-line="always">r<fo:character font-size="0pt"> </fo:character></fo:inline>
                    <fo:inline keep-with-next.within-line="always">e<fo:character font-size="0pt"> </fo:character></fo:inline>
                    <fo:inline keep-with-next.within-line="always">i<fo:character font-size="0pt"> </fo:character></fo:inline>
                    <fo:inline keep-with-next.within-line="always">b<fo:character font-size="0pt"> </fo:character></fo:inline>
                    <fo:inline keep-with-next.within-line="always">e<fo:character font-size="0pt"> </fo:character></fo:inline>
                    <fo:inline keep-with-next.within-line="always">r<fo:character font-size="0pt"> </fo:character></fo:inline>
                </fo:inline>
            </fo:block>
        </fo:block>
    </fo:block>
</fo:block>

So the word "Treiber" should not be hyphenated. But the PDF output looks the following:

SOLUTION UPDATE: The final workaround that worked for me was similar to the template above but with adding a non-breaking space (⁠) between each character.

<xsl:template match="text()[ancestor::span[@class='nobreak']]">
    <xsl:param name="text"><xsl:value-of select="replace(., ' ', '&#160;')" /></xsl:param>
    <fo:inline>
        <xsl:for-each select="tokenize(replace(replace($text,'(.)','$1\\n'),'\\n$',''),'\\n')">
        <fo:inline>
            <xsl:value-of select="."/>
            <!-- non-breaking invisible space after each character-->
            <fo:inline>&#8288;</fo:inline>
        </fo:inline>
        </xsl:for-each>
    </fo:inline>
</xsl:template>

Much thanks to @DanielNorberg

I found a solution for this (verified for FOP 2.2). The code "disables" hyphenation and keeps the inline content on the same line. It's of course a hack with no guarantee to work for later releases but it works for my purpose, maybe it can help you as well.

Sample XML:

<block>Lorem ipsum <inline class='nobreak>This is neither hyphenated or line broken</inline>.</block>

XSLT 2.0 solution:

Create a parent inline element (XSLT 1.0 and 2.0):

<xsl:template match="inline[@class='nobreak"]">
   <fo:inline>
      <xsl:apply-templates />
   </fo:inline>
</xsl:template>

"Disable" hyphenation and make the text content to be kept on the same line (XSLT 2.0):

<xsl:template match="text()[ancestor::inline[@class='nobreak']]">
    <xsl:param name="text"><xsl:value-of select="." /></xsl:param>
    <xsl:for-each select="tokenize(replace(replace($text,'(.)','$1\\n'),'\\n$',''),'\\n')">
       <fo:inline keep-with-next.within-line="always">
          <xsl:value-of select="."/>
          <fo:character font-size="0pt">
             <xsl:value-of select="' '" />
          </fo:character>
       </fo:inline>
    </xsl:for-each>
</xsl:template>

UPDATE XSLT 2.0, this seems to be better:

<xsl:template match="text()[ancestor::phrase[@class='nobreak']]">
    <xsl:param name="text"><xsl:value-of select="replace(., ' ', '&#160;')" /></xsl:param>
    <xsl:for-each select="tokenize(replace(replace($text,'(.)','$1\\n'),'\\n$',''),'\\n')">
       <fo:inline>
          <xsl:value-of select="."/>
          <fo:inline font-size="0pt">
             <xsl:value-of select="'$'" />
          </fo:inline>
       </fo:inline>
    </xsl:for-each>
</xsl:template>

If you want an XSLT 1.0 solution for this you can easily find code on the web that parses the text one character at the time.

hyphens, The hyphens property controls hyphenation of text in block level elements. You can prevent hyphenation from happening at all, allow it, or only� The hyphenated forms often show up because they are a visual aid to both the writer and the reader. Running too many elements together, especially if a prefix ends with a vowel and the main word begins with one, makes scanning difficult. “Nonhyphenation” is long enough that not hyphenating makes it hard to read.

The feature that should do the trick is:

<fo:block hyphenate="true">
  This text should be hyphenated 
  <fo:inline keep-together.within-line="always">This text shouldn’t be hyphenated</fo:inline>
</fo:block>

but was reported to be buggy some years ago. So, if you have a version of fop that is recent enough, you could try it.

Prevent hyphenation and use line break in block of text, See this answer in the UK TeX FAQ. Three "easy" ways to prevent hyphenation for a text block (as opposed to the whole document) are: Enclose the text block in � One can also remove hyphens by selecting the text box, going under the Text box tools forwarding menu, and on the far left hand side, selecting the hyphenation icon. Find any text you want to change and manually remove the hyphen by hitting delete. Resize the text box as needed. 4

I would think the only solution would be XSL FO markup that would be like this:

<fo:block hyphenate="true">
<fo:inline>I am some text that can be hyphenated. </fo:inline> 
<fo:inline keep-together.within-line="always">I</fo:inline> <fo:inline keep-together.within-line="always">am</fo:inline> <fo:inline keep-together.within-line="always">text</fo:inline> <fo:inline keep-together.within-line="always">that</fo:inline> <fo:inline keep-together.within-line="always">isn't</fo:inline> <fo:inline keep-together.within-line="always">hyphenated</fo:inline>.
</fo:block>

In theory, set hyphenation on the overall block and any child fo:inline that must be kept together in the line (word by word) specified. Now, how you get there with some template is likely not straight-forward considering what maybe are word boundaries and what are punctuation and such.

This would require some testing. You might also need to put breaking-space characters or additional inline elements inbetween the words with the space character.

Update 1

I used the above and created a simple FO. Formatting with RenderX I get what I would expect, even changing spome margins I can get hyphenation in the areas where it is not marked and none in the area where keeps are set.

RenderX output:

Using the exact same template (even adjusting margins several times because each formatter is different when it comes to line ending treatment), I cannot get any hyphenation at all in FOP.

FOP output:

Conclusion is that there seems to be an issue in using FOP and attempting to do what I said as a workaround.

Update 2

With RenderX as well as AHF as stated below, setting hyphenation on fo:inline works. Here is output from RenderX using this:

 <fo:block hyphenate="true">
    <fo:inline>I am some text that can be hyphenated. I am some text that can be hyphenated. I am some text that can be hyphenated. </fo:inline> 
    <fo:inline hyphenate="false">I am some text that cannot be hyphenated. I am some text that cannot be hyphenated. I am some text that cannot be hyphenated. </fo:inline>         
 </fo:block>

Hyphenation of the word block, Hyphenation of the English word block. Showing how to split Are you trying to hyphenate block? Block the way Barricade the streets Stop the busy road. 15. My problem is That it’s not possible to set hyphenate="false" on fo:inline because it’s not a property. And fo:block inside fo:block creates a new line Fo-Example: <fo:block hyphenate="true"> This text should be hyphenated <fo:inline hyphenate="false">This text shouldn’t be hyphenated</fo:inline> </fo:block> UPDATE:

One trick is to set a "bogus" language for the inner <inline>:

Here, I've set the inner block to Ukrainian, so the formatter attempts to use Ukrainian hyphenation rules, which obviously are not applicable.

In fact, I've found this trick because I needed Ukrainian hyphenation for one of my documents and it did not apply unless you explicitly specify the language.

<fo:block hyphenate="true">
This text should be hyphenated This text should be hyphenated This text should be
hyphenated <fo:inline  color="green" language="uk">This text shouldn’t be
hyphenated This text shouldn’t be hyphenated This text shouldn’t be
hyphenated </fo:inline>
</fo:block>

Result using RenderX XEP:

left: as in OP's question; right: with "bogus" language set

Stopping all hyphenation, Contrariwise, if you are writing a multilanguage document using the babel package, you cannot suppress hyphenation throughout using either the no- hyphens� Words are not hyphenated. manual. Default. Words are only hyphenated at &hyphen; or ­ (if needed) auto. Words are hyphenated where the algorithm is deciding (if needed) initial. Sets this property to its default value. Read about initial.

It should be possible to set hyphenate="false" on the fo:inline. hyphenate is an inherited property, and it applies to both fo:block and fo:character. (See https://www.w3.org/TR/xsl11/#fo_character and https://www.w3.org/TR/xsl11/#hyphenate.) Every character in the text of your XSL-FO document is interpreted as an fo:character, so it should just work.


For this XSL-FO:

<!-- Without fo:inline/@hyphenate: -->
<fo:block hyphenate="true" color="red">
This text should be hyphenated This text shouldn’t be hyphenated</fo:block>
<!-- With fo:inline/@hyphenate: -->
<fo:block hyphenate="true">
This text should be hyphenated <fo:inline hyphenate="false">This text shouldn’t be hyphenated</fo:inline>
</fo:block>

I get this result with AH Formatter V6.6:

Hyphenation, hyphenation Mandatory for justified text; optional otherwise breaking words between lines to create more consistency across a text block. of paragraphs, if you suppress hyphenation within paragraph and character styles. Word Right- click in the text and select Paragraph → Line and Page Breaks → Don't hyphenate. Say ‘no’ to inappropriate punctuation marks. This post aims to help those wanting to remove automatic hyphens / auto hyphenation occurring on their WordPress website or blog. We have noticed that some themes including TwentyTwelve have kept the pesky critters in place, which for some, make your page layout look neat, but are a bit unsightly.

Understanding automatic hyphenation – Squarespace Help, Hyphens (-) break up words that extend beyond the edges of a text area. There's no built-in way to disable automatic hyphenation, but if you don't like how it For example, if your Text Block is displaying in a sidebar, the� First, regarding manual hyphenation: You can press Ctrl+- (Ctrl and minus/hyphen) to insert a “soft hyphen”, which is only shown if the word is hyphenated there, otherwise it is invisible. Very handy even with automatic hyphenation turned on if you have long words (usually scientific) that Word does not have in its hyphenation dictionary.

Text Hyphenation : Magazine Designing, Hyphenate Last Word To prevent last words in paragraphs from being be used for short blocks of text and it does not have to be hyphenated. Scenario #3: Never use hyphens in place of em dashes. In Number 1, you saw an example of hyphens being used in place of em dashes to offset parenthetical elements. Em dashes are used stylistically and are very versatile. In contrast to hyphens, em dashes can take the place of colons, commas, and parentheses.

To hyphenate or not to hyphenate?, Attributive compound adjectives are hyphenated. Never hyphenate compounds including an adverb (generally, a word ending in 'ly'), whether attributive or�

Comments
  • Wow if that works that’s gonna be great. I will try this as soon as possible. Thanks!
  • Ok i tried now as you said. It sadly doesnt really fix the problem for me. my .fo output is the following: xml <fo:block hyphenate="true" xml:lang="de"> <fo:block>Die Entwicklung der folgenden Jahre bestätigte unsere Auffassung. Nicht nur erwiesen sich die <fo:inline> <fo:inline keep-with-next.within-line="always">T<fo:character font-size="0pt"> </fo:character> </fo:inline> <fo:inline keep-with-next.within-line="always">r<fo:character font-size="0pt"> </fo:character> </fo:inline> </fo:inline> von gestern... </fo:block> </fo:block>
  • I'll check your fo code as soon as possible. Hopefully I can find something obvious.
  • I updated my comment with new XSLT. See "UPDATE XSLT 2.0". It seems to work better. Can you try?
  • @CrazyEight Did you see that I updated the XSLT? I am new on Stack Overflow and do not have enough rep to add comments to your original question but you can see the new XSLT in the updated answer.
  • But if the line is only wide enough for "This text should be hyphenated This"?
  • Also tried that. I am using fop2.3. I think that’s the most recent version?
  • My version is now fop 2.1 and it doesn't work for me either. Sorry.
  • The last version of fop is 2.4.
  • The problem is that as soon as fop-hyphenation decides to hypenate a word it doesn't matter if there is keep-together.within-line="always". I think the only solution is to set a fo:block twhere u can set hyphenate="false" that behaves like a fo:inline