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

* [NTG-context] Re: \intertext and highlighting with \alignhere/\breakhere
  2024-03-12  7:57 [NTG-context] \intertext and highlighting with \alignhere/\breakhere Max Chernoff
@ 2024-03-12 10:22 ` Hans Hagen
  2024-03-12 14:21 ` Hans Hagen
  1 sibling, 0 replies; 7+ messages in thread
From: Hans Hagen @ 2024-03-12 10:22 UTC (permalink / raw)
  To: ntg-context

On 3/12/2024 8:57 AM, Max Chernoff wrote:
> 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.
maybe

\starttexdefinition protected newintertext #1
     \leftparbox [global] {
         \vadjust pre \bgroup
             \forgetall
             \vskip.5\strutdp % needs to be more clever in the end
             \dontleavehmode\vtop\bgroup
                 #1
             \egroup
         \egroup
     }
     \breakhere
\stoptexdefinition

but i need to discuss it with Mikael as we might integrate something 
better and then it needs to be documented (in the upcoming manual) as well

Hans

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

* [NTG-context] Re: \intertext and highlighting with \alignhere/\breakhere
  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
  1 sibling, 1 reply; 7+ messages in thread
From: Hans Hagen @ 2024-03-12 14:21 UTC (permalink / raw)
  To: ntg-context

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

On 3/12/2024 8:57 AM, Max Chernoff wrote:
> 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.
the next upload will support the attached ... so no ugly hacky code needed

Hans

-----------------------------------------------------------------
                                           Hans Hagen | PRAGMA ADE
               Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
        tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl
-----------------------------------------------------------------

