Re: [NTG-context] Subject: Leading spaces verbatim

2023-01-30 Thread Ulrike Fischer via ntg-context
Am Sat, 28 Jan 2023 03:01:24 +0100 schrieb Kalouguine Andre via
ntg-context:

> I'm trying to make a verbatim block of text with copiable leading spaces
> so that students can just copy my Python code snippets into their IDE.

This basically doesn't work (quite unrelated to the tex code). 
The PDF viewers have all their own mind here and none of them is
really "code friendly". See e.g. 

https://tex.stackexchange.com/a/472112/2388

It works sometimes a bit better if the PDF is tagged, but there too
you can't currently rely on four spaces staying four spaces (and not
all PDF reader understand tagging).

Better attach files with code. 

-- 
Ulrike Fischer 
http://www.troubleshooting-tex.de/

___
If your question is of interest to others as well, please add an entry to the 
Wiki!

maillist : ntg-context@ntg.nl / https://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : https://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki : https://contextgarden.net
___


Re: [NTG-context] Subject: Leading spaces verbatim

2023-01-30 Thread Pablo Rodriguez via ntg-context
On 1/29/23 17:58, Kalouguine Andre via ntg-context wrote:
> On 28.01.2023 22:54, Hans Hagen via ntg-context wrote:
>> […]
>> so: this is all very viewer dependent! (The suggested comment method
>> is more reliable.)
>  
> Unfortunately as I just found out, comments are also viewer dependent...
> For instance in Firefox, indentations are lost.

Hi André,

as far as I know, this may be a bug in PDF.js.

