ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* source code and result side by side
@ 2017-07-28 20:34 Henning Hraban Ramm
  2017-07-28 22:57 ` Aditya Mahajan
  0 siblings, 1 reply; 10+ messages in thread
From: Henning Hraban Ramm @ 2017-07-28 20:34 UTC (permalink / raw)
  To: mailing list for ConTeXt users

Ahoi again,

I’m preparing some ConTeXt docs with a lot of examples and would like to reproduce what we have in the wiki as

<context source="yes">
...
</context>

i.e. sourcecode beside the result.

Often the shown source is exactly what I want to show, in other cases I need some additional setup that I don’t want to show.

Which approach would you suggest? Combinations?


Greetlings, Hraban
---
http://www.fiee.net
http://wiki.contextgarden.net
GPG Key ID 1C9B22FD

___________________________________________________________________________________
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] 10+ messages in thread

* Re: source code and result side by side
  2017-07-28 20:34 source code and result side by side Henning Hraban Ramm
@ 2017-07-28 22:57 ` Aditya Mahajan
  2017-07-29  8:58   ` Pablo Rodriguez
  2017-07-30 17:13   ` Henning Hraban Ramm
  0 siblings, 2 replies; 10+ messages in thread
From: Aditya Mahajan @ 2017-07-28 22:57 UTC (permalink / raw)
  To: mailing list for ConTeXt users

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

On Fri, 28 Jul 2017, Henning Hraban Ramm wrote:

> Ahoi again,
>
> I’m preparing some ConTeXt docs with a lot of examples and would like to reproduce what we have in the wiki as
>
> <context source="yes">
> ...
> </context>
>
> i.e. sourcecode beside the result.
>
> Often the shown source is exactly what I want to show, in other cases I 
> need some additional setup that I don’t want to show.
>
> Which approach would you suggest? Combinations?

\startbuffer[example-1]
  ....
\stopbuffer


\placesidebyside
     {\typebuffer[example-1]}
     {\getbuffer[setups, example-1]}


Aditya

[-- Attachment #2: Type: text/plain, Size: 492 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] 10+ messages in thread

* Re: source code and result side by side
  2017-07-28 22:57 ` Aditya Mahajan
@ 2017-07-29  8:58   ` Pablo Rodriguez
  2017-07-29 10:46     ` Pablo Rodriguez
  2017-07-30 17:13   ` Henning Hraban Ramm
  1 sibling, 1 reply; 10+ messages in thread
From: Pablo Rodriguez @ 2017-07-29  8:58 UTC (permalink / raw)
  To: ntg-context

On 07/29/2017 12:57 AM, Aditya Mahajan wrote:
> [...]
> \startbuffer[example-1]
>   ....
> \stopbuffer
> 
> 
> \placesidebyside
>      {\typebuffer[example-1]}
>      {\getbuffer[setups, example-1]}

Many thanks for your suggestion, Aditya.

I’m afraid everything is forced to be in horizontal mode:

    \starttext
    \startbuffer[example-1]
    \setupexternalfigures[location=default]
    \starttext
    \ConTeXt\ is awesome!

    \externalfigure[cow.pdf][scale=250]
    \stoptext
    \stopbuffer

    \placesidebyside
         {\typebuffer[example-1]}
         {\getbuffer[setups, example-1]}
    \stoptext

\placeontopofeachother has the same feature.

This causes that \placefigure cannot be used.

Is there now hay to avoid the forced horizontal mode on both sides?

Many thanks for your help,

Pablo
-- 
http://www.ousia.tk
___________________________________________________________________________________
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] 10+ messages in thread

* Re: source code and result side by side
  2017-07-29  8:58   ` Pablo Rodriguez
@ 2017-07-29 10:46     ` Pablo Rodriguez
  0 siblings, 0 replies; 10+ messages in thread
From: Pablo Rodriguez @ 2017-07-29 10:46 UTC (permalink / raw)
  To: ntg-context

On 07/29/2017 10:58 AM, Pablo Rodriguez wrote:
> On 07/29/2017 12:57 AM, Aditya Mahajan wrote:
>> [...]
>> \placesidebyside
>>      {\typebuffer[example-1]}
>>      {\getbuffer[setups, example-1]}
> [...]
> Is there now hay to avoid the forced horizontal mode on both sides?

