ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* tikzpicture in margin
       [not found] <534947008.1281700.1613315494023.ref@mail.yahoo.com>
@ 2021-02-14 15:11 ` Jigé
  2021-02-14 15:41   ` Henning Hraban Ramm
  2021-02-14 21:43   ` Aditya Mahajan
  0 siblings, 2 replies; 4+ messages in thread
From: Jigé @ 2021-02-14 15:11 UTC (permalink / raw)
  To: ntg-context

Hi all.

I'm trying to place a TikZ picture in the margin.
Here is a small example:

\usemodule[tikz]
\setuplayout[backspace=4cm, topspace=2cm, height=middle]
\starttext
\input{lorem}
\margintext{I have discovered a truly
            marvelous proof ...  but
            this margin is too narrow
            to contain it.}
\input{lorem}
\inmargin{\externalfigure[cow] [width=\marginwidth]}
% The above works.
% The following does not:
\input{lorem}
\inmargin{
\starttikzpicture
  \draw[gray] (-2,0) grid (2,2) ;
  \draw plot [domain=-2:2, samples=50, smooth] (\x,{\x * \x});
\stoptikzpicture
}
\stoptext

-> Undefined control sequence

I tried using \startfigure, \hbox... no success.

Actually the command \startmarginblock ... \stop... described in the ConText reference works with a TikZ picture. But the picture, in the margin, gets near the top of the page. I don't understand the meaning of the options (especially the difference between `location' and `align'). And is it `\setuppagenumbering[alternative=doublesided]'-aware ?
Example:

\usemodule[tikz]
\setuplayout[backspace=4cm, topspace=2cm, height=middle]
\setuppagenumbering[alternative=doublesided]
\starttext
\input{lorem}
\inmargin{\externalfigure[cow] [width=\marginwidth]}
\pagebreak
\input{lorem}
\input{lorem}

\blank
We would like the picture to go the the left of this paragraph.
\setupmarginblocks[location=left,align=inner]
\startmarginblock
\starttikzpicture[scale=0.2]
  \draw[gray] (-2,0) grid (2,2) ;
  \draw plot [domain=-2:2, samples=50, smooth] (\x,{\x * \x});
\stoptikzpicture
\stopmarginblock
\stoptext


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

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

* Re: tikzpicture in margin
  2021-02-14 15:11 ` tikzpicture in margin Jigé
@ 2021-02-14 15:41   ` Henning Hraban Ramm
  2021-02-14 21:43   ` Aditya Mahajan
  1 sibling, 0 replies; 4+ messages in thread
From: Henning Hraban Ramm @ 2021-02-14 15:41 UTC (permalink / raw)
  To: mailing list for ConTeXt users


> Am 14.02.2021 um 16:11 schrieb Jigé <broumpf-c@yahoo.com>:
> 
> Hi all.
> 
> I'm trying to place a TikZ picture in the margin.
> Here is a small example:
> 
> \usemodule[tikz]
> \setuplayout[backspace=4cm, topspace=2cm, height=middle]
> \starttext
> \input{lorem}
> \margintext{I have discovered a truly
>             marvelous proof ...  but
>             this margin is too narrow
>             to contain it.}
> \input{lorem}
> \inmargin{\externalfigure[cow] [width=\marginwidth]}
> % The above works.
> % The following does not:
> \input{lorem}
> \inmargin{
> \starttikzpicture
>   \draw[gray] (-2,0) grid (2,2) ;
>   \draw plot [domain=-2:2, samples=50, smooth] (\x,{\x * \x});
> \stoptikzpicture
> }
> \stoptext

Does \placefigure[margin]{caption}{... tikzpicture ...} fit your needs?

That generally works, but using LMTX there’s a horizontal shift on left pages (still need to prepare a MWE for that).

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

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

* Re: tikzpicture in margin
  2021-02-14 15:11 ` tikzpicture in margin Jigé
  2021-02-14 15:41   ` Henning Hraban Ramm
@ 2021-02-14 21:43   ` Aditya Mahajan
  2021-02-15  9:04     ` Hans Hagen
  1 sibling, 1 reply; 4+ messages in thread
From: Aditya Mahajan @ 2021-02-14 21:43 UTC (permalink / raw)
  To: mailing list for ConTeXt users

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

