Re: [NTG-context] Clickable question/answer numbers

2016-11-04 Thread Mikael P. Sundqvist
Thank you very much Wolfgang!

Now I can get exactly what I need, see the example below (also tested
with my larger document, available at
http://www.maths.lth.se/matematiklth/personal/mickep/analysB2ht16/analys-context.pdf).

I'm very happy about this solution. Also, thanks to Hans for giving us
this very nice tool (I usually only write to the list when I have
problems, sorry)!

Best regards, Mikael

\definecolor[contrastcolor][darkred]
\defineintermediatecolor[contrastbgcolor][0.6,contrastcolor,white]

\setupinteraction[state=start,color=,contrastcolor=,style=]

\defineblock[answer]
\hideblocks[answer]

\def\myanswer[#1]{\inleft{\in[#1]\reference[A:#1]{\in[#1]}}}

\def\myheadcommand#1{\goto{Question #1}[A:\currentconstructionreference]}

\defineenumeration[question][
text=,
title=yes,
titlestyle=,
titlecolor=black,
headcommand={\myheadcommand},
headstyle={\sc},
headcolor=contrastcolor,
style=,
alternative=serried,
width=fit,
number=yes,
prefix=yes,
prefixsegments=chapter,
way=bychapter,
indentnext=no,
indenting=yes,
before={\testpage[2]\blank[big]},
after={\blank[big,samepage]},
]

\starttext

\section{A section with questions}

\startquestion[Q:test]{This is a title}
This is a question with title.
\stopquestion

\beginanswer
\myanswer[Q:test]
This is an answer
\endanswer

\startquestion[Q:test2]
This is a question without title.
\startformula
(a+b)^2=a^2+ab+ba+b^2.
\stopformula
\stopquestion

\beginanswer
\myanswer[Q:test2]
This is an answer.
\endanswer


\startquestion
This is a question without reference. It cannot have any answer.
\stopquestion


\page[yes]

\subject{Answers}

\useblocks[answer]

\stoptext

On Fri, Nov 4, 2016 at 12:50 PM, Wolfgang Schuster
 wrote:
> Mikael P. Sundqvist
> 3. November 2016 um 16:14
> Dear Otared (and others),
>
> while waiting for Hans reply on the \namedenumerationparameter and
> \enumerationparameter, this is the best I could do. Now, only
> "Question" is clickable and not the number, but I think I could live
> with that if no other solution show up.
>
> The reference value is set in a group and can only be accessed within this
> group
> but you can use \currentconstructionreference to access it.
>
> \setupinteraction[state=start]
>
> \define[1]\QuestionTextCommand
>
> {\doifreferencefoundelse{answer:\cldcontext{lpeg.match(lpeg.secondofsplit(":"),"\currentconstructionreference")}}
>
> {\goto{#1}[answer:\cldcontext{lpeg.match(lpeg.secondofsplit(":"),"\currentconstructionreference")}]}
>  {#1}}
>
> \define[1]\AnswerTextCommand
>
> {\doifreferencefoundelse{question:\cldcontext{lpeg.match(lpeg.secondofsplit(":"),"\currentconstructionreference")}}
>
> {\goto{#1}[question:\cldcontext{lpeg.match(lpeg.secondofsplit(":"),"\currentconstructionreference")}]}
>  {#1}}
>
> \defineenumeration [question]
> [text=Question,headcommand=\QuestionTextCommand]
> \defineenumeration [answer]   [text=Answer,headcommand=\AnswerTextCommand]
>
> \starttext
>
> \startquestion[question:knuth]
> \input knuth
> \stopquestion
>
> \page
>
> \startanswer[answer:knuth]
> \input knuth
> \stopanswer
>
> \stoptext
>
> Wolfgang
>
> ___
> 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
> ___
___
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
___

Re: [NTG-context] Clickable question/answer numbers

2016-11-04 Thread Wolfgang Schuster

Mikael P. Sundqvist 
3. November 2016 um 16:14
Dear Otared (and others),

while waiting for Hans reply on the \namedenumerationparameter and
\enumerationparameter, this is the best I could do. Now, only
"Question" is clickable and not the number, but I think I could live
with that if no other solution show up.
The reference value is set in a group and can only be accessed within 
this group

but you can use \currentconstructionreference to access it.

\setupinteraction[state=start]

\define[1]\QuestionTextCommand
  
{\doifreferencefoundelse{answer:\cldcontext{lpeg.match(lpeg.secondofsplit(":"),"\currentconstructionreference")}}
 
{\goto{#1}[answer:\cldcontext{lpeg.match(lpeg.secondofsplit(":"),"\currentconstructionreference")}]}

 {#1}}

\define[1]\AnswerTextCommand
  
{\doifreferencefoundelse{question:\cldcontext{lpeg.match(lpeg.secondofsplit(":"),"\currentconstructionreference")}}
 
{\goto{#1}[question:\cldcontext{lpeg.match(lpeg.secondofsplit(":"),"\currentconstructionreference")}]}

 {#1}}

\defineenumeration [question] 
[text=Question,headcommand=\QuestionTextCommand]

\defineenumeration [answer]   [text=Answer,headcommand=\AnswerTextCommand]

\starttext

\startquestion[question:knuth]
\input knuth
\stopquestion

\page

\startanswer[answer:knuth]
\input knuth
\stopanswer

\stoptext

Wolfgang
___
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
___

Re: [NTG-context] Bug in latest beta, shifted metapost (possibly with drawarrow)

2016-11-04 Thread Hans Hagen

On 11/3/2016 5:09 PM, Mikael P. Sundqvist wrote:

Dear list,

the example below has shifted axes. I updated to the latest standalone
earlier today. The problem was not present some weeks ago.

In particular look at the red line that should start from the origin...

\starttext
\startMPpage
ut:=1.0cm;
ux:=0.6cm;

vardef diffp(expr riktn) =
 ((-1,0)--(1,0)) rotatedaround (origin,angle(ut,riktn*ux))
enddef;

path taxel,xaxel;
taxel:=((-1.4,0)--(5.4,0));
xaxel:=((0,-1.4)--(0,4.6));
drawarrow taxel xyscaled(ut,ux);
drawarrow xaxel xyscaled(ut,ux);

label.bot("$t$", (point length(taxel) of taxel) xyscaled(ut,ux));
label.lft("$P$", (point length(xaxel) of xaxel) xyscaled(ut,ux));

draw image(
 vardef fun(expr t, x) = x*(3-x) enddef;
 for i=-1 step 0.5 until 5 :
  for j=-1 step 0.5 until 4 :
ii:=i;
jj:=j;
draw diffp(fun(ii,jj)) scaled 2bp shifted (ii*ut,jj*ux);
  endfor;
 endfor;

draw function (2, "x", "3/(1+2*exp(-3*x))" ,-1, 5, 1/5) xyscaled (ut,ux);

draw (0,0)--(3,3) xyscaled(ut,ux) withcolor darkred;

);
\stopMPpage
\stoptext


I'll fix it. Alan: we really need this one then:

vardef image@#(text t) =
save currentpicture ;
picture currentpicture ;
currentpicture := nullpicture ;
t ;
currentpicture
if str @# <> "" :
shifted (
  mfun_labxf@#   * lrcorner currentpicture
 + mfun_labyf@#  * ulcorner currentpicture
 + (1-mfun_labxf@#-mfun_labyf@#) * llcorner currentpicture
)
fi
enddef ;




--

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

Re: [NTG-context] Clickable question/answer numbers

2016-11-04 Thread Otared Kavian
Hi Mikael,

Thank you for sharing the solution you found!

Your definitions suit me too, but in any case I’ll play with your code to see 
whether using the concept of « coupling » between each exercise and its 
solution (or hint, if one adds them) could allow the creation of an automatic 
interaction link between them, so that one can remove the necessity of adding 
manually a reference to each exercise and each solution.

Best regards: OK


> On 3 Nov 2016, at 16:14, Mikael P. Sundqvist  wrote:
> 
> Dear Otared (and others),
> 
> while waiting for Hans reply on the \namedenumerationparameter and
> \enumerationparameter, this is the best I could do. Now, only
> "Question" is clickable and not the number, but I think I could live
> with that if no other solution show up.
> 
> Best regards, Mikael
> 
> \usemodule[references-show]
> 
> \setupinteraction[state=start,color=,contrastcolor=,style=]
> 
> \defineblock[answer]
> \hideblocks[answer]
> 
> \def\myanswer[#1]{\inleft{\in[#1]\reference[A:#1]{\in[#1]}}}
> 
> 
> \defineenumeration[exercise][
> text=Question,
> title=yes,
> titlestyle=,
> titlecolor=black,
> headstyle={\sc},
> headcolor=darkred,
> style=,
> number=yes,
> ]
> 
> 
> 
> \def\startquestion{\dodoubleempty\dostartquestion}
> 
> \long\def\dostartquestion[#1][#2]#3\stopquestion{%
>  \iffirstargument
>\setupenumeration[exercise][text={\goto{Question}[A:#1]}]
>\ifsecondargument
>  \startexercise[#1]{#2}
>\else
>  \startexercise[#1]
>\fi
>  \else
>\setupenumeration[exercise][text=Question]
>\startexercise
>  \fi
>  #3
> }
> 
> \def\stopquestion{\stopexercise}
> 
> 
> \starttext
> 
> \section{A section with questions}
> 
> \startquestion[Q:test][This is a title]
> This is a question with title.
> \stopquestion
> 
> \beginanswer
> \myanswer[Q:test]
> This is an answer
> \endanswer
> 
> \startquestion[Q:test2]
> This is a question without title.
> \startformula
> (a+b)^2=a^2+ab+ba+b^2.
> \stopformula
> \stopquestion
> 
> \beginanswer
> \myanswer[Q:test2]
> This is an answer.
> \endanswer
> 
> 
> \startquestion
> This is a question without reference. It cannot have any answer.
> \stopquestion
> 
> 
> \page[yes]
> 
> \subject{Answers}
> 
> \useblocks[answer]
> 
> \stoptext
> 
> On Thu, Nov 3, 2016 at 12:58 PM, Mikael P. Sundqvist  wrote:
>> Dear Hans,
>> 
>> This seems to be exactly what I need, but I cannot get it to work.
>> With the example below nothing comes from those
>> commands (I just updated my standalone to the latest one). On the
>> other hand, with text instead of reference it works.
>> 
>> Best regards, Mikael
>> 
>> \defineenumeration[question][
>> text=Question,
>> ]
>> 
>> \starttext
>> \startquestion[test]
>> This question has reference
>> \namedenumerationparameter{question}{reference} which could also
>> be achieved via \enumerationparameter{reference}. On the other hand,
>> \namedenumerationparameter{question}{text}
>> gives Question as assumed.
>> \stopquestion
>> 
>> \startquestion[reference=test2]
>> This question has reference
>> \namedenumerationparameter{question}{reference} which could also
>> be achieved via \enumerationparameter{reference}. On the other hand,
>> \namedenumerationparameter{question}{text}
>> gives Question as assumed.
>> \stopquestion
>> \stoptext
>> 
>> On Thu, Nov 3, 2016 at 10:34 AM, Hans Hagen  wrote:
>>> On 11/2/2016 9:58 PM, Mikael P. Sundqvist wrote:
 
 Dear Otared,
 
 thank you again. This is somehow a proof that it should work. In my
 real document I use the title to name some exercises (after old
 exams), and I don't see how that can be combined with your solution.
 
 If someone else reads this: I think the question boils down to the
 following:
 
 \startquestion[Q:test]
 How can I here automatically get access to to the string "Q:test"?
 \stopquestion
>>> 
>>> 
>>> it depends what automatically means
>>> 
>>> \enumerationparameter{reference}
>>> 
>>> or
>>> 
>>> \namedenumerationparameter{question}{reference}
>>> 
>>> 
 Best regards, Mikael
 
 On Wed, Nov 2, 2016 at 9:04 PM, Otared Kavian  wrote:
> 
> Hi Mikael,
> 
> A partial solution to the feature we are discussing is contained in the
> example below, but somone more aware of ConTeXtish coding might improve 
> it.
> It is not satisfactory in that one has to define twice \startquestion and
> \StartQuestion, \beginanswer and \BeginAnswer, and more importantly one
> cannot generate automatically the references (I tried \getnumber[question]
> and such to append to Q:\getnumber[question] for instance, but something
> does not work…).
> 
> Le me know if you find a satisfactory solution…
> 
> Best regards: OK
> %%% begin interactive-question-answer.tex
> \setupinteraction[state=start,color=,contrastcolor=,style=]
> 
> \defineblock[answer]
> \hideblocks[answer]