Replying to my own question, a fast fix (although far from perfect)
would be using xtables:

    \def\replacesidebyside#1{%
        \blank\startembeddedxtable[frame=off, option=stretch]
            \startxrow
                \startxcell\typebuffer[#1][option=TEX]\stopxcell
                \startxcell\getbuffer[setups, #1]\stopxcell
            \stopxrow
        \stopembeddedxtable\blank}

    \def\replaceontopofeachother#1{%
        \blank\startembeddedxtable[frame=off, option=stretch]
            \startxrow
                \startxcell\typebuffer[#1][option=TEX]\stopxcell
            \stopxrow
            \startxrow[toffset=1em, split=yes]
                \startxcell\getbuffer[setups, #1]\stopxcell
            \stopxrow
        \stopembeddedxtable\blank}

    \starttext
    \startbuffer[example-1]
    \setupexternalfigures[location=default]
    \starttext
    \ConTeXt\ is awesome!

    \externalfigure[cow.pdf][scale=250]
    \stoptext
    \stopbuffer

Frames won’t be split accross pages. There may be other issues, but none
tham I’m aware of ;-).

Just in case it helps,

Pablo
-- 
http://www.ousia.tk
___________________________________________________________________________________
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] 10+ messages in thread

* Re: source code and result side by side
  2017-07-28 22:57 ` Aditya Mahajan
  2017-07-29  8:58   ` Pablo Rodriguez
@ 2017-07-30 17:13   ` Henning Hraban Ramm
  2017-07-30 18:43     ` Pablo Rodriguez
  2017-07-31  1:26     ` Aditya Mahajan
  1 sibling, 2 replies; 10+ messages in thread
From: Henning Hraban Ramm @ 2017-07-30 17:13 UTC (permalink / raw)
  To: mailing list for ConTeXt users

Am 2017-07-29 um 00:57 schrieb Aditya Mahajan <adityam@umich.edu>:

> On Fri, 28 Jul 2017, Henning Hraban Ramm wrote:
> 
>> Ahoi again,
>> 
>> I’m preparing some ConTeXt docs with a lot of examples and would like to reproduce what we have in the wiki as
>> 
>> <context source="yes">
>> ...
>> </context>
>> 
>> i.e. sourcecode beside the result.
>> 
>> Often the shown source is exactly what I want to show, in other cases I need some additional setup that I don’t want to show.
>> 
>> Which approach would you suggest? Combinations?
> 
> \startbuffer[example-1]
> ....
> \stopbuffer
> 
> 
> \placesidebyside
>    {\typebuffer[example-1]}
>    {\getbuffer[setups, example-1]}


Thank you again, that should be enough for most of my small examples.
I guess I never heard of or forgot about \placesidebyside as well as \placeontopofeachother.

But I’d like to show a lot of similar examples to explain several options.
Therefore, if I’d like to simplify my code, but this doesn’t work:

\def\CodeExample#1{%
\startbuffer[zB]
#1
\stopbuffer
\typebuffer[zB]
\getbuffer[zB]
}

\CodeExample{\framed[frame=off,leftframe=on,rulethickness=1em,framecolor=blue]{Klotz am Bein}}


Compilation just stops, maybe some infinite loop?

Simpler:

\def\CodeExample#1{%
\startTEX
#1
\stopTEX
#1
}


Stops with the error:
Use of \m_syst_action_yes doesn't match its definition




Greetlings, Hraban
---
http://www.fiee.net
http://wiki.contextgarden.net
GPG Key ID 1C9B22FD

___________________________________________________________________________________
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] 10+ messages in thread

* Re: source code and result side by side
  2017-07-30 17:13   ` Henning Hraban Ramm
@ 2017-07-30 18:43     ` Pablo Rodriguez
  2017-07-31  1:26     ` Aditya Mahajan
  1 sibling, 0 replies; 10+ messages in thread
From: Pablo Rodriguez @ 2017-07-30 18:43 UTC (permalink / raw)
  To: ntg-context

On 07/30/2017 07:13 PM, Henning Hraban Ramm wrote:
> [...]
> But I’d like to show a lot of similar examples to explain several options.
> Therefore, if I’d like to simplify my code, but this doesn’t work:
> 
> \def\CodeExample#1{%
> \startbuffer[zB]
> #1
> \stopbuffer
> \typebuffer[zB]
> \getbuffer[zB]
> }
> 
> \CodeExample{\framed[frame=off,leftframe=on,rulethickness=1em,framecolor=blue]{Klotz am Bein}}
> 
> Compilation just stops, maybe some infinite loop?

This is what I get from your sample above.

> Simpler:
> 
> \def\CodeExample#1{%
> \startTEX
> #1
> \stopTEX
> #1
> }
> 
> Stops with the error:

