Difference between revisions of "Macro file template"
Jump to navigation
Jump to search
(2 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
<pre> |
<pre> |
||
− | # Put this in your course macros directory, define any custom subroutines you want and then use them in |
||
+ | # macros_template.pl |
||
+ | # Rename this file (with .pl extension) and place it in your course macros directory, |
||
+ | |||
+ | # define any custom subroutines you want and then use them in |
||
# problems by including the file in loadMacros() calls. |
# problems by including the file in loadMacros() calls. |
||
Line 49: | Line 52: | ||
</pre> |
</pre> |
||
+ | |||
+ | |||
+ | |||
+ | [[Category:Sample Problems]] |
||
+ | [[Category:Manpages]] |
Latest revision as of 20:07, 25 October 2016
# macros_template.pl # Rename this file (with .pl extension) and place it in your course macros directory, # define any custom subroutines you want and then use them in # problems by including the file in loadMacros() calls. # This particular file simply defines a new macros $BRED and $ERED which bracket a section of the # problem which should be printed in red. sub _init_macro_template { #Possibly add initialization code here #sub routine is not required, but prevents the macro from being re-loaded } #Now defined your custom subroutines for use in problem authoring. #At this level authors are restricted to using a 'safe' subset of perl. E.g. no system calls, printing, #importing libraries, etc. #Example subroutines for implementing colored text in problems: sub BRED { MODES(TeX => '{\\color{red} ', HTML => '<span style="color:red">'); }; sub ERED { MODES( TeX => '}', HTML => '</span>'); }; # Now you can wrap text between these subroutines and it will come out red both in latex/pdf and in html. # However, inside a BEGIN_TEXT/END_TEXT block the parser must be told that BRED() and ERED() are intended # to be perl functions and not literal text. As with the ANS_RULE() subroutine, you can do it like so: # \{ BRED() \} I want this text to be red. \{ ERED() \}. But to make display macros easier to use, the # following syntactic sugar is used: $main::BRED = BRED(); $main::ERED = ERED(); #The result of this is that you can now do it like so: # $BRED I want this text to be red $ERED 1; #required at end of file - a perl thing