On Sun, 14 Feb 2021, Jigé wrote:

> Hi all.
> 
> I'm trying to place a TikZ picture in the margin.
> Here is a small example:
> 
> \usemodule[tikz]
> \setuplayout[backspace=4cm, topspace=2cm, height=middle]
> \starttext
> \input{lorem}
> \margintext{I have discovered a truly
>             marvelous proof ...  but
>             this margin is too narrow
>             to contain it.}
> \input{lorem}
> \inmargin{\externalfigure[cow] [width=\marginwidth]}
> % The above works.
> % The following does not:
> \input{lorem}
> \inmargin{
> \starttikzpicture
>   \draw[gray] (-2,0) grid (2,2) ;
>   \draw plot [domain=-2:2, samples=50, smooth] (\x,{\x * \x});
> \stoptikzpicture
> }
> \stoptext
> 
> -> Undefined control sequence

Most likely because the argument of \inmargin is scanned upfront and at that time \draw etc are undefined. One option is:

\startbuffer[picture]
\starttikzpicture
...
\stoptikzpicture
\stopbuffer

\inmargin{\getbuffer[picture]}

Another option (but better to do that in tikz module) is:

\let\draw\relax
\let\x\relax

\inmargin{\starttikzpicture ... \stoptikzpicture}

> Actually the command \startmarginblock ... \stop... described in the ConText reference works with a TikZ picture. 

Because the \start ... \stop blocks don't scan the argument.

Aditya

[-- Attachment #2: Type: text/plain, Size: 493 bytes --]

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

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

* Re: tikzpicture in margin
  2021-02-14 21:43   ` Aditya Mahajan
@ 2021-02-15  9:04     ` Hans Hagen
  0 siblings, 0 replies; 4+ messages in thread
From: Hans Hagen @ 2021-02-15  9:04 UTC (permalink / raw)
  To: mailing list for ConTeXt users, Aditya Mahajan

On 2/14/2021 10:43 PM, Aditya Mahajan wrote:
> On Sun, 14 Feb 2021, Jigé wrote:
> 
>> Hi all.
>>
>> I'm trying to place a TikZ picture in the margin.
>> Here is a small example:
>>
>> \usemodule[tikz]
>> \setuplayout[backspace=4cm, topspace=2cm, height=middle]
>> \starttext
>> \input{lorem}
>> \margintext{I have discovered a truly
>>              marvelous proof ...  but
>>              this margin is too narrow
>>              to contain it.}
>> \input{lorem}
>> \inmargin{\externalfigure[cow] [width=\marginwidth]}
>> % The above works.
>> % The following does not:
>> \input{lorem}
>> \inmargin{
>> \starttikzpicture
>>    \draw[gray] (-2,0) grid (2,2) ;
>>    \draw plot [domain=-2:2, samples=50, smooth] (\x,{\x * \x});
>> \stoptikzpicture
>> }
>> \stoptext
>>
>> -> Undefined control sequence
> 
> Most likely because the argument of \inmargin is scanned upfront and at that time \draw etc are undefined. One option is:
> 
> \startbuffer[picture]
> \starttikzpicture
> ...
> \stoptikzpicture
> \stopbuffer
> 
> \inmargin{\getbuffer[picture]}
> 
> Another option (but better to do that in tikz module) is:
> 
> \let\draw\relax
> \let\x\relax
> 
> \inmargin{\starttikzpicture ... \stoptikzpicture}
> 
>> Actually the command \startmarginblock ... \stop... described in the ConText reference works with a TikZ picture.
> 
> Because the \start ... \stop blocks don't scan the argument.
Here's one for you to ponder:

we have this:

  % \doifelsenothing{#content}\donefalse\donetrue

we could use the slower (maybe even side effects)

  % \doifelsetext{#content}\donetrue\donefalse

but go modern instead:

    \ifparameter#content\donefalse\or\donetrue\else\donefalse\fi

i'll add that last one to lmtx

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

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

end of thread, other threads:[~2021-02-15  9:04 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <534947008.1281700.1613315494023.ref@mail.yahoo.com>
2021-02-14 15:11 ` tikzpicture in margin Jigé
2021-02-14 15:41   ` Henning Hraban Ramm
2021-02-14 21:43   ` Aditya Mahajan
2021-02-15  9:04     ` Hans Hagen

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).