Without or without definitions, there should be no expansion inside
\starttyping...\stoptyping.

Even with some expansion, I get an infinite loop:

\starttext
\setuptyping[TEX][escape=yes]
\def\CodeExample#1{%
\startTEX
/BTEX #1/ETEX
\stopTEX
#1
}
\CodeExample{\framed[frame=off,leftframe=on,rulethickness=1em,framecolor=blue]{Klotz
am Bein}}

\stoptext

Pablo
-- 
http://www.ousia.tk
___________________________________________________________________________________
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] 10+ messages in thread

* Re: source code and result side by side
  2017-07-30 17:13   ` Henning Hraban Ramm
  2017-07-30 18:43     ` Pablo Rodriguez
@ 2017-07-31  1:26     ` Aditya Mahajan
  2017-08-03 19:35       ` Henning Hraban Ramm
  2017-08-03 19:46       ` Henning Hraban Ramm
  1 sibling, 2 replies; 10+ messages in thread
From: Aditya Mahajan @ 2017-07-31  1:26 UTC (permalink / raw)
  To: mailing list for ConTeXt users

[-- Attachment #1: Type: TEXT/PLAIN, Size: 2011 bytes --]

On Sun, 30 Jul 2017, Henning Hraban Ramm wrote:

> Am 2017-07-29 um 00:57 schrieb Aditya Mahajan <adityam@umich.edu>:
>
>> On Fri, 28 Jul 2017, Henning Hraban Ramm wrote:
>> 
>>> Ahoi again,
>>> 
>>> I’m preparing some ConTeXt docs with a lot of examples and would like to reproduce what we have in the wiki as
>>> 
>>> <context source="yes">
>>> ...
>>> </context>
>>> 
>>> i.e. sourcecode beside the result.
>>> 
>>> Often the shown source is exactly what I want to show, in other cases I need some additional setup that I don’t want to show.
>>> 
>>> Which approach would you suggest? Combinations?
>> 
>> \startbuffer[example-1]
>> ....
>> \stopbuffer
>> 
>> 
>> \placesidebyside
>>    {\typebuffer[example-1]}
>>    {\getbuffer[setups, example-1]}
>
>
> Thank you again, that should be enough for most of my small examples.
> I guess I never heard of or forgot about \placesidebyside as well as \placeontopofeachother.
>
> But I’d like to show a lot of similar examples to explain several options.
> Therefore, if I’d like to simplify my code, but this doesn’t work:
>
> \def\CodeExample#1{%
> \startbuffer[zB]
> #1
> \stopbuffer
> \typebuffer[zB]
> \getbuffer[zB]
> }
>
> \CodeExample{\framed[frame=off,leftframe=on,rulethickness=1em,framecolor=blue]{Klotz am Bein}}

You can't do that with buffers. If you need to define your own macros that 
behave like buffers, you need to use \grabbufferdata (see buff-ini.mkiv). 
But in this case, there is a simpler solution:

\defineframed
   [CodeExampleFramed]
   [
     frame=off,
     width=0.5\textwidth,
     align=normal,
   ]

\definebuffer
     [CodeExample]

\define\stopCodeExample
     {\placesidebyside
 	{\CodeExampleFramed{\typeCodeExample}}
 	{\CodeExampleFramed{\getCodeExample}}}


\starttext
\startCodeExample
\framed
   [
     frame=off,
     leftframe=on,
     rulethickness=1em,
     framecolor=blue,
   ]{Klotz am Bein}
\stopCodeExample


\stoptext


[-- Attachment #2: Type: text/plain, Size: 492 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] 10+ messages in thread

* Re: source code and result side by side
  2017-07-31  1:26     ` Aditya Mahajan
@ 2017-08-03 19:35       ` Henning Hraban Ramm
  2017-08-03 19:46       ` Henning Hraban Ramm
  1 sibling, 0 replies; 10+ messages in thread
From: Henning Hraban Ramm @ 2017-08-03 19:35 UTC (permalink / raw)
  To: mailing list for ConTeXt users

Am 2017-07-31 um 03:26 schrieb Aditya Mahajan <adityam@umich.edu>:

> You can't do that with buffers. If you need to define your own macros that behave like buffers, you need to use \grabbufferdata (see buff-ini.mkiv). But in this case, there is a simpler solution:

Thank you very much, I can work with that.

A related question:
How can I use commands like \chapter{} in an example without affecting my main structure?

I’d like to show a few examples für head setups.


Greetlings, Hraban
---
http://www.fiee.net
http://wiki.contextgarden.net
GPG Key ID 1C9B22FD

