summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/exsheets/exsheets-listings.sty
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2013-10-25 21:58:37 +0000
committerKarl Berry <karl@freefriends.org>2013-10-25 21:58:37 +0000
commit478b4d04587698beca915fbed7329dbb77f6fde1 (patch)
tree75afc01d98227e70137d39cea3127343c205ef8b /Master/texmf-dist/tex/latex/exsheets/exsheets-listings.sty
parentdff6d5d76d6ad664ee2dced8151b59ec3c0ac021 (diff)
exsheets (25oct13)
git-svn-id: svn://tug.org/texlive/trunk@31997 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/latex/exsheets/exsheets-listings.sty')
-rw-r--r--Master/texmf-dist/tex/latex/exsheets/exsheets-listings.sty146
1 files changed, 146 insertions, 0 deletions
diff --git a/Master/texmf-dist/tex/latex/exsheets/exsheets-listings.sty b/Master/texmf-dist/tex/latex/exsheets/exsheets-listings.sty
new file mode 100644
index 00000000000..6e27fa7c90c
--- /dev/null
+++ b/Master/texmf-dist/tex/latex/exsheets/exsheets-listings.sty
@@ -0,0 +1,146 @@
+% ----------------------------------------------------------------------------
+% the EXSHEETS-LISTINGS package
+%
+% Using listings with exsheets
+%
+% ----------------------------------------------------------------------------
+% Clemens Niederberger
+% Web: https://bitbucket.org/cgnieder/exsheets/
+% E-Mail: contact@mychemistry.eu
+% ----------------------------------------------------------------------------
+% Copyright 2011-2013 Clemens Niederberger
+%
+% This work may be distributed and/or modified under the
+% conditions of the LaTeX Project Public License, either version 1.3
+% of this license or (at your option) any later version.
+% The latest version of this license is in
+% http://www.latex-project.org/lppl.txt
+% and version 1.3 or later is part of all distributions of LaTeX
+% version 2005/12/01 or later.
+%
+% This work has the LPPL maintenance status `maintained'.
+%
+% The Current Maintainer of this work is Clemens Niederberger.
+% ----------------------------------------------------------------------------
+% If you have any ideas, questions, suggestions or bugs to report, please
+% feel free to contact me.
+% ----------------------------------------------------------------------------
+\RequirePackage{exsheets,listings}
+\def\exsheets@listings@date{2013/10/11}
+\def\exsheets@listings@version{0.2}
+% we need this loaded before expl3 syntax is activated:
+\lst@RequireAspects{writefile}
+\ProvidesExplPackage{exsheets-listings}
+ {\exsheets@listings@date}
+ {\exsheets@listings@version}
+ {listings in exsheets}
+
+% ----------------------------------------------------------------------------
+% variables:
+\int_new:N \g__exsheets_listings_question_int
+\int_new:N \g__exsheets_listings_solution_int
+
+\tl_new:N \l__exsheets_listings_question_pre_tl
+\tl_new:N \l__exsheets_listings_question_post_tl
+\tl_new:N \l__exsheets_listings_question_options_tl
+\tl_new:N \l__exsheets_listings_question_code_tl
+\tl_new:N \l__exsheets_listings_solution_pre_tl
+\tl_new:N \l__exsheets_listings_solution_post_tl
+\tl_new:N \l__exsheets_listings_solution_options_tl
+\tl_new:N \l__exsheets_listings_solution_code_tl
+\tl_new:N \l__exsheets_listings_question_points_tl
+
+% ----------------------------------------------------------------------------
+% listings style for questions and solutions:
+\keys_define:nn { exsheets }
+ {
+ question / listings .tl_set:N = \l__exsheets_listings_question_code_tl ,
+ solution / listings .tl_set:N = \l__exsheets_listings_solution_code_tl
+ }
+
+% ----------------------------------------------------------------------------
+% expansion help:
+\cs_new:Npn \__exsheets_question_expandopt:Nnnnn #1#2#3#4#5
+ { #1{#2}[#3]{#4}#5 }
+\cs_generate_variant:Nn \__exsheets_question_expandopt:Nnnnn { NnVox }
+
+\cs_new:Npn \__exsheets_question_expand_opt_and_body:Nnnn #1#2#3#4
+ { #1{#2}[#3]#4 }
+\cs_generate_variant:Nn \__exsheets_question_expand_opt_and_body:Nnnn { NnVx }
+
+% ----------------------------------------------------------------------------
+% lstquestion environment:
+\keys_define:nn { exsheets / listings / question }
+ {
+ pre .tl_set:N = \l__exsheets_listings_question_pre_tl ,
+ post .tl_set:N = \l__exsheets_listings_question_post_tl ,
+ options .tl_set:N = \l__exsheets_listings_question_options_tl ,
+ points .tl_set:N = \l__exsheets_listings_question_points_tl ,
+ listings .tl_set:N = \l__exsheets_listings_question_code_tl ,
+ }
+
+\keys_define:nn { exsheets / listings / solution }
+ {
+ pre .tl_set:N = \l__exsheets_listings_solution_pre_tl ,
+ post .tl_set:N = \l__exsheets_listings_solution_post_tl ,
+ options .tl_set:N = \l__exsheets_listings_solution_options_tl ,
+ listings .tl_set:N = \l__exsheets_listings_solution_code_tl ,
+ }
+
+\cs_new:Npn \exsheets_listings_new_lstenvironment:nnnnnnn #1#2#3#4#5#6#7
+ {
+ \lstnewenvironment{#2}[1][]
+ {
+ \keys_set:nn {exsheets/listings/question} {#1,#4,##1}
+ \int_gincr:N \g__exsheets_listings_question_int
+ \lst@BeginWriteFile
+ { \c_job_name_tl - ex \int_use:N\g__exsheets_listings_question_int .lst }
+ }
+ {
+ \lst@EndWriteFile
+ \__exsheets_question_expandopt:NnVox
+ \begin {#3}
+ \l__exsheets_listings_question_options_tl
+ { \l__exsheets_listings_question_points_tl }
+ {
+ \exp_not:V \l__exsheets_listings_question_pre_tl
+ \exp_not:N \lstinputlisting
+ [ \exp_not:V \l__exsheets_listings_question_code_tl ]
+ { \c_job_name_tl - ex \int_use:N\g__exsheets_listings_question_int .lst }
+ \exp_not:V \l__exsheets_listings_question_post_tl
+ }
+ \end {#3}
+ }
+ \lstnewenvironment{#5}[1][]
+ {
+ \keys_set:nn { exsheets / listings / solution } { #1,#7,##1 }
+ \int_gincr:N \g__exsheets_listings_solution_int
+ \lst@BeginWriteFile
+ { \c_job_name_tl - sol \int_use:N \g__exsheets_listings_solution_int . lst }
+ }
+ {
+ \lst@EndWriteFile
+ \__exsheets_question_expand_opt_and_body:NnVx
+ \begin {#6}
+ \l__exsheets_listings_solution_options_tl
+ {
+ \exp_not:V \l__exsheets_listings_solution_pre_tl
+ \exp_not:N \lstinputlisting
+ [ \exp_not:V \l__exsheets_listings_solution_code_tl ]
+ { \c_job_name_tl - sol \int_use:N \g__exsheets_listings_solution_int . lst }
+ \exp_not:V \l__exsheets_listings_solution_post_tl
+ }
+ \end {#6}
+ }
+ }
+
+\NewDocumentCommand \NewLstQuSolPair { O{}mmO{}mmO{} }
+ { \exsheets_listings_new_lstenvironment:nnnnnnn {#1}{#2}{#3}{#4}{#5}{#6}{#7} }
+
+\NewLstQuSolPair{lstquestion}{question}{lstsolution}{solution}
+
+\tex_endinput:D
+
+HISTORY
+2013/09/18 v0.1 - first draft, see http://tex.stackexchange.com/a/133969/5049
+2013/10/11 v0.2 - first official version bundled with ExSheets