Theory Snippets.Snipping
section Snipping
theory Snipping
imports Main
keywords
"snipbegin" :: document_heading and
"snipend" :: document_heading
begin
text ‹Snippets allow specific components of the LaTeX document preparation to be included in other documents.›
ML ‹
fun wrapped_command (command: string) (name: string option) =
let
val command = "\\" ^ command
val argument = case name of
NONE => "" |
SOME v => ("{" ^ v ^ "}")
val latex = (command ^ argument)
val _ = @{print} latex;
in
Document_Output.document_output
{markdown = false,
markup = fn _ => XML.enclose "%\n" "\n" (Latex.string latex)}
end
val _ =
Outer_Syntax.command ("snipbegin", ⌂) "start a snippet"
(Parse.opt_target -- Parse.document_source >>
(fn (opt, n) =>
wrapped_command "isamarkupsnipbegin" (SOME (Input.string_of n)) (opt, n)));
val _ =
Outer_Syntax.command ("snipend", ⌂) "finish a snippet"
(Parse.opt_target -- Parse.document_source >>
(fn (opt, n) =>
wrapped_command "isamarkupsnipend" (NONE) (opt, n)));
›
text ‹
Snippets should be enclosed within the @{command snipbegin} and @{command snipend} commands.
For example, the box below is produced by the following:
›
text ‹
@{command snipbegin} ``snip-example''
@{command text} ``Hello world!''
@{command snipend}
›
snipbegin ‹snip-example›
text ‹Hello world!›
snipend -
end