[-- Attachment #2: inter-001.pdf --]
[-- Type: application/pdf, Size: 16261 bytes --]

[-- Attachment #3: inter-001.tex --]
[-- Type: text/plain, Size: 637 bytes --]

\definebar[mybar][inlined][offset=.25ex,color=red]

\starttext

    \startformula
                a      \alignhere= b + c \breakhere
        \mybar {d + e} \alignhere= f     \breakhere
                g      \alignhere= h + i
    \stopformula

    \page

    \samplefile{knuth}
    \startformula
        \text{something} + \text{really} + \text{really} + \text{long} \alignhere= \sqrt{x} \numberhere
        \texthere[inbetween]{\input{knuth}}
        d \alignhere= e + f \numberhere \breakhere
        g \alignhere= h + i \breakhere
        j \alignhere= k + l
    \stopformula
    \samplefile{knuth}

\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

* [NTG-context] Re: \intertext and highlighting with \alignhere/\breakhere
  2024-03-12 14:21 ` Hans Hagen
@ 2024-03-13 10:32   ` Max Chernoff
  2024-03-13 11:26     ` Mikael Sundqvist
  0 siblings, 1 reply; 7+ messages in thread
From: Max Chernoff @ 2024-03-13 10:32 UTC (permalink / raw)
  To: ntg-context

Hi Hans,

On Tue, 2024-03-12 at 15:21 +0100, Hans Hagen wrote:
> the next upload will support the attached ... so no ugly hacky code needed

"\texthere[inbetween]" looks perfect, thanks!

The "\definebar[...][inlined]" doesn't look quite right though -- the
issue that I'm having is that I can't figure out how to highlight across
both sides of an \alignhere without any questionable hacks. Unless the
new "inlined" does work across an \alignhere and I'm just not seeing it
in the example.

Thanks again,
-- Max
___________________________________________________________________________________
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

* [NTG-context] Re: \intertext and highlighting with \alignhere/\breakhere
  2024-03-13 10:32   ` Max Chernoff
@ 2024-03-13 11:26     ` Mikael Sundqvist
  2024-03-13 12:06       ` Hans Hagen via ntg-context
  0 siblings, 1 reply; 7+ messages in thread
From: Mikael Sundqvist @ 2024-03-13 11:26 UTC (permalink / raw)
  To: mailing list for ConTeXt users

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

Hi,

On Wed, Mar 13, 2024 at 11:37 AM Max Chernoff <mseven@telus.net> wrote:
>
> Hi Hans,
>
> On Tue, 2024-03-12 at 15:21 +0100, Hans Hagen wrote:
> > the next upload will support the attached ... so no ugly hacky code needed
>
> "\texthere[inbetween]" looks perfect, thanks!
>
> The "\definebar[...][inlined]" doesn't look quite right though -- the
> issue that I'm having is that I can't figure out how to highlight across
> both sides of an \alignhere without any questionable hacks. Unless the
> new "inlined" does work across an \alignhere and I'm just not seeing it
> in the example.
>
> Thanks again,
> -- Max

I can confirm that it works over \alignhere. Hans is doing some black
magic, but I guess he did not want to show off by including the whole
line.

/Mikael

[-- Attachment #2: Screenshot 2024-03-13 12.24.09.png --]
[-- Type: image/png, Size: 16460 bytes --]

[-- Attachment #3: 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

* [NTG-context] Re: \intertext and highlighting with \alignhere/\breakhere
  2024-03-13 11:26     ` Mikael Sundqvist
@ 2024-03-13 12:06       ` Hans Hagen via ntg-context
  2024-03-13 21:50         ` Max Chernoff
  0 siblings, 1 reply; 7+ messages in thread
From: Hans Hagen via ntg-context @ 2024-03-13 12:06 UTC (permalink / raw)
  To: Mikael Sundqvist, mailing list for ConTeXt users; +Cc: Hans Hagen

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

On 3/13/2024 12:26 PM, Mikael Sundqvist wrote:
> Hi,
> 
> On Wed, Mar 13, 2024 at 11:37 AM Max Chernoff <mseven@telus.net> wrote:
>>
>> Hi Hans,
>>
>> On Tue, 2024-03-12 at 15:21 +0100, Hans Hagen wrote:
>>> the next upload will support the attached ... so no ugly hacky code needed
>>
>> "\texthere[inbetween]" looks perfect, thanks!
>>
>> The "\definebar[...][inlined]" doesn't look quite right though -- the
>> issue that I'm having is that I can't figure out how to highlight across
>> both sides of an \alignhere without any questionable hacks. Unless the
>> new "inlined" does work across an \alignhere and I'm just not seeing it
>> in the example.
>>
>> Thanks again,
>> -- Max
> 
> I can confirm that it works over \alignhere. Hans is doing some black
> magic, but I guess he did not want to show off by including the whole
> line.
Indeed, no need to show of the obvious

\definebar
   [mybar]
   [backgroundbar]
   [height=\strutht,depth=\strutdp,offset=.250ex,color=red]

\definebar
   [yourbar]
   [backgroundbar]
   [height=\strutht,depth=\strutdp,offset=.125ex,color=blue]

\definebar
   [ourbar]
   [backgroundbar]
   [height=\strutht,depth=\strutdp,offset=.125ex,color=green]

\starttext

\startTEXpage[width=4cm]
     \startformula
                 a \alignhere= b + c \breakhere
         \mybar {d + \yourbar{e \alignhere=} f \breakhere
                 g \alignhere \ourbar{=} h} + i
     \stopformula
\stopTEXpage

\stoptext

Especially when it would not pass the rigourous accessibility check (esp 
wrt color) of your university,

Hans

-----------------------------------------------------------------
                                           Hans Hagen | PRAGMA ADE
               Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
        tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl
-----------------------------------------------------------------

[-- Attachment #2: inter-001.pdf --]
[-- Type: application/pdf, Size: 16407 bytes --]

[-- Attachment #3: 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

* [NTG-context] Re: \intertext and highlighting with \alignhere/\breakhere
  2024-03-13 12:06       ` Hans Hagen via ntg-context
@ 2024-03-13 21:50         ` Max Chernoff
  0 siblings, 0 replies; 7+ messages in thread
From: Max Chernoff @ 2024-03-13 21:50 UTC (permalink / raw)
  To: ntg-context

Hi Hans, Mikael,

On Wed, 2024-03-13 at 13:06 +0100, Hans Hagen wrote:
> On 3/13/2024 12:26 PM, Mikael Sundqvist wrote:
> > I can confirm that it works over \alignhere. Hans is doing some black
> > magic, but I guess he did not want to show off by including the whole
> > line.
> Indeed, no need to show of the obvious
> 
> \definebar
>    [mybar]
>    [backgroundbar]
>    [height=\strutht,depth=\strutdp,offset=.250ex,color=red]
> 
> [...]

That looks perfect, thanks!
-- Max
___________________________________________________________________________________
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).