src/Pure/Isar/isar_cmd.ML
author wenzelm
Sun Mar 01 23:36:12 2009 +0100 (2009-03-01)
changeset 30190 479806475f3c
parent 30173 eabece26b89b
child 30223 24d975352879
permissions -rw-r--r--
use long names for old-style fold combinators;
     1 (*  Title:      Pure/Isar/isar_cmd.ML
     2     Author:     Markus Wenzel, TU Muenchen
     3 
     4 Derived Isar commands.
     5 *)
     6 
     7 signature ISAR_CMD =
     8 sig
     9   val generic_setup: string * Position.T -> theory -> theory
    10   val parse_ast_translation: bool * (string * Position.T) -> theory -> theory
    11   val parse_translation: bool * (string * Position.T) -> theory -> theory
    12   val print_translation: bool * (string * Position.T) -> theory -> theory
    13   val typed_print_translation: bool * (string * Position.T) -> theory -> theory
    14   val print_ast_translation: bool * (string * Position.T) -> theory -> theory
    15   val oracle: bstring -> SymbolPos.text * Position.T -> theory -> theory
    16   val add_axioms: ((binding * string) * Attrib.src list) list -> theory -> theory
    17   val add_defs: (bool * bool) * ((binding * string) * Attrib.src list) list -> theory -> theory
    18   val declaration: string * Position.T -> local_theory -> local_theory
    19   val simproc_setup: string -> string list -> string * Position.T -> string list ->
    20     local_theory -> local_theory
    21   val hide_names: bool -> string * xstring list -> theory -> theory
    22   val have: (Attrib.binding * (string * string list) list) list -> bool -> Proof.state -> Proof.state
    23   val hence: (Attrib.binding * (string * string list) list) list -> bool -> Proof.state -> Proof.state
    24   val show: (Attrib.binding * (string * string list) list) list -> bool -> Proof.state -> Proof.state
    25   val thus: (Attrib.binding * (string * string list) list) list -> bool -> Proof.state -> Proof.state
    26   val qed: Method.text option -> Toplevel.transition -> Toplevel.transition
    27   val terminal_proof: Method.text * Method.text option ->
    28     Toplevel.transition -> Toplevel.transition
    29   val default_proof: Toplevel.transition -> Toplevel.transition
    30   val immediate_proof: Toplevel.transition -> Toplevel.transition
    31   val done_proof: Toplevel.transition -> Toplevel.transition
    32   val skip_proof: Toplevel.transition -> Toplevel.transition
    33   val init_theory: string * string list * (string * bool) list ->
    34     Toplevel.transition -> Toplevel.transition
    35   val exit: Toplevel.transition -> Toplevel.transition
    36   val quit: Toplevel.transition -> Toplevel.transition
    37   val pr: string list * (int option * int option) -> Toplevel.transition -> Toplevel.transition
    38   val disable_pr: Toplevel.transition -> Toplevel.transition
    39   val enable_pr: Toplevel.transition -> Toplevel.transition
    40   val ml_diag: bool -> string * Position.T -> Toplevel.transition -> Toplevel.transition
    41   val cd: Path.T -> Toplevel.transition -> Toplevel.transition
    42   val pwd: Toplevel.transition -> Toplevel.transition
    43   val display_drafts: Path.T list -> Toplevel.transition -> Toplevel.transition
    44   val print_drafts: Path.T list -> Toplevel.transition -> Toplevel.transition
    45   val pretty_setmargin: int -> Toplevel.transition -> Toplevel.transition
    46   val print_context: Toplevel.transition -> Toplevel.transition
    47   val print_theory: bool -> Toplevel.transition -> Toplevel.transition
    48   val print_syntax: Toplevel.transition -> Toplevel.transition
    49   val print_abbrevs: Toplevel.transition -> Toplevel.transition
    50   val print_facts: Toplevel.transition -> Toplevel.transition
    51   val print_configs: Toplevel.transition -> Toplevel.transition
    52   val print_theorems: Toplevel.transition -> Toplevel.transition
    53   val print_locales: Toplevel.transition -> Toplevel.transition
    54   val print_locale: bool * xstring -> Toplevel.transition -> Toplevel.transition
    55   val print_attributes: Toplevel.transition -> Toplevel.transition
    56   val print_simpset: Toplevel.transition -> Toplevel.transition
    57   val print_rules: Toplevel.transition -> Toplevel.transition
    58   val print_trans_rules: Toplevel.transition -> Toplevel.transition
    59   val print_methods: Toplevel.transition -> Toplevel.transition
    60   val print_antiquotations: Toplevel.transition -> Toplevel.transition
    61   val class_deps: Toplevel.transition -> Toplevel.transition
    62   val thy_deps: Toplevel.transition -> Toplevel.transition
    63   val thm_deps: (Facts.ref * Attrib.src list) list -> Toplevel.transition -> Toplevel.transition
    64   val unused_thms: (string list * string list option) option ->
    65     Toplevel.transition -> Toplevel.transition
    66   val print_binds: Toplevel.transition -> Toplevel.transition
    67   val print_cases: Toplevel.transition -> Toplevel.transition
    68   val print_stmts: string list * (Facts.ref * Attrib.src list) list
    69     -> Toplevel.transition -> Toplevel.transition
    70   val print_thms: string list * (Facts.ref * Attrib.src list) list
    71     -> Toplevel.transition -> Toplevel.transition
    72   val print_prfs: bool -> string list * (Facts.ref * Attrib.src list) list option
    73     -> Toplevel.transition -> Toplevel.transition
    74   val print_prop: (string list * string) -> Toplevel.transition -> Toplevel.transition
    75   val print_term: (string list * string) -> Toplevel.transition -> Toplevel.transition
    76   val print_type: (string list * string) -> Toplevel.transition -> Toplevel.transition
    77   val header_markup: SymbolPos.text * Position.T -> Toplevel.transition -> Toplevel.transition
    78   val local_theory_markup: xstring option * (SymbolPos.text * Position.T) ->
    79     Toplevel.transition -> Toplevel.transition
    80   val proof_markup: SymbolPos.text * Position.T -> Toplevel.transition -> Toplevel.transition
    81 end;
    82 
    83 structure IsarCmd: ISAR_CMD =
    84 struct
    85 
    86 
    87 (** theory declarations **)
    88 
    89 (* generic_setup *)
    90 
    91 fun generic_setup (txt, pos) =
    92   ML_Context.expression pos "val setup: theory -> theory" "Context.map_theory setup" txt
    93   |> Context.theory_map;
    94 
    95 
    96 (* translation functions *)
    97 
    98 local
    99 
   100 fun advancedT false = ""
   101   | advancedT true = "Proof.context -> ";
   102 
   103 fun advancedN false = ""
   104   | advancedN true = "advanced_";
   105 
   106 in
   107 
   108 fun parse_ast_translation (a, (txt, pos)) =
   109   txt |> ML_Context.expression pos
   110     ("val parse_ast_translation: (string * (" ^ advancedT a ^
   111       "Syntax.ast list -> Syntax.ast)) list")
   112     ("Context.map_theory (Sign.add_" ^ advancedN a ^ "trfuns (parse_ast_translation, [], [], []))")
   113   |> Context.theory_map;
   114 
   115 fun parse_translation (a, (txt, pos)) =
   116   txt |> ML_Context.expression pos
   117     ("val parse_translation: (string * (" ^ advancedT a ^
   118       "term list -> term)) list")
   119     ("Context.map_theory (Sign.add_" ^ advancedN a ^ "trfuns ([], parse_translation, [], []))")
   120   |> Context.theory_map;
   121 
   122 fun print_translation (a, (txt, pos)) =
   123   txt |> ML_Context.expression pos
   124     ("val print_translation: (string * (" ^ advancedT a ^
   125       "term list -> term)) list")
   126     ("Context.map_theory (Sign.add_" ^ advancedN a ^ "trfuns ([], [], print_translation, []))")
   127   |> Context.theory_map;
   128 
   129 fun print_ast_translation (a, (txt, pos)) =
   130   txt |> ML_Context.expression pos
   131     ("val print_ast_translation: (string * (" ^ advancedT a ^
   132       "Syntax.ast list -> Syntax.ast)) list")
   133     ("Context.map_theory (Sign.add_" ^ advancedN a ^ "trfuns ([], [], [], print_ast_translation))")
   134   |> Context.theory_map;
   135 
   136 fun typed_print_translation (a, (txt, pos)) =
   137   txt |> ML_Context.expression pos
   138     ("val typed_print_translation: (string * (" ^ advancedT a ^
   139       "bool -> typ -> term list -> term)) list")
   140     ("Context.map_theory (Sign.add_" ^ advancedN a ^ "trfunsT typed_print_translation)")
   141   |> Context.theory_map;
   142 
   143 end;
   144 
   145 
   146 (* oracles *)
   147 
   148 fun oracle name (oracle_txt, pos) =
   149   let
   150     val oracle = SymbolPos.content (SymbolPos.explode (oracle_txt, pos));
   151     val txt =
   152       "local\n\
   153       \  val name = " ^ quote name ^ ";\n\
   154       \  val oracle = " ^ oracle ^ ";\n\
   155       \in\n\
   156       \  val " ^ name ^ " = snd (Context.>>> (Context.map_theory_result (Thm.add_oracle (name, oracle))));\n\
   157       \end;\n";
   158   in Context.theory_map (ML_Context.exec (fn () => ML_Context.eval false pos txt)) end;
   159 
   160 
   161 (* axioms *)
   162 
   163 fun add_axms f args thy =
   164   f (map (fn ((b, ax), srcs) => ((Binding.base_name b, ax), map (Attrib.attribute thy) srcs)) args) thy;
   165 
   166 val add_axioms = add_axms (snd oo PureThy.add_axioms_cmd);
   167 
   168 fun add_defs ((unchecked, overloaded), args) =
   169   add_axms
   170     (snd oo (if unchecked then PureThy.add_defs_unchecked_cmd else PureThy.add_defs_cmd) overloaded) args;
   171 
   172 
   173 (* declarations *)
   174 
   175 fun declaration (txt, pos) =
   176   txt |> ML_Context.expression pos
   177     "val declaration: Morphism.declaration"
   178     "Context.map_proof (LocalTheory.declaration declaration)"
   179   |> Context.proof_map;
   180 
   181 
   182 (* simprocs *)
   183 
   184 fun simproc_setup name lhss (proc, pos) identifier =
   185   ML_Context.expression pos
   186     "val proc: Morphism.morphism -> Simplifier.simpset -> cterm -> thm option"
   187   ("Context.map_proof (Simplifier.def_simproc {name = " ^ ML_Syntax.print_string name ^ ", \
   188     \lhss = " ^ ML_Syntax.print_strings lhss ^ ", proc = proc, \
   189     \identifier = Library.maps ML_Context.thms " ^ ML_Syntax.print_strings identifier ^ "})") proc
   190   |> Context.proof_map;
   191 
   192 
   193 (* hide names *)
   194 
   195 val hide_kinds =
   196  [("class", (Sign.intern_class, can o Sign.certify_class, Sign.hide_class)),
   197   ("type", (Sign.intern_type, Sign.declared_tyname, Sign.hide_type)),
   198   ("const", (Sign.intern_const, Sign.declared_const, Sign.hide_const)),
   199   ("fact", (PureThy.intern_fact, PureThy.defined_fact, PureThy.hide_fact))];
   200 
   201 fun hide_names b (kind, xnames) thy =
   202   (case AList.lookup (op =) hide_kinds kind of
   203     SOME (intern, check, hide) =>
   204       let
   205         val names = map (intern thy) xnames;
   206         val bads = filter_out (check thy) names;
   207       in
   208         if null bads then fold (hide b) names thy
   209         else error ("Attempt to hide undeclared item(s): " ^ commas_quote bads)
   210       end
   211   | NONE => error ("Bad name space specification: " ^ quote kind));
   212 
   213 
   214 (* goals *)
   215 
   216 fun goal opt_chain goal stmt int =
   217   opt_chain #> goal NONE (K I) stmt int;
   218 
   219 val have = goal I Proof.have;
   220 val hence = goal Proof.chain Proof.have;
   221 val show = goal I Proof.show;
   222 val thus = goal Proof.chain Proof.show;
   223 
   224 
   225 (* local endings *)
   226 
   227 fun local_qed m = Toplevel.proof (Proof.local_qed (m, true));
   228 val local_terminal_proof = Toplevel.proof o Proof.local_terminal_proof;
   229 val local_default_proof = Toplevel.proof Proof.local_default_proof;
   230 val local_immediate_proof = Toplevel.proof Proof.local_immediate_proof;
   231 val local_done_proof = Toplevel.proof Proof.local_done_proof;
   232 val local_skip_proof = Toplevel.proof' Proof.local_skip_proof;
   233 
   234 val skip_local_qed = Toplevel.skip_proof (fn i => if i > 1 then i - 1 else raise Toplevel.UNDEF);
   235 
   236 
   237 (* global endings *)
   238 
   239 fun global_qed m = Toplevel.end_proof (K (Proof.global_qed (m, true)));
   240 val global_terminal_proof = Toplevel.end_proof o K o Proof.global_terminal_proof;
   241 val global_default_proof = Toplevel.end_proof (K Proof.global_default_proof);
   242 val global_immediate_proof = Toplevel.end_proof (K Proof.global_immediate_proof);
   243 val global_skip_proof = Toplevel.end_proof Proof.global_skip_proof;
   244 val global_done_proof = Toplevel.end_proof (K Proof.global_done_proof);
   245 
   246 val skip_global_qed = Toplevel.skip_proof_to_theory (fn n => n = 1);
   247 
   248 
   249 (* common endings *)
   250 
   251 fun qed m = local_qed m o global_qed m o skip_local_qed o skip_global_qed;
   252 fun terminal_proof m = local_terminal_proof m o global_terminal_proof m;
   253 val default_proof = local_default_proof o global_default_proof;
   254 val immediate_proof = local_immediate_proof o global_immediate_proof;
   255 val done_proof = local_done_proof o global_done_proof;
   256 val skip_proof = local_skip_proof o global_skip_proof;
   257 
   258 
   259 (* init and exit *)
   260 
   261 fun init_theory (name, imports, uses) =
   262   Toplevel.init_theory name (ThyInfo.begin_theory name imports (map (apfst Path.explode) uses))
   263     (fn thy =>
   264       if ThyInfo.check_known_thy (Context.theory_name thy)
   265       then ThyInfo.end_theory thy else ());
   266 
   267 val exit = Toplevel.keep (fn state =>
   268  (Context.set_thread_data (try Toplevel.generic_theory_of state);
   269   raise Toplevel.TERMINATE));
   270 
   271 val quit = Toplevel.imperative quit;
   272 
   273 
   274 (* print state *)
   275 
   276 fun set_limit _ NONE = ()
   277   | set_limit r (SOME n) = r := n;
   278 
   279 fun pr (modes, (lim1, lim2)) = Toplevel.keep (fn state =>
   280   (set_limit goals_limit lim1; set_limit ProofContext.prems_limit lim2; Toplevel.quiet := false;
   281     PrintMode.with_modes modes (Toplevel.print_state true) state));
   282 
   283 val disable_pr = Toplevel.imperative (fn () => Toplevel.quiet := true);
   284 val enable_pr = Toplevel.imperative (fn () => Toplevel.quiet := false);
   285 
   286 
   287 (* diagnostic ML evaluation *)
   288 
   289 fun ml_diag verbose (txt, pos) = Toplevel.keep (fn state =>
   290   (ML_Context.eval_in
   291     (Option.map Context.proof_of (try Toplevel.generic_theory_of state)) verbose pos txt));
   292 
   293 
   294 (* current working directory *)
   295 
   296 fun cd path = Toplevel.imperative (fn () => (File.cd path));
   297 val pwd = Toplevel.imperative (fn () => writeln (Path.implode (File.pwd ())));
   298 
   299 
   300 (* present draft files *)
   301 
   302 fun display_drafts files = Toplevel.imperative (fn () =>
   303   let val outfile = File.shell_path (Present.drafts (getenv "ISABELLE_DOC_FORMAT") files)
   304   in File.isabelle_tool ("display -c " ^ outfile ^ " &"); () end);
   305 
   306 fun print_drafts files = Toplevel.imperative (fn () =>
   307   let val outfile = File.shell_path (Present.drafts "ps" files)
   308   in File.isabelle_tool ("print -c " ^ outfile); () end);
   309 
   310 
   311 (* pretty_setmargin *)
   312 
   313 fun pretty_setmargin n = Toplevel.imperative (fn () => Pretty.setmargin n);
   314 
   315 
   316 (* print parts of theory and proof context *)
   317 
   318 val print_context = Toplevel.keep Toplevel.print_state_context;
   319 
   320 fun print_theory verbose = Toplevel.unknown_theory o
   321   Toplevel.keep (Pretty.writeln o ProofDisplay.pretty_full_theory verbose o Toplevel.theory_of);
   322 
   323 val print_syntax = Toplevel.unknown_context o
   324   Toplevel.keep (ProofContext.print_syntax o Toplevel.context_of);
   325 
   326 val print_abbrevs = Toplevel.unknown_context o
   327   Toplevel.keep (ProofContext.print_abbrevs o Toplevel.context_of);
   328 
   329 val print_facts = Toplevel.unknown_context o Toplevel.keep (fn state =>
   330   ProofContext.setmp_verbose
   331     ProofContext.print_lthms (Toplevel.context_of state));
   332 
   333 val print_configs = Toplevel.unknown_context o Toplevel.keep (fn state =>
   334   Attrib.print_configs (Toplevel.context_of state));
   335 
   336 val print_theorems_proof = Toplevel.keep (fn state =>
   337   ProofContext.setmp_verbose
   338     ProofContext.print_lthms (Proof.context_of (Toplevel.proof_of state)));
   339 
   340 val print_theorems_theory = Toplevel.keep (fn state =>
   341   Toplevel.theory_of state |>
   342   (case Toplevel.previous_node_of state of
   343     SOME prev_node =>
   344       ProofDisplay.print_theorems_diff (ProofContext.theory_of (Toplevel.context_node prev_node))
   345   | _ => ProofDisplay.print_theorems));
   346 
   347 val print_theorems = Toplevel.unknown_context o print_theorems_theory o print_theorems_proof;
   348 
   349 val print_locales = Toplevel.unknown_theory o
   350   Toplevel.keep (Locale.print_locales o Toplevel.theory_of);
   351 
   352 fun print_locale (show_facts, name) = Toplevel.unknown_theory o
   353   Toplevel.keep (fn state =>
   354     Locale.print_locale (Toplevel.theory_of state) show_facts name);
   355 
   356 val print_attributes = Toplevel.unknown_theory o
   357   Toplevel.keep (Attrib.print_attributes o Toplevel.theory_of);
   358 
   359 val print_simpset = Toplevel.unknown_context o
   360   Toplevel.keep (Pretty.writeln o Simplifier.pretty_ss o Simplifier.local_simpset_of o Toplevel.context_of);
   361 
   362 val print_rules = Toplevel.unknown_context o
   363   Toplevel.keep (ContextRules.print_rules o Toplevel.context_of);
   364 
   365 val print_trans_rules = Toplevel.unknown_context o
   366   Toplevel.keep (Calculation.print_rules o Toplevel.context_of);
   367 
   368 val print_methods = Toplevel.unknown_theory o
   369   Toplevel.keep (Method.print_methods o Toplevel.theory_of);
   370 
   371 val print_antiquotations = Toplevel.imperative ThyOutput.print_antiquotations;
   372 
   373 val thy_deps = Toplevel.unknown_theory o Toplevel.keep (fn state =>
   374   let
   375     val thy = Toplevel.theory_of state;
   376     val all_thys = sort ThyInfo.thy_ord (thy :: Theory.ancestors_of thy);
   377     val gr = all_thys |> map (fn node =>
   378       let
   379         val name = Context.theory_name node;
   380         val parents = map Context.theory_name (Theory.parents_of node);
   381         val dir = Present.session_name node;
   382         val unfold = not (ThyInfo.known_thy name andalso ThyInfo.is_finished name);
   383       in {name = name, ID = name, parents = parents, dir = dir, unfold = unfold, path = ""} end);
   384   in Present.display_graph gr end);
   385 
   386 val class_deps = Toplevel.unknown_theory o Toplevel.keep (fn state =>
   387   let
   388     val thy = Toplevel.theory_of state;
   389     val {classes = (space, algebra), ...} = Type.rep_tsig (Sign.tsig_of thy);
   390     val {classes, ...} = Sorts.rep_algebra algebra;
   391     fun entry (c, (i, (_, cs))) =
   392       (i, {name = NameSpace.extern space c, ID = c, parents = cs,
   393             dir = "", unfold = true, path = ""});
   394     val gr =
   395       Graph.fold (cons o entry) classes []
   396       |> sort (int_ord o pairself #1) |> map #2;
   397   in Present.display_graph gr end);
   398 
   399 fun thm_deps args = Toplevel.unknown_theory o Toplevel.keep (fn state =>
   400   ThmDeps.thm_deps (Proof.get_thmss (Toplevel.enter_proof_body state) args));
   401 
   402 
   403 (* find unused theorems *)
   404 
   405 fun unused_thms opt_range = Toplevel.keep (fn state =>
   406   let
   407     val thy = Toplevel.theory_of state;
   408     val ctxt = Toplevel.context_of state;
   409     fun pretty_thm (a, th) = ProofContext.pretty_fact ctxt (a, [th]);
   410   in
   411     ThmDeps.unused_thms
   412       (case opt_range of
   413         NONE => (Theory.parents_of thy, [thy])
   414       | SOME (xs, NONE) => (map ThyInfo.get_theory xs, [thy])
   415       | SOME (xs, SOME ys) => (map ThyInfo.get_theory xs, map ThyInfo.get_theory ys))
   416     |> map pretty_thm |> Pretty.chunks |> Pretty.writeln
   417   end);
   418 
   419 
   420 (* print proof context contents *)
   421 
   422 val print_binds = Toplevel.unknown_context o Toplevel.keep (fn state =>
   423   ProofContext.setmp_verbose ProofContext.print_binds (Toplevel.context_of state));
   424 
   425 val print_cases = Toplevel.unknown_context o Toplevel.keep (fn state =>
   426   ProofContext.setmp_verbose ProofContext.print_cases (Toplevel.context_of state));
   427 
   428 
   429 (* print theorems, terms, types etc. *)
   430 
   431 local
   432 
   433 fun string_of_stmts state args =
   434   Proof.get_thmss state args
   435   |> map (Element.pretty_statement (Proof.context_of state) Thm.theoremK)
   436   |> Pretty.chunks2 |> Pretty.string_of;
   437 
   438 fun string_of_thms state args =
   439   Pretty.string_of (ProofContext.pretty_thms (Proof.context_of state)
   440     (Proof.get_thmss state args));
   441 
   442 fun string_of_prfs full state arg =
   443   Pretty.string_of (case arg of
   444       NONE =>
   445         let
   446           val (ctxt, (_, thm)) = Proof.get_goal state;
   447           val thy = ProofContext.theory_of ctxt;
   448           val prf = Thm.proof_of thm;
   449           val prop = Thm.full_prop_of thm;
   450           val prf' = Proofterm.rewrite_proof_notypes ([], []) prf
   451         in
   452           ProofSyntax.pretty_proof ctxt
   453             (if full then Reconstruct.reconstruct_proof thy prop prf' else prf')
   454         end
   455     | SOME args => Pretty.chunks
   456         (map (ProofSyntax.pretty_proof_of (Proof.context_of state) full)
   457           (Proof.get_thmss state args)));
   458 
   459 fun string_of_prop state s =
   460   let
   461     val ctxt = Proof.context_of state;
   462     val prop = Syntax.read_prop ctxt s;
   463     val ctxt' = Variable.auto_fixes prop ctxt;
   464   in Pretty.string_of (Pretty.quote (Syntax.pretty_term ctxt' prop)) end;
   465 
   466 fun string_of_term state s =
   467   let
   468     val ctxt = Proof.context_of state;
   469     val t = Syntax.read_term ctxt s;
   470     val T = Term.type_of t;
   471     val ctxt' = Variable.auto_fixes t ctxt;
   472   in
   473     Pretty.string_of
   474       (Pretty.block [Pretty.quote (Syntax.pretty_term ctxt' t), Pretty.fbrk,
   475         Pretty.str "::", Pretty.brk 1, Pretty.quote (Syntax.pretty_typ ctxt' T)])
   476   end;
   477 
   478 fun string_of_type state s =
   479   let
   480     val ctxt = Proof.context_of state;
   481     val T = Syntax.read_typ ctxt s;
   482   in Pretty.string_of (Pretty.quote (Syntax.pretty_typ ctxt T)) end;
   483 
   484 fun print_item string_of (modes, arg) = Toplevel.keep (fn state =>
   485   PrintMode.with_modes modes (fn () =>
   486     writeln (string_of (Toplevel.enter_proof_body state) arg)) ());
   487 
   488 in
   489 
   490 val print_stmts = print_item string_of_stmts;
   491 val print_thms = print_item string_of_thms;
   492 val print_prfs = print_item o string_of_prfs;
   493 val print_prop = print_item string_of_prop;
   494 val print_term = print_item string_of_term;
   495 val print_type = print_item string_of_type;
   496 
   497 end;
   498 
   499 
   500 (* markup commands *)
   501 
   502 fun check_text (txt, pos) opt_node =
   503  (Position.report Markup.doc_source pos;
   504   ignore (ThyOutput.eval_antiquote (#1 (OuterKeyword.get_lexicons ())) opt_node (txt, pos)));
   505 
   506 fun header_markup txt = Toplevel.keep (fn state =>
   507   if Toplevel.is_toplevel state then check_text txt NONE
   508   else raise Toplevel.UNDEF);
   509 
   510 fun local_theory_markup (loc, txt) = Toplevel.present_local_theory loc (check_text txt o SOME);
   511 fun proof_markup txt = Toplevel.present_proof (check_text txt o SOME);
   512 
   513 end;