___________________________________________________________________________________
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] 10+ messages in thread

* Re: source code and result side by side
  2017-07-31  1:26     ` Aditya Mahajan
  2017-08-03 19:35       ` Henning Hraban Ramm
@ 2017-08-03 19:46       ` Henning Hraban Ramm
       [not found]         ` <d7f4de09-e6d8-950b-5a98-6cab8195f959@gmail.com>
  1 sibling, 1 reply; 10+ messages in thread
From: Henning Hraban Ramm @ 2017-08-03 19:46 UTC (permalink / raw)
  To: mailing list for ConTeXt users

Am 2017-07-31 um 03:26 schrieb Aditya Mahajan <adityam@umich.edu>:

> You can't do that with buffers. If you need to define your own macros that behave like buffers, you need to use \grabbufferdata (see buff-ini.mkiv). But in this case, there is a simpler solution:
> 
> \defineframed
>  [CodeExampleFramed]
>  [
>    frame=off,
>    width=0.5\textwidth,
>    align=normal,
>  ]
> 
> \definebuffer
>    [CodeExample]
> 
> \define\stopCodeExample
>    {\placesidebyside
> 	{\CodeExampleFramed{\typeCodeExample}}
> 	{\CodeExampleFramed{\getCodeExample}}}

Oh, I overlooked something:
Can I get pretty printing back, like in \startTEX ... \stopTEX?

I couldn’t find any suitable setup options.

This doesn’t work:
\setupbuffer[CodeExampleB][before={\startTEX},after={\stopTEX}]


Greetlings, Hraban
---
http://www.fiee.net
http://wiki.contextgarden.net
GPG Key ID 1C9B22FD

___________________________________________________________________________________
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] 10+ messages in thread

* Re: source code and result side by side
       [not found]         ` <d7f4de09-e6d8-950b-5a98-6cab8195f959@gmail.com>
@ 2017-08-04 10:32           ` Henning Hraban Ramm
  0 siblings, 0 replies; 10+ messages in thread
From: Henning Hraban Ramm @ 2017-08-04 10:32 UTC (permalink / raw)
  To: mailing list for ConTeXt users

Am 2017-08-04 um 06:30 schrieb Henri Menke <henrimenke@gmail.com>:

> On 08/04/2017 07:46 AM, Henning Hraban Ramm wrote:
>> Am 2017-07-31 um 03:26 schrieb Aditya Mahajan <adityam@umich.edu>:
>> 
>>> You can't do that with buffers. If you need to define your own macros that behave like buffers, you need to use \grabbufferdata (see buff-ini.mkiv). But in this case, there is a simpler solution:
>>> 
>>> \defineframed
>>> [CodeExampleFramed]
>>> [
>>>   frame=off,
>>>   width=0.5\textwidth,
>>>   align=normal,
>>> ]
>>> 
>>> \definebuffer
>>>   [CodeExample]
>>> 
>>> \define\stopCodeExample
>>>   {\placesidebyside
>>> 	{\CodeExampleFramed{\typeCodeExample}}
>>> 	{\CodeExampleFramed{\getCodeExample}}}
>> 
>> Oh, I overlooked something:
>> Can I get pretty printing back, like in \startTEX ... \stopTEX?
>> 
>> I couldn’t find any suitable setup options.
> 
> \typebuffer[whatever][option=tex]

\typebuffer[CodeExample][option=tex] doesn’t do anything,
but \typeCodeExample[option=tex] actually works, I didn’t expect that.
Thank you!


Greetlings, Hraban
---
http://www.fiee.net
http://wiki.contextgarden.net
GPG Key ID 1C9B22FD

___________________________________________________________________________________
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] 10+ messages in thread

end of thread, other threads:[~2017-08-04 10:32 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-07-28 20:34 source code and result side by side Henning Hraban Ramm
2017-07-28 22:57 ` Aditya Mahajan
2017-07-29  8:58   ` Pablo Rodriguez
2017-07-29 10:46     ` Pablo Rodriguez
2017-07-30 17:13   ` Henning Hraban Ramm
2017-07-30 18:43     ` Pablo Rodriguez
2017-07-31  1:26     ` Aditya Mahajan
2017-08-03 19:35       ` Henning Hraban Ramm
2017-08-03 19:46       ` Henning Hraban Ramm
     [not found]         ` <d7f4de09-e6d8-950b-5a98-6cab8195f959@gmail.com>
2017-08-04 10:32           ` Henning Hraban Ramm

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