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 <[email protected]> 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
-----------------------------------------------------------------
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the 
Wiki!

maillist : [email protected] / 
https://mailman.ntg.nl/mailman3/lists/ntg-context.ntg.nl
webpage  : https://www.pragma-ade.nl / https://context.aanhet.net (mirror)
archive  : https://github.com/contextgarden/context
wiki     : https://wiki.contextgarden.net
___________________________________________________________________________________

Reply via email to