February 15th, 2014 |
We'd like to extract the following content to different files, one with the question another with the answer:
be measurable with
and
for some
. Show
that
for all .
if
, and
if
. Therefore, for all
we
have
no matter what
is. This leads to the rough estimate
. We
may improve this with…
First we define a helper routine to create the contents of the new buffers:
(define (new-document from doc)
"Returns a document with the same style as the given
one"
(with l (select (buffer-get from) '(:* style 0))
(with tup (if (nnull? l) (tree->stree (car l)) '(tuple
"generic"))
‘(document
(TeXmacs ,(texmacs-version))
(style ,tup)
(body ,doc)))))
Scheme]
Now, the routine which will actually extract the contents. Notice how
we use the selector
(define (pick-env env from to)
"Selects all subtrees of type @env in @from and sets
@to's contents"
(with l (select (buffer-get from) ‘(:* ,env))
(with doc (if (nnull? l)
(append '(document) l)
'(document "No subtrees found of the
type given"))
(buffer-set to (new-document from doc)))))
Scheme]
Here are two examples of how we may use the preceding stuff. A more general solution, maybe with a nice dialog box would be better.
(define (pick-questions from)
"Creates a new buffer with all questions from a given
one"
(with u (new-buffer)
(pick-env 'question from u)
(switch-to-buffer u)))
Scheme]
(define (pick-answers from)
"Creates a new buffer with all cuestions"
(with u (new-buffer)
(pick-env 'answer from u)
(switch-to-buffer u)))
Scheme]
(pick-questions (current-buffer))
Scheme]
(pick-answers (current-buffer))
Scheme]
And finally here's an example inserting those two commands in a new
menu
(menu-bind extract-menu
("Questions" (choose-file pick-questions
"Choose questions file"
"texmacs"))
("Answers" (choose-file pick-answers
"Choose answers file"
"texmacs")))
Scheme]
(menu-bind tools-menu
(-> "Extract" (link extract-menu))
(former))
Scheme]