Could you report it to the developers (https://github.com/mozilla/pdf.js)?

Many thanks for your help,

Pablo

___
If your question is of interest to others as well, please add an entry to the 
Wiki!

maillist : ntg-context@ntg.nl / https://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : https://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki : https://contextgarden.net
___


Re: [NTG-context] Subject: Leading spaces verbatim

2023-01-29 Thread Kalouguine Andre via ntg-context
On 28.01.2023 22:54, Hans Hagen via ntg-context wrote:

> On 1/28/2023 9:26 PM, Kalouguine Andre via ntg-context wrote: On 28.01.2023 
> 17:37, Pablo Rodriguez via ntg-context wrote:
> 
> Using Fedora 37 (and having just installed Okular), I see that
> annotations are tricky to open in Okular.
> 
> First you have to select the Annotations tab on the left pane, go to the
> annotation and then right-click on it to open (the pop-up note).
> 
> Evince has a more effective approach: double-clicking on the icon opens
> the note (afaIk, this is similar to Acrobat). Right you are, it works with 
> your method, thanks!
> I think the students have Evince so perhaps it's the best solution in the 
> absence
 there are some provisions for spaces in text but for verbatim it is a
bit more tricky

\setuptyping[space=on]

you now see visual spaces show up that can be copied

now, say that we add real spaces, which you can do after and this (in
cont-new.mkxl):

\unprotect
\setvalue{\??typingspace\v!character}{\chardef\obeyedspace32 }
\protect

and then:

\setuptyping[space=character]

in sumatra pdf:

default   : spaces are copied as spaces (so three become three
on: visual spaces for every one
character : funny newlines when more than two spaces 

OK, I see, thanks for the explanation! Indeed, when I look at the
makeup, there is no glue there to offset the line. But in Okular it just
ignores those spaces. 

> Cheats that add some kerning before and after confuse viewers even more.
> 
> so: this is all very viewer dependent! (The suggested comment method is more 
> reliable.)
> 
> Hans

Unfortunately as I just found out, comments are also viewer dependent...
For instance in Firefox, indentations are lost. 

So for now, attached files for longer snippets and visual spaces with a
string replacement operation afterwards are the way to go it seems. 

Best regards, 
Andre___
If your question is of interest to others as well, please add an entry to the 
Wiki!

maillist : ntg-context@ntg.nl / https://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : https://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki : https://contextgarden.net
___


Re: [NTG-context] Subject: Leading spaces verbatim

2023-01-28 Thread Hans Hagen via ntg-context

On 1/28/2023 9:26 PM, Kalouguine Andre via ntg-context wrote:

On 28.01.2023 17:37, Pablo Rodriguez via ntg-context wrote:


Using Fedora 37 (and having just installed Okular), I see that
annotations are tricky to open in Okular.

First you have to select the Annotations tab on the left pane, go to the
annotation and then right-click on it to open (the pop-up note).

Evince has a more effective approach: double-clicking on the icon opens
the note (afaIk, this is similar to Acrobat).

Right you are, it works with your method, thanks!
I think the students have Evince so perhaps it's the best solution in 
the absence
there are some provisions for spaces in text but for verbatim it is a 
bit more tricky


\setuptyping[space=on]

you now see visual spaces show up that can be copied

now, say that we add real spaces, which you can do after and this (in 
cont-new.mkxl):


\unprotect
\setvalue{\??typingspace\v!character}{\chardef\obeyedspace32 }
\protect

and then:

\setuptyping[space=character]

in sumatra pdf:

default   : spaces are copied as spaces (so three become three
on: visual spaces for every one
character : funny newlines when more than two spaces

Cheats that add some kerning before and after confuse viewers even more.

so: this is all very viewer dependent! (The suggested comment method is 
more reliable.)


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://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : https://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki : https://contextgarden.net
___


Re: [NTG-context] Subject: Leading spaces verbatim

2023-01-28 Thread Kalouguine Andre via ntg-context
On 28.01.2023 17:37, Pablo Rodriguez via ntg-context wrote:

> Using Fedora 37 (and having just installed Okular), I see that
> annotations are tricky to open in Okular.
> 
> First you have to select the Annotations tab on the left pane, go to the
> annotation and then right-click on it to open (the pop-up note).
> 
> Evince has a more effective approach: double-clicking on the icon opens
> the note (afaIk, this is similar to Acrobat).

Right you are, it works with your method, thanks! 
I think the students have Evince so perhaps it's the best solution in
the absence 
of copiable spaces in verbatim mode. 
Thanks again! 
Best regards, 
Andre___
If your question is of interest to others as well, please add an entry to the 
Wiki!

maillist : ntg-context@ntg.nl / https://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : https://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki : https://contextgarden.net
___


Re: [NTG-context] Subject: Leading spaces verbatim

2023-01-28 Thread Pablo Rodriguez via ntg-context
On 1/28/23 14:31, Kalouguine Andre via ntg-context wrote:
> Hi Pablo,

Hi André,

> [...]  
> That's actually something I had never thought of, using PDF comments,
> thanks!.

When I faced a similar task, I thought it could be the way of solving
the issue (how to copy and paste ConTeXt code and console commands).

> It's a really nice approach, though weirdly it doesn't work on
> Okular (Linux+KDE) for me, even though attachments worked fine. I'll
> try and see why that is.
Using Fedora 37 (and having just installed Okular), I see that
annotations are tricky to open in Okular.

First you have to select the Annotations tab on the left pane, go to the
annotation and then right-click on it to open (the pop-up note).

Evince has a more effective approach: double-clicking on the icon opens
the note (afaIk, this is similar to Acrobat).

I hope this helps,

Pablo
___
If your question is of interest to others as well, please add an entry to the 
Wiki!

maillist : ntg-context@ntg.nl / https://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : https://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki : https://contextgarden.net
___


Re: [NTG-context] Subject: Leading spaces verbatim

2023-01-28 Thread Kalouguine Andre via ntg-context
Hi Pablo,

> \showframe
> \setupinteraction[state=start]
> \starttext
> \startbuffer[abc]
> def foo(x):
> if x == 0:
> bar()
> else:
> baz(x)
> foo(x - 1)
> \stopbuffer
> \comment[location=leftmargin,
> space=yes,
> buffer=abc,
> title={Python code}]
> {}\typebuffer[abc]
> \stoptext
> 
> This might solve what you need. At least, this is the approach that I
> use to provide text that can be directly copied.
> 
> I'm on Linux and last time I tested on Windows there were extra lines in
> the comments.

That's actually something I had never thought of, using PDF comments,
thanks!. 
It's a really nice approach, though weirdly it doesn't work on Okular
(Linux+KDE) 
for me, even though attachments worked fine. I'll try and see why that
is. 

What I had in mind was rather the following: 

\starttext 
\starttyping[space=on] 
def foo(x):
y = bar(x) 
if y: 
return x 
return y 
foo(1) 
\stoptyping 
\stoptext

but with ordinary char32 spaces rather than \textcontrolspace
characters. 

Best regards,___
If your question is of interest to others as well, please add an entry to the 
Wiki!

maillist : ntg-context@ntg.nl / https://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : https://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki : https://contextgarden.net
___


Re: [NTG-context] Subject: Leading spaces verbatim

2023-01-28 Thread Pablo Rodriguez via ntg-context
On 1/28/23 03:01, Kalouguine Andre via ntg-context wrote:
> Good day to everyone,
> 
> I'm trying to make a verbatim block of text with copiable leading spaces
> so that students can just copy my Python code snippets into their IDE.

Hi André,

I wonder whether I’m getting your point with the following sample:

  \showframe
  \setupinteraction[state=start]
  \starttext
  \startbuffer[abc]
  def foo(x):
  if x == 0:
  bar()
  else:
  baz(x)
  foo(x - 1)
  \stopbuffer
  \comment[location=leftmargin,
space=yes,
buffer=abc,
title={Python code}]
{}\typebuffer[abc]
  \stoptext

This might solve what you need. At least, this is the approach that I
use to provide text that can be directly copied.

I’m on Linux and last time I tested on Windows there were extra lines in
the comments.

Just in case it might help,

Pablo
___
If your question is of interest to others as well, please add an entry to the 
Wiki!

maillist : ntg-context@ntg.nl / https://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : https://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki : https://contextgarden.net
___