ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* [NTG-context] \intertext and highlighting with \alignhere/\breakhere
@ 2024-03-12  7:57 Max Chernoff
  2024-03-12 10:22 ` [NTG-context] " Hans Hagen
  2024-03-12 14:21 ` Hans Hagen
  0 siblings, 2 replies; 7+ messages in thread
From: Max Chernoff @ 2024-03-12  7:57 UTC (permalink / raw)
  To: ntg-context

[-- Attachment #1: Type: text/plain, Size: 555 bytes --]

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

[-- Attachment #2: Type: text/x-tex, Size: 2476 bytes --]

\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

[-- Attachment #3: Type: text/x-tex, Size: 932 bytes --]

\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

[-- Attachment #4: Type: text/plain, Size: 511 bytes --]

___________________________________________________________________________________
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
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2024-03-13 21:52 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-12  7:57 [NTG-context] \intertext and highlighting with \alignhere/\breakhere Max Chernoff
2024-03-12 10:22 ` [NTG-context] " Hans Hagen
2024-03-12 14:21 ` Hans Hagen
2024-03-13 10:32   ` Max Chernoff
2024-03-13 11:26     ` Mikael Sundqvist
2024-03-13 12:06       ` Hans Hagen via ntg-context
2024-03-13 21:50         ` Max Chernoff

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).