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