5

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?

Kuba
  • 136,707
  • 13
  • 279
  • 740
Steve D
  • 2,199
  • 1
  • 17
  • 22
  • 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!" – Szabolcs Feb 07 '14 at 19:02
  • 1
    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? – bill s Feb 07 '14 at 19:20
  • So you are giving them notebook with questions and you want to check this? – Kuba Feb 07 '14 at 19:51
  • @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. – Steve D Feb 07 '14 at 21:15

2 Answers2

7

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.

Simon Woods
  • 84,945
  • 8
  • 175
  • 324
  • 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. – Kuba Feb 07 '14 at 20:54
  • 1
    Heh, poor Mr.Wizard... he's gonna lose a grade by wasting time counting leaves :D – rm -rf Feb 07 '14 at 20:54
  • @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 ;-) – Simon Woods Feb 07 '14 at 21:09
  • 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? – Steve D Feb 07 '14 at 21:12
  • @SteveD You can use NotebookEventActions and send the e-mail yourself. Or just use the trigger to store the value :) – Kuba Feb 07 '14 at 21:20
  • @SimonWoods Lol... I think a lot of people here learned it from Todd Gayley's answer a while ago. – rm -rf Feb 07 '14 at 21:23
  • @Kuba: but how does one store a value in a notebook? That is something I don't know how to do, and haven't gotten the answers to fully work over at http://mathematica.stackexchange.com/questions/5959/saving-data-inside-a-notebook-so-that-i-dont-have-to-run-it-again – Steve D Feb 07 '14 at 21:27
  • @SteveD, try using InputNotebook in place of EvaluationNotebook in those answers – Simon Woods Feb 07 '14 at 21:32
  • 1
    @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. – Szabolcs Feb 08 '14 at 03:04
  • @Kuba see my comment above, and here's the ref: http://mathematica.stackexchange.com/a/1113/12 – Szabolcs Feb 08 '14 at 03:06
  • @Kuba, done.... – Simon Woods Apr 27 '14 at 19:11
  • @SimonWoods Thank you :) – Kuba Apr 27 '14 at 19:11
2

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.

Kuba
  • 136,707
  • 13
  • 279
  • 740