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

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>
1.5     ! damieng    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>
1.1       lira       24: </library>
                     25: \end{verbatim}
                     26: 
                     27: \noindent Problem file:
                     28: \begin{verbatim}
                     29: <problem>
1.5     ! damieng    30:   <import id="15">randomletter.library</import>
        !            31:   <startouttext />The random letter is $letter.<endouttext />
        !            32:   <!-- other problem tags could go here -->
1.1       lira       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>
1.5     ! damieng    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>
1.1       lira       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>
1.5     ! damieng    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. -->
1.1       lira       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>
1.5     ! damieng    83:   <import id="15">/res/msu/raeburn/cleaneq.library</import>
1.1       lira       84: 
1.5     ! damieng    85:   <script type="loncapa/perl">
        !            86:     $eq = "1x + 0y +-7z --3";
        !            87:     $eq2 = &cleaneq($eq,'x','y','z');
        !            88:   </script>
        !            89:   <startouttext />Here is an example equation:<br />
        !            90:   Without cleaneq: $eq<br />
        !            91:   With cleaneq: $eq2<endouttext />
1.1       lira       92: </problem>
                     93: \end{verbatim}
                     94: 
                     95: \null
                     96: \noindent \textbf{Assigning random problems using libraries}
                     97: Libraries can be used to store alternative parts of problems which are
                     98: selected with the $<$randomlist$>$ tag.\index{randomlist}\index{randomizing parts}
                     99: The .library file
                    100: hold the all content that would normally appear inside the $<$part$>$ tag.
                    101: \begin{verbatim}
                    102: <part id="11">
1.5     ! damieng   103:   <randomlist show="1">
        !           104:     <import id="12">sample1.library</import>
        !           105:     <import id="13">sample2.library</import>
        !           106:     <import id="14">sample3.library</import>
        !           107:   </randomlist>
        !           108: </part>
1.1       lira      109: <part id="15">
1.5     ! damieng   110:   <randomlist show="1">
        !           111:     <import id="16">sample4.library</import>
        !           112:     <import id="17">sample5.library</import>
        !           113:     <import id="18">sample6.library</import>
        !           114:   </randomlist>
        !           115: </part>
1.1       lira      116: \end{verbatim}
                    117: 
1.2       lira      118: Note: when using $<$randomlist$>$ as shown above, all students will work
                    119: every part of the problem, but the actual problem statements will be different. Another
                    120: option is to wrap multiple $<$part$>$ tags but then not all students will work
                    121: all parts unless the value of `show' equals the total parts wrapped. For more
                    122: information see section \ref{Authoring_Scripting_Tags}.
1.1       lira      123: 
                    124: \null 
                    125: \noindent \textbf{Viewing the text contents of a library script block}
                    126: 
                    127: If you click on a .library file when browsing the shared content
                    128: repository, and the .library file contains just a script block, then
                    129: nothing will be displayed in the pop-up window.
                    130: 
                    131: The code is viewable if the author has enabled access to the source
                    132: XML when publishing a .library item that is pure script block.  If that
                    133: is done, then when a user checks the ``Source Available'' checkbox when
                    134: browsing the shared content pool, a link will be displayed for items
                    135: with available source code. Clicking the ``Source Code'' link for
                    136: any such items will open a pop-up which displays the content of the library
                    137: file. It is good practice to enable access to the source code when publishing any 
                    138: library that will be shared. Otherwise, users cannot see it.
                    139: 
                    140: \null
                    141: \noindent \textbf{Viewing variables from a library script during testing}
                    142: 
                    143: When viewing a problem in the problem testing mode of Authoring Space, 
                    144: you will see a separate
                    145: Script Vars link at the bottom of the testing area for each script block 
                    146: (either a block included directly
                    147: within the file, or a block included within a library file imported into
                    148: a problem). By clicking the respective link, you can view variable values from
                    149: the respective script.\index{script variables, viewing}
                    150: 
                    151: \null
                    152: \noindent \textbf{Accessing submissions from a problem part loaded from a library}
                    153: 
                    154: When *response items (e.g., *response is a wildcard such as optionresponce, 
                    155: stringresponse, numericalresponse, etc.)\index{*response} are defined in a
                    156: .library file, this results in an extra id item in the identifier
                    157: required in \&EXT() \index{\&EXT}functions, e.g., if a problem contains two parts with
1.3       lira      158: ids of a and b respectively, and the id of the $<$import$>$ for the .library is 15, 
1.4       raeburn   159: and the *response items have ids of 11 and 12 respectively, the
1.1       lira      160: most recent submissions could be retrieved with the following \&EXT() calls.\index{\&EXT}
                    161: 
1.4       raeburn   162: \texttt{\&EXT(\char`\"{}user.resource.resource.a.15\_11.submission\char`\"{});}
1.1       lira      163: 
1.4       raeburn   164: \texttt{\&EXT(\char`\"{}user.resource.resource.b.15\_12.submission\char`\"{});}
1.1       lira      165: 

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