Annotation of loncom/html/adm/help/tex/Authoring_Library_Scripts.tex, revision 1.4

1.1       lira        1: \label{Authoring_Library_Scripts}
                      2: 
                      3: A LON-CAPA .library file can contain just a script block, or just
                      4: response items, or both.  A LON-CAPA problem can import as many published library 
                      5: files as desired. A .library file always starts with a $<$library$>$ tag, and 
                      6: always ends with a $<$/library$>$ tag.\index{library}
                      7: 
                      8: \null
                      9: \noindent \textbf{Storing entire scripts}
                     10: 
                     11: Entire scripts can be stored in a library file. The entire script can then be imported
                     12: into a problem file. \index{library}\index{random\_permutation}
                     13: 
                     14: \null
                     15: \noindent Library file:
                     16: \begin{verbatim}
                     17: <library>
                     18: <script type="loncapa/perl">
                     19: @alpha=('A','B','C','D',);
                     20: $seed=&random(1,1000000,1);
                     21: @alpha=&random_permutation($seed,@alpha); #scramble order
                     22: $letter = $alpha[0]; #select first element
                     23: </script>
                     24: </library>
                     25: \end{verbatim}
                     26: 
                     27: \noindent Problem file:
                     28: \begin{verbatim}
                     29: <problem>
                     30: <import id="15">randomletter.library</import>
                     31: <startouttext />The random letter is $letter.<endouttext />
                     32: <!-- other problem tags could go here -->
                     33: </problem>
                     34: \end{verbatim}
                     35: 
                     36: \null
                     37: \noindent \textbf{Storing a portion of a script}
                     38: 
                     39: A portion of a script, such as a large data array can be stored in a library file.
                     40: 
                     41: \null 
                     42: \noindent Library file:
                     43: \begin{verbatim}
                     44: <library>
                     45: <script type="loncapa/perl">
                     46: @alpha=('A','B','C','D',);
                     47: $seed=&random(1,1000000,1);
                     48: @alpha=&random_permutation($seed,@alpha); #scramble order
                     49: </script>
                     50: </library>
                     51: \end{verbatim}
                     52: 
                     53: \noindent Problem file: (note the $<$script$>$ tag is repeated and other
                     54: script calculations can be done using variables from the library file.)
                     55: \begin{verbatim}
                     56: <problem>
                     57: <import id="15">randomletter.library</import>
                     58: <script type="loncapa/perl">
                     59: $letter = $alpha[0];
                     60: </script>
                     61: <startouttext />The random letter is $letter.<endouttext />
                     62: <!-- other problem tags could go here. -->
                     63: </problem>
                     64: \end{verbatim}
                     65: 
                     66: \null
                     67: \noindent \textbf{Storing a subroutine}
                     68: 
                     69: Another use of a .library file is to define a subroutine which you plan
                     70: to call in a number of instances, e.g., (see notes below about browsing libraries
                     71: in the repository to see the contents of this subroutine)
                     72: 
                     73: \begin{verbatim}
                     74: /res/msu/raeburn/cleaneq.library
                     75: \end{verbatim}
                     76: 
                     77: Here is some example XML problem code
                     78: which makes a call to the \&cleaneq() routine defined in the library file, passing
1.4     ! raeburn    79: some arguments: \$eq,`x',`y',`z' in the call to the routine.
1.1       lira       80: 
                     81: \begin{verbatim}
                     82: <problem>
                     83: <import id="15">/res/msu/raeburn/cleaneq.library</import>
                     84: 
                     85: <script type="loncapa/perl">
                     86: $eq = "1x + 0y +-7z --3";
                     87: $eq2 = &cleaneq($eq,'x','y','z');</script>
                     88: <startouttext />Here is an example equation:<br />
                     89: Without cleaneq: $eq<br />
                     90: With cleaneq: $eq2<endouttext />
                     91: </problem>
                     92: \end{verbatim}
                     93: 
                     94: \null
                     95: \noindent \textbf{Assigning random problems using libraries}
                     96: Libraries can be used to store alternative parts of problems which are
                     97: selected with the $<$randomlist$>$ tag.\index{randomlist}\index{randomizing parts}
                     98: The .library file
                     99: hold the all content that would normally appear inside the $<$part$>$ tag.
                    100: \begin{verbatim}
                    101: <part id="11">
                    102: <randomlist show="1">
                    103: <import id="12">sample1.library< /import>
                    104: <import id="13">sample2.library< /import>
                    105: <import id="14">sample3.library< /import>
                    106: < /randomlist>
                    107: < /part>
                    108: <part id="15">
                    109: <randomlist show="1">
                    110: <import id="16">sample4.library< /import>
                    111: <import id="17">sample5.library< /import>
                    112: <import id="18">sample6.library< /import>
                    113: < /randomlist>
                    114: < /part>
                    115: \end{verbatim}
                    116: 
1.2       lira      117: Note: when using $<$randomlist$>$ as shown above, all students will work
                    118: every part of the problem, but the actual problem statements will be different. Another
                    119: option is to wrap multiple $<$part$>$ tags but then not all students will work
                    120: all parts unless the value of `show' equals the total parts wrapped. For more
                    121: information see section \ref{Authoring_Scripting_Tags}.
1.1       lira      122: 
                    123: \null 
                    124: \noindent \textbf{Viewing the text contents of a library script block}
                    125: 
                    126: If you click on a .library file when browsing the shared content
                    127: repository, and the .library file contains just a script block, then
                    128: nothing will be displayed in the pop-up window.
                    129: 
                    130: The code is viewable if the author has enabled access to the source
                    131: XML when publishing a .library item that is pure script block.  If that
                    132: is done, then when a user checks the ``Source Available'' checkbox when
                    133: browsing the shared content pool, a link will be displayed for items
                    134: with available source code. Clicking the ``Source Code'' link for
                    135: any such items will open a pop-up which displays the content of the library
                    136: file. It is good practice to enable access to the source code when publishing any 
                    137: library that will be shared. Otherwise, users cannot see it.
                    138: 
                    139: \null
                    140: \noindent \textbf{Viewing variables from a library script during testing}
                    141: 
                    142: When viewing a problem in the problem testing mode of Authoring Space, 
                    143: you will see a separate
                    144: Script Vars link at the bottom of the testing area for each script block 
                    145: (either a block included directly
                    146: within the file, or a block included within a library file imported into
                    147: a problem). By clicking the respective link, you can view variable values from
                    148: the respective script.\index{script variables, viewing}
                    149: 
                    150: \null
                    151: \noindent \textbf{Accessing submissions from a problem part loaded from a library}
                    152: 
                    153: When *response items (e.g., *response is a wildcard such as optionresponce, 
                    154: stringresponse, numericalresponse, etc.)\index{*response} are defined in a
                    155: .library file, this results in an extra id item in the identifier
                    156: required in \&EXT() \index{\&EXT}functions, e.g., if a problem contains two parts with
1.3       lira      157: ids of a and b respectively, and the id of the $<$import$>$ for the .library is 15, 
1.4     ! raeburn   158: and the *response items have ids of 11 and 12 respectively, the
1.1       lira      159: most recent submissions could be retrieved with the following \&EXT() calls.\index{\&EXT}
                    160: 
1.4     ! raeburn   161: \texttt{\&EXT(\char`\"{}user.resource.resource.a.15\_11.submission\char`\"{});}
1.1       lira      162: 
1.4     ! raeburn   163: \texttt{\&EXT(\char`\"{}user.resource.resource.b.15\_12.submission\char`\"{});}
1.1       lira      164: 

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>