On 6/26/2020 5:39 PM, mf wrote:
Hello list,
I'm using a 2-columns layout and I'd like to put some information in the margin. I should put that information in the left margin when I'm in the left column, and in the right margin when I'm in the right column, to prevent the extra information overlapping the main text in the other column.

I found a useful counter in page-pcl.mkiv: \c_page_col_current.

Here's a MWE:

\unprotect
\def\curCol{\c_page_col_current}
\protect

\def\InfoInMargin#1{\doifelse{\the\curCol}{1}{\inmargin{#1}}{\inothermargin{#1}}} \def\TestText{\InfoInMargin{\bf \the\curCol}\input ward \InfoInMargin{\bf \the\curCol} \input ward}
\starttext
   \startpagecolumns[n=2,distance=25mm]
   \dorecurse{5}{\TestText\par}
   \stoppagecolumns
\stoptext

\c_page_col_current works most of the time, but unfortunately it tells you the current column before the lines of a paragraph get distributed over columns.

So sometimes it fails. You can see that in the MWE: the bold "1" between columns in the upper part of the page. It should be a bold "2" in the right margin.

Is there a better way to read the current column?
Because I want you to run the usual stress test on the latest greatest, here's your reward:

\usemodule[article-basic] \setupalign[verytolerant,stretch] \dontcomplain

\newcounter\MyCounter

\def\InfoInMargin#1%
  {\doglobal\increment\MyCounter
   \ifodd\MPcolumn{\MPregion{MyPos:\MyCounter}}\relax
      \inmargin{\xypos{MyPos:\MyCounter}#1}%
   \else
      \inothermargin{\xypos{MyPos:\MyCounter}#1}%
   \fi}

\starttext
  \startpagecolumns[n=2,distance=10mm]
    \dorecurse {50}  {
        \InfoInMargin{\bf#1}\input ward
        \InfoInMargin{\sl#1}\input ward
        \par
    }
  \stoppagecolumns
\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 : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

Reply via email to