Annotation of loncom/html/adm/help/tex/Authoring_Library_Scripts.tex, revision 1.1
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
! 79: some arguments: \$eq,'x','y','z' in the call to the routine.
! 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:
! 117: Note: when using $<$randomlist$>$, always put the randomlist tag \textit{inside}
! 118: the $<$part$>$ tag. If multiple $<$part$>$ tags are inside a $<$randomlist$>$, then
! 119: the grading and course management will be more difficult.
! 120:
! 121: \null
! 122: \noindent \textbf{Viewing the text contents of a library script block}
! 123:
! 124: If you click on a .library file when browsing the shared content
! 125: repository, and the .library file contains just a script block, then
! 126: nothing will be displayed in the pop-up window.
! 127:
! 128: The code is viewable if the author has enabled access to the source
! 129: XML when publishing a .library item that is pure script block. If that
! 130: is done, then when a user checks the ``Source Available'' checkbox when
! 131: browsing the shared content pool, a link will be displayed for items
! 132: with available source code. Clicking the ``Source Code'' link for
! 133: any such items will open a pop-up which displays the content of the library
! 134: file. It is good practice to enable access to the source code when publishing any
! 135: library that will be shared. Otherwise, users cannot see it.
! 136:
! 137: \null
! 138: \noindent \textbf{Viewing variables from a library script during testing}
! 139:
! 140: When viewing a problem in the problem testing mode of Authoring Space,
! 141: you will see a separate
! 142: Script Vars link at the bottom of the testing area for each script block
! 143: (either a block included directly
! 144: within the file, or a block included within a library file imported into
! 145: a problem). By clicking the respective link, you can view variable values from
! 146: the respective script.\index{script variables, viewing}
! 147:
! 148: \null
! 149: \noindent \textbf{Accessing submissions from a problem part loaded from a library}
! 150:
! 151: When *response items (e.g., *response is a wildcard such as optionresponce,
! 152: stringresponse, numericalresponse, etc.)\index{*response} are defined in a
! 153: .library file, this results in an extra id item in the identifier
! 154: required in \&EXT() \index{\&EXT}functions, e.g., if a problem contains two parts with
! 155: ids of a and b respectively, and the *reponse items have ids of 11 and
! 156: 12 respectively, and the id of the $<$import$>$ for the .library is 15, the
! 157: most recent submissions could be retrieved with the following \&EXT() calls.\index{\&EXT}
! 158:
! 159: \&EXT('user.resource.resource.a.15\_11.submission');
! 160:
! 161: \&EXT('user.resource.resource.b.15\_12.submission');
! 162:
! 163:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>