Right-to-left Layout of paragraphs switches after first paragraph when in framed section
I originally tried to send this question on December 23, but the size of the email was too large and the email bounced. So I have not included the font. It bounced again several times because I was trying to include the image inline. Attaching the image, the email was still too large. So I will follow up with an email that contains the image. Sorry if this question ends up appearing more than once. *Problem:* When using r2l alignment, layout of paragraphs appears to be flipped (from r2l to l2r) after correctly placing the first paragraph inside of a frame. *Questions:* 1. What is going on? (I'm not sure how to describe what's happening.) Is the paragraph not being formatted correctly or the frame? 2. What document can I look at to understand what's happening to format the text? typo-duc.lmt seems to be referencing some other work that has sections and tagged rules. What document is that? 3. What are typo-dir, typo-dha, and typo-duc each doing? I'm curious to know so I can better navigate the codebase going forward. *Context Version:* ConTeXt ver: 2025.11.24 17:55 LMTX fmt: 2025.12.24 int: english/english (LMTX fmt with more of the typesetters enabled for looking at the logs) *Code Example:* \definefontfeature[minimal][default][ script=hebr ] \starttypescript [serif] [hebrew] \definefontsynonym [Serif] [file:/workspaces/context_lmtx/context_2/build_from_cmake_2/context_from_scratch/tex/texmf-fonts/firago/FiraGO-Regular.ttf][features=minimal] \stoptypescript \definetypeface [hebrew] [rm] [serif] [hebrew] \definetypeface [hebrew] [ss] [serif] [hebrew] \setupbodyfont[hebrew, 20pt] \setupalign[r2l] \setupdirections[bidi=on, method=two] \defineframed[Zimmun][width=\textwidth,align={flushleft,nothyphenated,verytolerant,r2l}, frame=off] \defineparagraphs[SubZimmun][n=2,before={\blank},after={},align=r2l] \setupparagraphs[SubZimmun][1][width=.3\textwidth,align=middle] \define[1]\instructionalText{{\switchtobodyfont[hebrew,8pt]#1}} \enabletrackers["typesetters"] \showdirections \starttext \Zimmun { \showdirections \setupalign[righttoleft] \showdirections שלושה שאכלו כאחד חייבין בזימון, וכך מזמנין: \startSubZimmun \showdirections \instructionalText{ המזמן אומר: } \SubZimmun רַבּוֹתַי נְבָרֵךְ: \stopSubZimmun \startSubZimmun \instructionalText{ המסובים עונים: } \SubZimmun \showdirections יְהִי שֵׁם יְהֹוָה מְבֹרָךְ מֵעַתָּה וְעַד־עוֹלָם: \stopSubZimmun \startSubZimmun \instructionalText{ וממשיך: } \SubZimmun בִּרְשׁוּת מָרָנָן וְרַבָּנָן וְרַבּוֹתַי נְבָרֵךְ (בעשרה אֱלֺהֵֽינוּ) שֶׁאָכַֽלְנוּ מִשֶּׁלּוֹ: \stopSubZimmun } \instructionalText{ המסובים עונים: } בָּרוּךְ (בעשרה אֱלֺהֵֽינוּ) שֶֽׁאָכַֽלְנוּ מִשֶּׁלּוֹ וּבְטוּבוֹ חָיִֽינוּ: \stoptext The above code produces the result (with my line annotations added by hand) that's attached. Image to come. *Comments on image:* Line 2 appears to be formatted as I expect. The smaller text is located on the right of the larger text. Lines 3 and 4 appear to be formatted incorrectly with the smaller text being placed on the left of the larger text instead of the right. I think this placement makes sense if there is something that is causing the layout of the paragraph elements to be l2r at that point. Line 5 appears to be formatted as I expect. It is not using the Zimmun frame or SubZimmun paragraph blocks. Therefore, the small text appears to the right of the larger text. Throughout the generated document the layout shows as l2r. I would expect it to be r2l since I've set that up with \setupalign. Any help would be greatly appreciated. Thank you! Best, Aryeh
Am 28.12.2025 um 17:58 schrieb Aryeh Zapinsky:
I originally tried to send this question on December 23, but the size of the email was too large and the email bounced. So I have not included the font. It bounced again several times because I was trying to include the image inline. Attaching the image, the email was still too large. So I will follow up with an email that contains the image. Sorry if this question ends up appearing more than once.
_Problem:_ When using r2l alignment, layout of paragraphs appears to be flipped (from r2l to l2r) after correctly placing the first paragraph inside of a frame.
_Questions:_ 1. What is going on? (I'm not sure how to describe what's happening.) Is the paragraph not being formatted correctly or the frame? 2. What document can I look at to understand what's happening to format the text? typo-duc.lmt seems to be referencing some other work that has sections and tagged rules. What document is that? 3. What are typo-dir, typo-dha, and typo-duc each doing? I'm curious to know so I can better navigate the codebase going forward.
I can reproduce the problem with the following minimal example \defineparagraphs [Columns] [n=2,rule=on] \starttext \startframed[width=max,align=r2l] \startColumns 1 \nextColumns 2 \stopColumns \startColumns 1 \nextColumns 2 \stopColumns \stopframed \stoptext The reason why the first environment is r2l is because it start in horizontal mode while the second start in vertical mode, when you add \dontleavehmode before the second one it will also switch to r2l. One way to fix this problem is to add a direction key with will by default place the column "left to right" with the option to reverse it to "right to left". Wolfgang
Sent with Proton Mail secure email.
On Sunday, December 28th, 2025 at 8:00 PM, Wolfgang Schuster
Am 28.12.2025 um 17:58 schrieb Aryeh Zapinsky:
Problem: When using r2l alignment, layout of paragraphs appears to be flipped (from r2l to l2r) after correctly placing the first paragraph inside of a frame.
Questions: 1. What is going on? (I'm not sure how to describe what's happening.) Is the paragraph not being formatted correctly or the frame? 2. What document can I look at to understand what's happening to format the text? typo-duc.lmt seems to be referencing some other work that has sections and tagged rules. What document is that? 3. What are typo-dir, typo-dha, and typo-duc each doing? I'm curious to know so I can better navigate the codebase going forward.
I can reproduce the problem with the following minimal example
\defineparagraphs [Columns] [n=2,rule=on]
\starttext
\startframed[width=max,align=r2l] \startColumns 1 \nextColumns 2 \stopColumns \startColumns 1 \nextColumns 2 \stopColumns \stopframed
\stoptext
The reason why the first environment is r2l is because it start in horizontal mode while the second start in vertical mode, when you add \dontleavehmode before the second one it will also switch to r2l.
One way to fix this problem is to add a direction key with will by default place the column "left to right" with the option to reverse it to "right to left".
It looks like \startparagraphs is internally using \hpack without considering the layout directions, maybe something like the following solve it? \defineparagraphs [Columns] [n=2,rule=on] \unprotect \overloadmode=0 \overloaded\protected\def\startparagraphs[#1]% quite slow {\bgroup % (1) \cdef\currentparagraphs{#1}% \edef\p_width{\paragraphsparameter\c!width}% \ifempty\p_width \d_typo_paragraphs_width\availablehsize \else \d_typo_paragraphs_width\p_width\relax \fi \d_typo_paragraphs_width{\d_typo_paragraphs_width-(\paragraphsparameter\c!offset)*2}% \c_typo_paragraphs_max{\paragraphsparameter\c!n}% \d_typo_paragraphs_auto\d_typo_paragraphs_width\relax \scratchcounter\zerocount \localcontrolledrepeat \c_typo_paragraphs_max {\edef\p_width{\namedparagraphsparameter{\currentparagraphs:\the\currentloopiterator}\c!width}% \ifempty\p_width \advanceby\scratchcounter\plusone \else \advanceby\d_typo_paragraphs_auto-\p_width\relax \fi \ifnum\currentloopiterator>\plusone \advanceby\d_typo_paragraphs_auto{-(\namedparagraphsparameter{\currentparagraphs:\number\currentloopiterator}\c!distance)}% \fi}% \ifnum\scratchcounter>\zerocount \divideby\d_typo_paragraphs_auto\scratchcounter \else \d_typo_paragraphs_auto\zeropoint \fi \parindent\zeropoint \c_typo_paragraphs_n\zerocount \enforced\let\\\nextparagraphs % downward compatible \setbox\scratchbox\hpack\c!direction\displaylefttoright % <---------- was \setbox\scratchbox\hpack \bgroup % (2) \forgetall \ifchkdimension\paragraphsparameter\c!offset\or\advanceby\hsize-2\lastchkdimension\fi \let\typo_paragraphs_start_cell\typo_paragraphs_start_cell_indeed \let\typo_paragraphs_stop_cell \typo_paragraphs_stop_cell_indeed \typo_paragraphs_start_cell_indeed} \protect \starttext \startframed[width=max,align=r2l] \startColumns Column one text here \Columns Column two text here \stopColumns \stopframed \stoptext Udi
Am 28.12.2025 um 20:33 schrieb Udi Fogiel via ntg-context:
Sent with Proton Mail secure email.
On Sunday, December 28th, 2025 at 8:00 PM, Wolfgang Schuster
wrote: Am 28.12.2025 um 17:58 schrieb Aryeh Zapinsky:
Problem: When using r2l alignment, layout of paragraphs appears to be flipped (from r2l to l2r) after correctly placing the first paragraph inside of a frame.
Questions: 1. What is going on? (I'm not sure how to describe what's happening.) Is the paragraph not being formatted correctly or the frame? 2. What document can I look at to understand what's happening to format the text? typo-duc.lmt seems to be referencing some other work that has sections and tagged rules. What document is that? 3. What are typo-dir, typo-dha, and typo-duc each doing? I'm curious to know so I can better navigate the codebase going forward. I can reproduce the problem with the following minimal example
\defineparagraphs [Columns] [n=2,rule=on]
\starttext
\startframed[width=max,align=r2l] \startColumns 1 \nextColumns 2 \stopColumns \startColumns 1 \nextColumns 2 \stopColumns \stopframed
\stoptext
The reason why the first environment is r2l is because it start in horizontal mode while the second start in vertical mode, when you add \dontleavehmode before the second one it will also switch to r2l.
One way to fix this problem is to add a direction key with will by default place the column "left to right" with the option to reverse it to "right to left". It looks like \startparagraphs is internally using \hpack without considering the layout directions, maybe something like the following solve it?
\defineparagraphs [Columns] [n=2,rule=on] \unprotect \overloadmode=0 \overloaded\protected\def\startparagraphs[#1]% quite slow {\bgroup % (1) \cdef\currentparagraphs{#1}% \edef\p_width{\paragraphsparameter\c!width}% \ifempty\p_width \d_typo_paragraphs_width\availablehsize \else \d_typo_paragraphs_width\p_width\relax \fi \d_typo_paragraphs_width{\d_typo_paragraphs_width-(\paragraphsparameter\c!offset)*2}% \c_typo_paragraphs_max{\paragraphsparameter\c!n}% \d_typo_paragraphs_auto\d_typo_paragraphs_width\relax \scratchcounter\zerocount \localcontrolledrepeat \c_typo_paragraphs_max {\edef\p_width{\namedparagraphsparameter{\currentparagraphs:\the\currentloopiterator}\c!width}% \ifempty\p_width \advanceby\scratchcounter\plusone \else \advanceby\d_typo_paragraphs_auto-\p_width\relax \fi \ifnum\currentloopiterator>\plusone \advanceby\d_typo_paragraphs_auto{-(\namedparagraphsparameter{\currentparagraphs:\number\currentloopiterator}\c!distance)}% \fi}% \ifnum\scratchcounter>\zerocount \divideby\d_typo_paragraphs_auto\scratchcounter \else \d_typo_paragraphs_auto\zeropoint \fi \parindent\zeropoint \c_typo_paragraphs_n\zerocount \enforced\let\\\nextparagraphs % downward compatible \setbox\scratchbox\hpack\c!direction\displaylefttoright % <---------- was \setbox\scratchbox\hpack
Nearly perfect but a few minor changes are necessary: 1. direction uses the \s! prefix. 2. You have to pass \directionlefttoright as argument to direction. 3. You can add a reverse option for the direction. \edef\p_direction{\paragraphsparameter\c!direction}% \setbox\scratchbox\hpack\s!direction\ifx\p_direction\v!reverse\directionrighttoleft\else\directionlefttoright\fi Wolfgang
On 12/28/2025 8:53 PM, Wolfgang Schuster wrote:
Am 28.12.2025 um 20:33 schrieb Udi Fogiel via ntg-context:
Sent with Proton Mail secure email.
On Sunday, December 28th, 2025 at 8:00 PM, Wolfgang Schuster
wrote: Am 28.12.2025 um 17:58 schrieb Aryeh Zapinsky:
Problem: When using r2l alignment, layout of paragraphs appears to be flipped (from r2l to l2r) after correctly placing the first paragraph inside of a frame.
Questions: 1. What is going on? (I'm not sure how to describe what's happening.) Is the paragraph not being formatted correctly or the frame? 2. What document can I look at to understand what's happening to format the text? typo-duc.lmt seems to be referencing some other work that has sections and tagged rules. What document is that? 3. What are typo-dir, typo-dha, and typo-duc each doing? I'm curious to know so I can better navigate the codebase going forward. I can reproduce the problem with the following minimal example
\defineparagraphs [Columns] [n=2,rule=on]
\starttext
\startframed[width=max,align=r2l] \startColumns 1 \nextColumns 2 \stopColumns \startColumns 1 \nextColumns 2 \stopColumns \stopframed
\stoptext
The reason why the first environment is r2l is because it start in horizontal mode while the second start in vertical mode, when you add \dontleavehmode before the second one it will also switch to r2l.
One way to fix this problem is to add a direction key with will by default place the column "left to right" with the option to reverse it to "right to left". It looks like \startparagraphs is internally using \hpack without considering the layout directions, maybe something like the following solve it?
\defineparagraphs [Columns] [n=2,rule=on] \unprotect \overloadmode=0 \overloaded\protected\def\startparagraphs[#1]% quite slow {\bgroup % (1) \cdef\currentparagraphs{#1}% \edef\p_width{\paragraphsparameter\c!width}% \ifempty\p_width \d_typo_paragraphs_width\availablehsize \else \d_typo_paragraphs_width\p_width\relax \fi \d_typo_paragraphs_width{\d_typo_paragraphs_width- (\paragraphsparameter\c!offset)*2}% \c_typo_paragraphs_max{\paragraphsparameter\c!n}% \d_typo_paragraphs_auto\d_typo_paragraphs_width\relax \scratchcounter\zerocount \localcontrolledrepeat \c_typo_paragraphs_max {\edef\p_width{\namedparagraphsparameter{\currentparagraphs: \the\currentloopiterator}\c!width}% \ifempty\p_width \advanceby\scratchcounter\plusone \else \advanceby\d_typo_paragraphs_auto-\p_width\relax \fi \ifnum\currentloopiterator>\plusone \advanceby\d_typo_paragraphs_auto{- (\namedparagraphsparameter{\currentparagraphs: \number\currentloopiterator}\c!distance)}% \fi}% \ifnum\scratchcounter>\zerocount \divideby\d_typo_paragraphs_auto\scratchcounter \else \d_typo_paragraphs_auto\zeropoint \fi \parindent\zeropoint \c_typo_paragraphs_n\zerocount \enforced\let\\\nextparagraphs % downward compatible \setbox\scratchbox\hpack\c!direction\displaylefttoright % <---------- was \setbox\scratchbox\hpack
Nearly perfect but a few minor changes are necessary:
1. direction uses the \s! prefix.
2. You have to pass \directionlefttoright as argument to direction.
3. You can add a reverse option for the direction.
\edef\p_direction{\paragraphsparameter\c!direction}% \setbox\scratchbox\hpack\s!direction\ifx\p_direction\v! reverse\directionrighttoleft\else\directionlefttoright\fi
So to summariuze, we get this? \unprotect \pushoverloadmode \permanent\protected\def\startparagraphs[#1]% quite slow {\bgroup % (1) \cdef\currentparagraphs{#1}% \edef\p_width{\paragraphsparameter\c!width}% \ifempty\p_width \d_typo_paragraphs_width\availablehsize \else \d_typo_paragraphs_width\p_width\relax \fi \d_typo_paragraphs_width{\d_typo_paragraphs_width-(\paragraphsparameter\c!offset)*2}% \c_typo_paragraphs_max{\paragraphsparameter\c!n}% \d_typo_paragraphs_auto\d_typo_paragraphs_width\relax \scratchcounter\zerocount \localcontrolledrepeat \c_typo_paragraphs_max {\edef\p_width{\namedparagraphsparameter{\currentparagraphs:\the\currentloopiterator}\c!width}% \ifempty\p_width \advanceby\scratchcounter\plusone \else \advanceby\d_typo_paragraphs_auto-\p_width\relax \fi \ifnum\currentloopiterator>\plusone \advanceby\d_typo_paragraphs_auto{-(\namedparagraphsparameter{\currentparagraphs:\number\currentloopiterator}\c!distance)}% \fi}% \ifnum\scratchcounter>\zerocount \divideby\d_typo_paragraphs_auto\scratchcounter \else \d_typo_paragraphs_auto\zeropoint \fi \parindent\zeropoint \c_typo_paragraphs_n\zerocount \enforced\let\\\nextparagraphs % downward compatible \setbox\scratchbox\hpack \s!direction \ifcstok{\paragraphsparameter\c!direction}\v!reverse \directionrighttoleft \else \directionlefttoright \fi \bgroup % (2) \forgetall %\advanceby\hsize-2\scratchoffset \ifchkdimension\paragraphsparameter\c!offset\or\advanceby\hsize-2\lastchkdimension\fi \let\typo_paragraphs_start_cell\typo_paragraphs_start_cell_indeed \let\typo_paragraphs_stop_cell \typo_paragraphs_stop_cell_indeed \typo_paragraphs_start_cell_indeed} \protect \defineparagraphs [Columns] [n=2,rule=on,after=,before=\par,direction=reverse] \starttext \startframed[width=max,align=r2l,strut=no] \startColumns 1 \nextColumns 2 \stopColumns \startColumns 1 \nextColumns 2 \stopColumns \stopframed \stoptext ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl -----------------------------------------------------------------
Am 29.12.2025 um 10:47 schrieb Hans Hagen via ntg-context:
On 12/28/2025 8:53 PM, Wolfgang Schuster wrote:
Am 28.12.2025 um 20:33 schrieb Udi Fogiel via ntg-context:
Sent with Proton Mail secure email.
On Sunday, December 28th, 2025 at 8:00 PM, Wolfgang Schuster
wrote: Am 28.12.2025 um 17:58 schrieb Aryeh Zapinsky:
Problem: When using r2l alignment, layout of paragraphs appears to be flipped (from r2l to l2r) after correctly placing the first paragraph inside of a frame.
Questions: 1. What is going on? (I'm not sure how to describe what's happening.) Is the paragraph not being formatted correctly or the frame? 2. What document can I look at to understand what's happening to format the text? typo-duc.lmt seems to be referencing some other work that has sections and tagged rules. What document is that? 3. What are typo-dir, typo-dha, and typo-duc each doing? I'm curious to know so I can better navigate the codebase going forward. I can reproduce the problem with the following minimal example
\defineparagraphs [Columns] [n=2,rule=on]
\starttext
\startframed[width=max,align=r2l] \startColumns 1 \nextColumns 2 \stopColumns \startColumns 1 \nextColumns 2 \stopColumns \stopframed
\stoptext
The reason why the first environment is r2l is because it start in horizontal mode while the second start in vertical mode, when you add \dontleavehmode before the second one it will also switch to r2l.
One way to fix this problem is to add a direction key with will by default place the column "left to right" with the option to reverse it to "right to left". It looks like \startparagraphs is internally using \hpack without considering the layout directions, maybe something like the following solve it?
[...]
Nearly perfect but a few minor changes are necessary:
1. direction uses the \s! prefix.
2. You have to pass \directionlefttoright as argument to direction.
3. You can add a reverse option for the direction.
\edef\p_direction{\paragraphsparameter\c!direction}% \setbox\scratchbox\hpack\s!direction\ifx\p_direction\v! reverse\directionrighttoleft\else\directionlefttoright\fi
So to summariuze, we get this?
Yes Wolfgang
Thanks Udi, Wolfgang, and Hans! With the change to take a direction parameter and then setting that parameter the result looks like what I had in mind. Best, Aryeh
participants (4)
-
Aryeh Zapinsky -
Hans Hagen -
Udi Fogiel -
Wolfgang Schuster