Hi all,

Often I want to include a sentence/paragraph in the middle of a long
multipart formula. With the old \startalign/\stopalign formulas, I could
use \intertext{...} to do this, but this doesn't work with the new
\alignhere/\breakhere formulas. I've managed to find a "solution" for
this, although I'd prefer something a bit less hacky. Any ideas?

Also, is there a way to highlight an equation across an \alignhere? Once
again, I've found a "solution", but like before, it's pretty hacky.

Example files are attached.

Thanks,
-- Max
\setupindenting[yes, 3em]
\setuphead[section][page=yes]

\unprotect
\newbox\intertext_tmp_box
\newdimen\intertext_tmp_dimen

\starttexdefinition protected newintertext #1
    \texthere[left]{
        \setbox\intertext_tmp_box=\hbox{
            \startframedtext[
                offset=none,
                width=\hsize,
                frame=off,
            ]
                \parindent = \v_spac_indentation_normal
                \noindent
                #1
            \stopframedtext
        }
        \global\intertext_tmp_dimen = \ht\intertext_tmp_box
        \vbox to 0pt{
            \vskip\dimexpr 1ex - \baselineskip \relax
            \box\intertext_tmp_box
            \vss
        }
        \aftergrouped{
            \aftergrouped{
                \vadjust{
                    \penalty 10000
                    \vskip\dimexpr \intertext_tmp_dimen - \baselineskip \relax
                }
            }
        }
    }
    \breakhere
\stoptexdefinition
\protect

\starttext
    \section{Old alignment}
    \samplefile{knuth}
    \placeformula\startformula\startalign
        \NC \text{something} + \text{really} + \text{really} + \text{long} \NC= \sqrt{x} \NR[+]
        \intertext{\samplefile{knuth}}
        \NC d \NC= e + f \NR[+]
        \NC g \NC= h + i
    \stopalign\stopformula
    \samplefile{knuth}


    \section{“I expect to see \tex{noalign} only after the \tex{cr} of an alignment.”}
    \starttyping
    \samplefile{knuth}
    \startformula
        \text{something} + \text{really} + \text{really} + \text{long} \alignhere= \sqrt{x} \numberhere \breakhere
        \intertext{\samplefile{knuth}}
        d \alignhere= e + f \numberhere \breakhere
        g \alignhere= h + i
    \stopformula
    \samplefile{knuth}
    \stoptyping


    \section{Alignment not kept}
    \samplefile{knuth}
    \startformula
        \text{something} + \text{really} + \text{really} + \text{long} \alignhere= \sqrt{x} \numberhere
    \stopformula
    \samplefile{knuth}
    \startformula
        d \alignhere= e + f \numberhere \breakhere
        g \alignhere= h + i
    \stopformula
    \samplefile{knuth}


    \section{My hack}
    \samplefile{knuth}
    \startformula
        \text{something} + \text{really} + \text{really} + \text{long} \alignhere= \sqrt{x} \numberhere \breakhere
        \newintertext{\samplefile{knuth}}
        d \alignhere= e + f \numberhere \breakhere
        g \alignhere= h + i
    \stopformula
    \samplefile{knuth}
\stoptext
\unprotect
\newbox\hightlight_tmp_box

\definemathframed[_highlight][
    location=mathematics,
    frame=off,
    background=color,
    backgroundcolor=lightred,
    backgroundoffset=0.25ex,
]

\tolerant\def\highlighthere#1\alignhere#2#3\breakhere{%
    \setbox\hightlight_tmp_box=\hbox{%
        \m{%
            \forcedisplaymath%
            #1#2\null%
        }%
    }%
    \alignhere%
    \phantom{%
        \null#2\null%
    }%
    \mskip -8mu%
    \hskip -\wd\hightlight_tmp_box%
    \lower 1ex \hbox{%
        \_highlight[
            loffset=\wd\hightlight_tmp_box,
            location=keep
        ]{%
            \hskip -\wd\hightlight_tmp_box%
            \forcedisplaymath%
            #1#2#3%
        }%
    }%
    \breakhere%
}
\protect

\starttext
    \startformula
        a \alignhere= b + c \breakhere
        \highlighthere d + e \alignhere= f \breakhere
        g \alignhere= h + i
    \stopformula
\stoptext
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the 
Wiki!

maillist : ntg-context@ntg.nl / 
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