Custom Chapter created with tabular does not wrap text

I created a custom chapter heading (with help from here), using tabular, like this:

<assign|chapter-numbered-title|<\macro|title>
  <no-indent>\ 

  <with|color|gray|<with|font-family|ss|<\with|text-color|grey>
    <no-indent>

    <\wide-tabular>
      <tformat|
         <cwith|2|2|1|1|cell-tborder|4ln>|
         <cwith|1|1|1|1|cell-bborder|4ln>|
         <cwith|2|2|1|1|cell-bborder|4ln>|
         <cwith|2|2|1|1|cell-lborder|0ln>|
         <cwith|2|2|1|1|cell-rborder|0ln>|
         <cwith|2|2|1|1|cell-hyphen|t>|
         <cwith|1|1|1|1|cell-halign|r>|
         <cwith|1|-1|1|1|cell-lsep|0.0em>|
         <cwith|1|-1|1|1|cell-rsep|0.0em>|
         <cwith|1|-1|1|1|cell-bsep|1.5em>|
         <cwith|1|-1|1|1|cell-tsep|1.5em>|
         <table|
          <row|<\cell>
          <with|font-series|bold|font-family|ss|font-shape|small-caps|<large|
            Chapter <with|font-base-size|38| <the-chapter>>>>
          </cell>>|
         <row|<\cell>
          <no-indent><with|font-series|bold|font-shape|small-caps|font-family|ss|<very-large|   <with|color|black|<arg|title>>>>
      </cell>>>>
    </wide-tabular>
  </with>>>
</macro>>

However, for long chapter text, the title does not wrap around the next line.

Any way to fix this?

EDIT: The behavior of this macro is strange. When I start a chapter with \chapter the line does wrap around, however the title is justified and words are hyphenated. This is not desirable for my chapter tiles. Ideally the text should be left-aligned and un-hyphenated. I can prevent words by grouping them (Format > Break > Horizontal), but this results in large spaces between words.

On the other hand, when I try to switch to left aligned text via Format > Paragraph > Alignment, that’s when the line-wrapping breaks and the above issue happens. Even stranger, if I try to switch back to justified, the error is not corrected.

One possible work-around is to manually break the line in the title (via Format > Break > New Line), but this seems like a very inelegant solution. I would prefer if I could make the macro work correctly. Also, this screws up the headers, as they also appear to have a new-line.

I am not on my computer and cannot check, this said I think there is an option for hyphenation of table cells.
Maybe easy to find through the menus, and looking at the source of the table that is generated through the menu.

Edit: I see now that you have cell-hyphen equal to true in your table settings, and I think it is that. Then I need to experiment, sorry.

Another note. As far as I understand, TeXmacs does not have “internal states”, but interpretes the text that it finds in your document, including some parts at the end that you do not see either in default view or in source mode view; you can see those parts with a text editor, maybe it us worth checking your file before and after the changes of text alignment.

I found the difference—with a macro different from yours but I think the same in the relevant parts (I could not get your macro to work, maybe something went off with copy-pasting).

The chapter title that wraps is

<chapter|Test Test Test Test Test Test Test Test Test Test test>

The one that does not wrap, that I obtain after changing the paragraph alignment, is

<\chapter>
  Test Test Test Test Test Test Test Test Test TestTest Test Test Test Test
  Test Test Test Test Test Test Test Test Test Test
</chapter>

and I did not find how to go back from the second markup to the first. May be it is the implicit document tag, which I do not know how to use together with table cells.

An idea for permitting line breaks only at the end of words is to mark the text in a language for which there are no hyphenation rules; I have not been able to make this work.

Also, I did not yet understand how to prevent the indent in the title.

<taiwanese|Test Test Test Test Test Test Test Test Test Test test test test
test test test test averylongwordthatdoesnotgethyphenated
andthehyphenationatwordbreak>

Edit: this is what I got today, setting the par-flexibility environment variable for the table in the chapter macro:

<assign|chapter-numbered-title|<\macro|title>
  <\with|color|gray|par-flexibility|0>
    <\wide-tabular>
      <tformat|<cwith|2|2|1|1|cell-tborder|4ln>|<cwith|1|1|1|1|cell-halign|r>|<cwith|2|2|1|1|cell-halign|l>|<cwith|2|2|1|1|cell-hyphen|y>|<cwith|2|2|1|1|cell-block|y>|<table|<row|<\cell>
        <with|font-series|bold|cont-shape|small-caps|<large|<chapter-text>><with|font-base-size|38|<the-chapter>>>
      </cell>>|<row|<cell|<with|font-series|bold|font-shape|small-caps|font-family|ss|<very-large|
      <with|color|black|<taiwanese|<arg|title>>>>>>>>>
    </wide-tabular>
  </with>
</macro>>

This, with par-hyphen set to normal, does not make all of the lines of equal length:

<assign|chapter-numbered-title|<\macro|title>
  <\with|color|gray|par-flexibility|0|par-hyphen|normal>
    <\wide-tabular>
      <tformat|<cwith|2|2|1|1|cell-tborder|4ln>|<cwith|1|1|1|1|cell-halign|r>|<cwith|2|2|1|1|cell-halign|l>|<cwith|2|2|1|1|cell-hyphen|y>|<cwith|2|2|1|1|cell-block|y>|<table|<row|<\cell>
        <with|font-series|bold|cont-shape|small-caps|<large|<chapter-text>><with|font-base-size|38|<the-chapter>>>
      </cell>>|<row|<cell|<with|font-series|bold|font-shape|small-caps|font-family|ss|<very-large|
      <with|color|black|<taiwanese|<arg|title>>>>>>>>>
    </wide-tabular>
  </with>
</macro>>

I think that more experimentation and reading can help (I did not yet read in the “Jolly Writer”).