5
$\begingroup$

I teach an Intro to Mathematica course, and one of the things I try to reinforce early on is just how helpful Mathematica's help is. In the very first lab for the course, I even give the students a randomly selected command (from among simple ones like PrimeQ, IntegerDigits, etc.) and ask them to tell me what that command does. As of right now, they get this question right if they correctly explain what the given command does.

What I'd like to do is make sure they are actually going to the help. Is there some way to capture an F1 key press within an EventHandler or something similar?

$\endgroup$
5
  • $\begingroup$ If it helps, MemberQ[Contexts[], "DocumentationSearch`"] will only start returning True after the documentation search has been used at least once in the session ... Otherwise I think it's really the students' responsibility to listen to something as simple as "use the documentation!" $\endgroup$
    – Szabolcs
    Commented Feb 7, 2014 at 19:02
  • 1
    $\begingroup$ Trying to make sure they press F1 may not be such a good idea... what if they go to help by typing ? or by searching google? If you want to make sure they go to help, ask a question like: how many items are there in the examples subsection of the help page? $\endgroup$
    – bill s
    Commented Feb 7, 2014 at 19:20
  • $\begingroup$ So you are giving them notebook with questions and you want to check this? $\endgroup$
    – Kuba
    Commented Feb 7, 2014 at 19:51
  • $\begingroup$ related: link to the currently opened help page $\endgroup$
    – Kuba
    Commented Feb 7, 2014 at 20:16
  • $\begingroup$ @bills: I actually would like to make sure they visit the help, however they do it. It's just that I explain the F1 option to them in class, which is why I would expect most would go that route. $\endgroup$
    – Steve D
    Commented Feb 7, 2014 at 21:15

2 Answers 2

7
$\begingroup$

You could add a trap to Documentation`HelpLookup which is called when F1 is pressed:

Unprotect[Documentation`HelpLookup];
Documentation`HelpLookup[link_String, nb_, lang_String, opts : OptionsPattern[]] :=
 Block[{$inblock = True},
   lookedup[link] = True;
   Documentation`HelpLookup[link, nb, opts]] /; ! TrueQ[$inblock]

You can add whatever code you want. As an example I assign a downvalue to lookedup so the searched expressions can be viewed with ? lookedup

Note: The Block[{$in = True}, ...] /; ! TrueQ[$in] construct is the Villegas-Gayley technique for injecting code into built-in functions.

$\endgroup$
12
  • $\begingroup$ It seems it is called whenever documentation page is opened. So not only with F1 but also when you dig throught See also... or if you open documentation in menu. $\endgroup$
    – Kuba
    Commented Feb 7, 2014 at 20:54
  • 1
    $\begingroup$ Heh, poor Mr.Wizard... he's gonna lose a grade by wasting time counting leaves :D $\endgroup$
    – rm -rf
    Commented Feb 7, 2014 at 20:54
  • $\begingroup$ @rm-rf, ha ha. I didn't see that question 2 days ago, I was hoping everyone would be stunned by my spelunking skills, now it just looks like I'm copying from higher rep users ;-) $\endgroup$ Commented Feb 7, 2014 at 21:09
  • $\begingroup$ This is great, but is there any way to store the lookedup variable between sessions? The students will do the lab, close it, send it to me, then I open it. Any way I can still find out what help items they've visited? $\endgroup$
    – Steve D
    Commented Feb 7, 2014 at 21:12
  • 1
    $\begingroup$ @SteveD "but how does one store a value in a notebook?" --> use TaggingRules! This is better than making up an option like Stored and it was recommended in the past as the solution to use. 1. Check the value of CurrentValue[SelectedNotebook[], {TaggingRules, "lookups"}]. If it's "Inherited", then initialize it: CurrentValue[SelectedNotebook[], {TaggingRules, "lookups"}] = {}. Then keep appending AppendTo[CurrentValue[ SelectedNotebook[], {TaggingRules, "lookups"}], "asd"]. When they save the notebook, this gets saved with it. $\endgroup$
    – Szabolcs
    Commented Feb 8, 2014 at 3:04
2
$\begingroup$

This is my idea.

If you give them the notebook with questions just put the following code in the cell with a question text (as InlineCell Alt+9)

DynamicModule[{},
 DynamicWrapper["test",
   Refresh[
    help = DeleteDuplicates @ Join[help, "WindowTitle" /. NotebookInformation /@
    Select[Notebooks[], ("DocumentType" /. NotebookInformation[#]) == "Help" &]]
    , UpdateInterval -> .5]]
 , Initialization :> (help = {};)]

Then EvaluateInPlace this with Ctrl+Shift+Enter or via menu.

There is now variable help that will show you which documentation pages were opened.

Test this with

Dynamic@help
{Dynamic - Wolfram Mathematica, Animate - Wolfram Mathematica,...}

You can work on this to get the date etc. The only problem is it will show a message that the notebook contains dynamic content.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.