doc-src/antiquote_setup.ML
author wenzelm
Thu, 15 May 2008 20:02:40 +0200
changeset 26910 aa6357b39212
parent 26903 0542898ab667
child 27353 71c4dd53d4cb
permissions -rw-r--r--
tuned clean_name (underscore);
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
24584
01e83ffa6c54 fixed title
haftmann
parents: 24204
diff changeset
     1
(*  Title:      Doc/antiquote_setup.ML
21375
ae8a112b62d7 Auxiliary antiquotations for Isabelle manuals.
wenzelm
parents:
diff changeset
     2
    ID:         $Id$
ae8a112b62d7 Auxiliary antiquotations for Isabelle manuals.
wenzelm
parents:
diff changeset
     3
    Author:     Makarius
ae8a112b62d7 Auxiliary antiquotations for Isabelle manuals.
wenzelm
parents:
diff changeset
     4
26742
5a86bc79431c misc cleanup;
wenzelm
parents: 26710
diff changeset
     5
Auxiliary antiquotations for the Isabelle manuals.
21375
ae8a112b62d7 Auxiliary antiquotations for Isabelle manuals.
wenzelm
parents:
diff changeset
     6
*)
ae8a112b62d7 Auxiliary antiquotations for Isabelle manuals.
wenzelm
parents:
diff changeset
     7
26742
5a86bc79431c misc cleanup;
wenzelm
parents: 26710
diff changeset
     8
structure AntiquoteSetup: sig end =
5a86bc79431c misc cleanup;
wenzelm
parents: 26710
diff changeset
     9
struct
21375
ae8a112b62d7 Auxiliary antiquotations for Isabelle manuals.
wenzelm
parents:
diff changeset
    10
22094
008794185f4d renamed IsarOutput to ThyOutput;
wenzelm
parents: 22090
diff changeset
    11
structure O = ThyOutput;
21375
ae8a112b62d7 Auxiliary antiquotations for Isabelle manuals.
wenzelm
parents:
diff changeset
    12
26742
5a86bc79431c misc cleanup;
wenzelm
parents: 26710
diff changeset
    13
5a86bc79431c misc cleanup;
wenzelm
parents: 26710
diff changeset
    14
(* misc utils *)
5a86bc79431c misc cleanup;
wenzelm
parents: 26710
diff changeset
    15
26768
844068d16ba0 clean_string: handle { };
wenzelm
parents: 26756
diff changeset
    16
val clean_string = translate_string
26853
52cb0e965041 clean_string: map "_" to "\\_" (best used with underscore.sty);
wenzelm
parents: 26843
diff changeset
    17
  (fn "_" => "\\_"
26897
044619358d3a clean_string: cover <;
wenzelm
parents: 26894
diff changeset
    18
    | "<" => "$<$"
26768
844068d16ba0 clean_string: handle { };
wenzelm
parents: 26756
diff changeset
    19
    | ">" => "$>$"
844068d16ba0 clean_string: handle { };
wenzelm
parents: 26756
diff changeset
    20
    | "#" => "\\#"
844068d16ba0 clean_string: handle { };
wenzelm
parents: 26756
diff changeset
    21
    | "{" => "\\{"
844068d16ba0 clean_string: handle { };
wenzelm
parents: 26756
diff changeset
    22
    | "}" => "\\}"
844068d16ba0 clean_string: handle { };
wenzelm
parents: 26756
diff changeset
    23
    | c => c);
26751
2b97ea3130c2 added setup for Isar entities;
wenzelm
parents: 26742
diff changeset
    24
26897
044619358d3a clean_string: cover <;
wenzelm
parents: 26894
diff changeset
    25
fun clean_name "\\<dots>" = "dots"
044619358d3a clean_string: cover <;
wenzelm
parents: 26894
diff changeset
    26
  | clean_name ".." = "ddot"
044619358d3a clean_string: cover <;
wenzelm
parents: 26894
diff changeset
    27
  | clean_name "." = "dot"
26910
aa6357b39212 tuned clean_name (underscore);
wenzelm
parents: 26903
diff changeset
    28
  | clean_name "_" = "underscore"
26897
044619358d3a clean_string: cover <;
wenzelm
parents: 26894
diff changeset
    29
  | clean_name "{" = "braceleft"
044619358d3a clean_string: cover <;
wenzelm
parents: 26894
diff changeset
    30
  | clean_name "}" = "braceright"
26903
0542898ab667 clean_name: replace "_" by "-";
wenzelm
parents: 26897
diff changeset
    31
  | clean_name s = s |> translate_string (fn "_" => "-" | c => c);
26897
044619358d3a clean_string: cover <;
wenzelm
parents: 26894
diff changeset
    32
21375
ae8a112b62d7 Auxiliary antiquotations for Isabelle manuals.
wenzelm
parents:
diff changeset
    33
val str_of_source = space_implode " " o map Args.string_of o #2 o #1 o Args.dest_src;
ae8a112b62d7 Auxiliary antiquotations for Isabelle manuals.
wenzelm
parents:
diff changeset
    34
26742
5a86bc79431c misc cleanup;
wenzelm
parents: 26710
diff changeset
    35
fun tweak_line s =
5a86bc79431c misc cleanup;
wenzelm
parents: 26710
diff changeset
    36
  if ! O.display then s else Symbol.strip_blanks s;
5a86bc79431c misc cleanup;
wenzelm
parents: 26710
diff changeset
    37
5a86bc79431c misc cleanup;
wenzelm
parents: 26710
diff changeset
    38
val pretty_text = Pretty.chunks o map Pretty.str o map tweak_line o Library.split_lines;
5a86bc79431c misc cleanup;
wenzelm
parents: 26710
diff changeset
    39
5a86bc79431c misc cleanup;
wenzelm
parents: 26710
diff changeset
    40
fun pretty_term ctxt t = Syntax.pretty_term (Variable.auto_fixes t ctxt) t;
5a86bc79431c misc cleanup;
wenzelm
parents: 26710
diff changeset
    41
fun pretty_thm ctxt = pretty_term ctxt o Thm.full_prop_of;
5a86bc79431c misc cleanup;
wenzelm
parents: 26710
diff changeset
    42
5a86bc79431c misc cleanup;
wenzelm
parents: 26710
diff changeset
    43
5a86bc79431c misc cleanup;
wenzelm
parents: 26710
diff changeset
    44
(* verbatim text *)
5a86bc79431c misc cleanup;
wenzelm
parents: 26710
diff changeset
    45
5a86bc79431c misc cleanup;
wenzelm
parents: 26710
diff changeset
    46
val verbatim = space_implode "\\verb,|," o map (enclose "\\verb|" "|") o space_explode "|";
5a86bc79431c misc cleanup;
wenzelm
parents: 26710
diff changeset
    47
5a86bc79431c misc cleanup;
wenzelm
parents: 26710
diff changeset
    48
val _ = O.add_commands
5a86bc79431c misc cleanup;
wenzelm
parents: 26710
diff changeset
    49
 [("verbatim", O.args (Scan.lift Args.name) (fn _ => fn _ =>
5a86bc79431c misc cleanup;
wenzelm
parents: 26710
diff changeset
    50
      split_lines #> map verbatim #> space_implode "\\isasep\\isanewline%\n"))];
5a86bc79431c misc cleanup;
wenzelm
parents: 26710
diff changeset
    51
5a86bc79431c misc cleanup;
wenzelm
parents: 26710
diff changeset
    52
5a86bc79431c misc cleanup;
wenzelm
parents: 26710
diff changeset
    53
(* ML text *)
5a86bc79431c misc cleanup;
wenzelm
parents: 26710
diff changeset
    54
5a86bc79431c misc cleanup;
wenzelm
parents: 26710
diff changeset
    55
local
5a86bc79431c misc cleanup;
wenzelm
parents: 26710
diff changeset
    56
21375
ae8a112b62d7 Auxiliary antiquotations for Isabelle manuals.
wenzelm
parents:
diff changeset
    57
fun ml_val (txt1, "") = "fn _ => (" ^ txt1 ^ ");"
ae8a112b62d7 Auxiliary antiquotations for Isabelle manuals.
wenzelm
parents:
diff changeset
    58
  | ml_val (txt1, txt2) = "fn _ => (" ^ txt1 ^ ": " ^ txt2 ^ ");";
ae8a112b62d7 Auxiliary antiquotations for Isabelle manuals.
wenzelm
parents:
diff changeset
    59
ae8a112b62d7 Auxiliary antiquotations for Isabelle manuals.
wenzelm
parents:
diff changeset
    60
fun ml_type (txt1, "") = "val _ = NONE : (" ^ txt1 ^ ") option;"
ae8a112b62d7 Auxiliary antiquotations for Isabelle manuals.
wenzelm
parents:
diff changeset
    61
  | ml_type (txt1, txt2) = "val _ = [NONE : (" ^ txt1 ^ ") option, NONE : (" ^ txt2 ^ ") option];";
22289
41ce4f5c97c9 added antiquotation for exceptions
haftmann
parents: 22094
diff changeset
    62
23651
6e0b8b6012c9 renamed ML_exc to ML_exn;
wenzelm
parents: 22289
diff changeset
    63
fun ml_exn (txt1, "") = "fn _ => (" ^ txt1 ^ ": exn);"
6e0b8b6012c9 renamed ML_exc to ML_exn;
wenzelm
parents: 22289
diff changeset
    64
  | ml_exn (txt1, txt2) = "fn _ => (" ^ txt1 ^ ": " ^ txt2 ^ " -> exn);";
22289
41ce4f5c97c9 added antiquotation for exceptions
haftmann
parents: 22094
diff changeset
    65
21375
ae8a112b62d7 Auxiliary antiquotations for Isabelle manuals.
wenzelm
parents:
diff changeset
    66
fun ml_structure (txt, _) = "functor DUMMY_FUNCTOR() = struct structure DUMMY = " ^ txt ^ " end;"
ae8a112b62d7 Auxiliary antiquotations for Isabelle manuals.
wenzelm
parents:
diff changeset
    67
ae8a112b62d7 Auxiliary antiquotations for Isabelle manuals.
wenzelm
parents:
diff changeset
    68
fun ml_functor _ = "val _ = ();";  (*no check!*)
ae8a112b62d7 Auxiliary antiquotations for Isabelle manuals.
wenzelm
parents:
diff changeset
    69
ae8a112b62d7 Auxiliary antiquotations for Isabelle manuals.
wenzelm
parents:
diff changeset
    70
fun index_ml kind ml src ctxt (txt1, txt2) =
ae8a112b62d7 Auxiliary antiquotations for Isabelle manuals.
wenzelm
parents:
diff changeset
    71
  let
ae8a112b62d7 Auxiliary antiquotations for Isabelle manuals.
wenzelm
parents:
diff changeset
    72
    val txt = if txt2 = "" then txt1 else
26742
5a86bc79431c misc cleanup;
wenzelm
parents: 26710
diff changeset
    73
      if kind = "type" then txt1 ^ " = " ^ txt2
5a86bc79431c misc cleanup;
wenzelm
parents: 26710
diff changeset
    74
      else if kind = "exception" then txt1 ^ " of " ^ txt2
22289
41ce4f5c97c9 added antiquotation for exceptions
haftmann
parents: 22094
diff changeset
    75
      else txt1 ^ ": " ^ txt2;
21375
ae8a112b62d7 Auxiliary antiquotations for Isabelle manuals.
wenzelm
parents:
diff changeset
    76
    val txt' = if kind = "" then txt else kind ^ " " ^ txt;
22289
41ce4f5c97c9 added antiquotation for exceptions
haftmann
parents: 22094
diff changeset
    77
    val _ = writeln (ml (txt1, txt2));
26455
1757a6e049f4 reorganized signature of ML_Context;
wenzelm
parents: 26385
diff changeset
    78
    val _ = ML_Context.eval_in (SOME (Context.Proof ctxt)) false Position.none (ml (txt1, txt2));
21375
ae8a112b62d7 Auxiliary antiquotations for Isabelle manuals.
wenzelm
parents:
diff changeset
    79
  in
26751
2b97ea3130c2 added setup for Isar entities;
wenzelm
parents: 26742
diff changeset
    80
    "\\indexml" ^ kind ^ enclose "{" "}" (clean_string txt1) ^
21375
ae8a112b62d7 Auxiliary antiquotations for Isabelle manuals.
wenzelm
parents:
diff changeset
    81
    ((if ! O.source then str_of_source src else txt')
ae8a112b62d7 Auxiliary antiquotations for Isabelle manuals.
wenzelm
parents:
diff changeset
    82
    |> (if ! O.quotes then quote else I)
ae8a112b62d7 Auxiliary antiquotations for Isabelle manuals.
wenzelm
parents:
diff changeset
    83
    |> (if ! O.display then enclose "\\begin{verbatim}\n" "\n\\end{verbatim}"
26751
2b97ea3130c2 added setup for Isar entities;
wenzelm
parents: 26742
diff changeset
    84
        else split_lines #> map verbatim #> space_implode "\\isasep\\isanewline%\n"))
21375
ae8a112b62d7 Auxiliary antiquotations for Isabelle manuals.
wenzelm
parents:
diff changeset
    85
  end;
ae8a112b62d7 Auxiliary antiquotations for Isabelle manuals.
wenzelm
parents:
diff changeset
    86
26461
da989545e59c some styling
haftmann
parents: 26455
diff changeset
    87
fun output_ml ctxt src =
da989545e59c some styling
haftmann
parents: 26455
diff changeset
    88
  if ! O.display then enclose "\\begin{verbatim}\n" "\n\\end{verbatim}"
26742
5a86bc79431c misc cleanup;
wenzelm
parents: 26710
diff changeset
    89
  else
26461
da989545e59c some styling
haftmann
parents: 26455
diff changeset
    90
    split_lines
da989545e59c some styling
haftmann
parents: 26455
diff changeset
    91
    #> map (space_implode "\\verb,|," o map (enclose "\\verb|" "|") o space_explode "|")
da989545e59c some styling
haftmann
parents: 26455
diff changeset
    92
    #> space_implode "\\isasep\\isanewline%\n";
da989545e59c some styling
haftmann
parents: 26455
diff changeset
    93
26742
5a86bc79431c misc cleanup;
wenzelm
parents: 26710
diff changeset
    94
fun ml_args x = O.args (Scan.lift (Args.name -- Scan.optional (Args.colon |-- Args.name) "")) x;
5a86bc79431c misc cleanup;
wenzelm
parents: 26710
diff changeset
    95
5a86bc79431c misc cleanup;
wenzelm
parents: 26710
diff changeset
    96
in
21375
ae8a112b62d7 Auxiliary antiquotations for Isabelle manuals.
wenzelm
parents:
diff changeset
    97
26742
5a86bc79431c misc cleanup;
wenzelm
parents: 26710
diff changeset
    98
val _ = O.add_commands
5a86bc79431c misc cleanup;
wenzelm
parents: 26710
diff changeset
    99
 [("index_ML", ml_args (index_ml "" ml_val)),
5a86bc79431c misc cleanup;
wenzelm
parents: 26710
diff changeset
   100
  ("index_ML_type", ml_args (index_ml "type" ml_type)),
5a86bc79431c misc cleanup;
wenzelm
parents: 26710
diff changeset
   101
  ("index_ML_exn", ml_args (index_ml "exception" ml_exn)),
5a86bc79431c misc cleanup;
wenzelm
parents: 26710
diff changeset
   102
  ("index_ML_structure", ml_args (index_ml "structure" ml_structure)),
5a86bc79431c misc cleanup;
wenzelm
parents: 26710
diff changeset
   103
  ("index_ML_functor", ml_args (index_ml "functor" ml_functor)),
5a86bc79431c misc cleanup;
wenzelm
parents: 26710
diff changeset
   104
  ("ML_functor", O.args (Scan.lift Args.name) output_ml),
5a86bc79431c misc cleanup;
wenzelm
parents: 26710
diff changeset
   105
  ("ML_text", O.args (Scan.lift Args.name) output_ml)];
21375
ae8a112b62d7 Auxiliary antiquotations for Isabelle manuals.
wenzelm
parents:
diff changeset
   106
26742
5a86bc79431c misc cleanup;
wenzelm
parents: 26710
diff changeset
   107
end;
21375
ae8a112b62d7 Auxiliary antiquotations for Isabelle manuals.
wenzelm
parents:
diff changeset
   108
23846
bfedd1a024fc Added named_thms antiquotation.
berghofe
parents: 23651
diff changeset
   109
bfedd1a024fc Added named_thms antiquotation.
berghofe
parents: 23651
diff changeset
   110
(* theorems with names *)
bfedd1a024fc Added named_thms antiquotation.
berghofe
parents: 23651
diff changeset
   111
26742
5a86bc79431c misc cleanup;
wenzelm
parents: 26710
diff changeset
   112
local
23846
bfedd1a024fc Added named_thms antiquotation.
berghofe
parents: 23651
diff changeset
   113
26742
5a86bc79431c misc cleanup;
wenzelm
parents: 26710
diff changeset
   114
fun output_named_thms src ctxt xs =
5a86bc79431c misc cleanup;
wenzelm
parents: 26710
diff changeset
   115
  map (apfst (pretty_thm ctxt)) xs        (*always pretty in order to exhibit errors!*)
23846
bfedd1a024fc Added named_thms antiquotation.
berghofe
parents: 23651
diff changeset
   116
  |> (if ! O.quotes then map (apfst Pretty.quote) else I)
bfedd1a024fc Added named_thms antiquotation.
berghofe
parents: 23651
diff changeset
   117
  |> (if ! O.display then
bfedd1a024fc Added named_thms antiquotation.
berghofe
parents: 23651
diff changeset
   118
    map (fn (p, name) =>
bfedd1a024fc Added named_thms antiquotation.
berghofe
parents: 23651
diff changeset
   119
      Output.output (Pretty.string_of (Pretty.indent (! O.indent) p)) ^
bfedd1a024fc Added named_thms antiquotation.
berghofe
parents: 23651
diff changeset
   120
      "\\rulename{" ^ Output.output (Pretty.str_of (pretty_text name)) ^ "}")
bfedd1a024fc Added named_thms antiquotation.
berghofe
parents: 23651
diff changeset
   121
    #> space_implode "\\par\\smallskip%\n"
bfedd1a024fc Added named_thms antiquotation.
berghofe
parents: 23651
diff changeset
   122
    #> enclose "\\begin{isabelle}%\n" "%\n\\end{isabelle}"
bfedd1a024fc Added named_thms antiquotation.
berghofe
parents: 23651
diff changeset
   123
  else
bfedd1a024fc Added named_thms antiquotation.
berghofe
parents: 23651
diff changeset
   124
    map (fn (p, name) =>
bfedd1a024fc Added named_thms antiquotation.
berghofe
parents: 23651
diff changeset
   125
      Output.output (Pretty.str_of p) ^
bfedd1a024fc Added named_thms antiquotation.
berghofe
parents: 23651
diff changeset
   126
      "\\rulename{" ^ Output.output (Pretty.str_of (pretty_text name)) ^ "}")
bfedd1a024fc Added named_thms antiquotation.
berghofe
parents: 23651
diff changeset
   127
    #> space_implode "\\par\\smallskip%\n"
bfedd1a024fc Added named_thms antiquotation.
berghofe
parents: 23651
diff changeset
   128
    #> enclose "\\isa{" "}");
bfedd1a024fc Added named_thms antiquotation.
berghofe
parents: 23651
diff changeset
   129
21375
ae8a112b62d7 Auxiliary antiquotations for Isabelle manuals.
wenzelm
parents:
diff changeset
   130
in
ae8a112b62d7 Auxiliary antiquotations for Isabelle manuals.
wenzelm
parents:
diff changeset
   131
ae8a112b62d7 Auxiliary antiquotations for Isabelle manuals.
wenzelm
parents:
diff changeset
   132
val _ = O.add_commands
26742
5a86bc79431c misc cleanup;
wenzelm
parents: 26710
diff changeset
   133
 [("named_thms", O.args (Scan.repeat (Attrib.thm --
26751
2b97ea3130c2 added setup for Isar entities;
wenzelm
parents: 26742
diff changeset
   134
      Scan.lift (Args.parens Args.name))) output_named_thms)];
21375
ae8a112b62d7 Auxiliary antiquotations for Isabelle manuals.
wenzelm
parents:
diff changeset
   135
ae8a112b62d7 Auxiliary antiquotations for Isabelle manuals.
wenzelm
parents:
diff changeset
   136
end;
26742
5a86bc79431c misc cleanup;
wenzelm
parents: 26710
diff changeset
   137
5a86bc79431c misc cleanup;
wenzelm
parents: 26710
diff changeset
   138
5a86bc79431c misc cleanup;
wenzelm
parents: 26710
diff changeset
   139
(* theory files *)
5a86bc79431c misc cleanup;
wenzelm
parents: 26710
diff changeset
   140
5a86bc79431c misc cleanup;
wenzelm
parents: 26710
diff changeset
   141
val _ = O.add_commands
5a86bc79431c misc cleanup;
wenzelm
parents: 26710
diff changeset
   142
 [("thy_file", O.args (Scan.lift Args.name) (O.output (fn _ => fn name =>
5a86bc79431c misc cleanup;
wenzelm
parents: 26710
diff changeset
   143
      (ThyLoad.check_thy Path.current name; Pretty.str name))))];
5a86bc79431c misc cleanup;
wenzelm
parents: 26710
diff changeset
   144
26751
2b97ea3130c2 added setup for Isar entities;
wenzelm
parents: 26742
diff changeset
   145
2b97ea3130c2 added setup for Isar entities;
wenzelm
parents: 26742
diff changeset
   146
(* Isar entities (with index) *)
2b97ea3130c2 added setup for Isar entities;
wenzelm
parents: 26742
diff changeset
   147
2b97ea3130c2 added setup for Isar entities;
wenzelm
parents: 26742
diff changeset
   148
local
2b97ea3130c2 added setup for Isar entities;
wenzelm
parents: 26742
diff changeset
   149
26894
1120f6cc10b0 proper checking of various Isar elements;
wenzelm
parents: 26853
diff changeset
   150
fun no_check _ _ = true;
1120f6cc10b0 proper checking of various Isar elements;
wenzelm
parents: 26853
diff changeset
   151
1120f6cc10b0 proper checking of various Isar elements;
wenzelm
parents: 26853
diff changeset
   152
fun thy_check intern defined ctxt =
1120f6cc10b0 proper checking of various Isar elements;
wenzelm
parents: 26853
diff changeset
   153
  let val thy = ProofContext.theory_of ctxt
1120f6cc10b0 proper checking of various Isar elements;
wenzelm
parents: 26853
diff changeset
   154
  in defined thy o intern thy end;
1120f6cc10b0 proper checking of various Isar elements;
wenzelm
parents: 26853
diff changeset
   155
26751
2b97ea3130c2 added setup for Isar entities;
wenzelm
parents: 26742
diff changeset
   156
val arg = enclose "{" "}" o clean_string;
2b97ea3130c2 added setup for Isar entities;
wenzelm
parents: 26742
diff changeset
   157
26894
1120f6cc10b0 proper checking of various Isar elements;
wenzelm
parents: 26853
diff changeset
   158
fun output_entity check markup index kind ctxt (logic, name) =
26897
044619358d3a clean_string: cover <;
wenzelm
parents: 26894
diff changeset
   159
  let
044619358d3a clean_string: cover <;
wenzelm
parents: 26894
diff changeset
   160
    val hyper_name = "{" ^ NameSpace.append kind (NameSpace.append logic (clean_name name)) ^ "}";
044619358d3a clean_string: cover <;
wenzelm
parents: 26894
diff changeset
   161
    val hyper =
044619358d3a clean_string: cover <;
wenzelm
parents: 26894
diff changeset
   162
      enclose ("\\hyperlink" ^ hyper_name ^ "{") "}" #>
044619358d3a clean_string: cover <;
wenzelm
parents: 26894
diff changeset
   163
      index = SOME true ? enclose ("\\hypertarget" ^ hyper_name ^ "{") "}";
044619358d3a clean_string: cover <;
wenzelm
parents: 26894
diff changeset
   164
    val idx =
044619358d3a clean_string: cover <;
wenzelm
parents: 26894
diff changeset
   165
      (case index of
044619358d3a clean_string: cover <;
wenzelm
parents: 26894
diff changeset
   166
        NONE => ""
044619358d3a clean_string: cover <;
wenzelm
parents: 26894
diff changeset
   167
      | SOME is_def =>
044619358d3a clean_string: cover <;
wenzelm
parents: 26894
diff changeset
   168
          "\\index" ^ (if is_def then "def" else "ref") ^ arg logic ^ arg kind ^ arg name);
044619358d3a clean_string: cover <;
wenzelm
parents: 26894
diff changeset
   169
  in
044619358d3a clean_string: cover <;
wenzelm
parents: 26894
diff changeset
   170
    if check ctxt name then
044619358d3a clean_string: cover <;
wenzelm
parents: 26894
diff changeset
   171
      idx ^
044619358d3a clean_string: cover <;
wenzelm
parents: 26894
diff changeset
   172
      (Output.output name
044619358d3a clean_string: cover <;
wenzelm
parents: 26894
diff changeset
   173
        |> (if markup = "" then I else enclose ("\\" ^ markup ^ "{") "}")
044619358d3a clean_string: cover <;
wenzelm
parents: 26894
diff changeset
   174
        |> (if ! O.quotes then quote else I)
044619358d3a clean_string: cover <;
wenzelm
parents: 26894
diff changeset
   175
        |> (if ! O.display then enclose "\\begin{isabelle}%\n" "%\n\\end{isabelle}"
044619358d3a clean_string: cover <;
wenzelm
parents: 26894
diff changeset
   176
            else hyper o enclose "\\mbox{\\isa{" "}}"))
044619358d3a clean_string: cover <;
wenzelm
parents: 26894
diff changeset
   177
    else error ("Undefined " ^ kind ^ " " ^ quote name)
044619358d3a clean_string: cover <;
wenzelm
parents: 26894
diff changeset
   178
  end;
26751
2b97ea3130c2 added setup for Isar entities;
wenzelm
parents: 26742
diff changeset
   179
26894
1120f6cc10b0 proper checking of various Isar elements;
wenzelm
parents: 26853
diff changeset
   180
fun entity check markup index kind =
26751
2b97ea3130c2 added setup for Isar entities;
wenzelm
parents: 26742
diff changeset
   181
  O.args (Scan.lift (Scan.optional (Args.parens Args.name) "" -- Args.name))
26894
1120f6cc10b0 proper checking of various Isar elements;
wenzelm
parents: 26853
diff changeset
   182
    (K (output_entity check markup index kind));
26897
044619358d3a clean_string: cover <;
wenzelm
parents: 26894
diff changeset
   183
26894
1120f6cc10b0 proper checking of various Isar elements;
wenzelm
parents: 26853
diff changeset
   184
fun entity_antiqs check markup kind =
1120f6cc10b0 proper checking of various Isar elements;
wenzelm
parents: 26853
diff changeset
   185
 [(kind, entity check markup NONE kind),
26897
044619358d3a clean_string: cover <;
wenzelm
parents: 26894
diff changeset
   186
  (kind ^ "_def", entity check markup (SOME true) kind),
26894
1120f6cc10b0 proper checking of various Isar elements;
wenzelm
parents: 26853
diff changeset
   187
  (kind ^ "_ref", entity check markup (SOME false) kind)];
26751
2b97ea3130c2 added setup for Isar entities;
wenzelm
parents: 26742
diff changeset
   188
2b97ea3130c2 added setup for Isar entities;
wenzelm
parents: 26742
diff changeset
   189
in
2b97ea3130c2 added setup for Isar entities;
wenzelm
parents: 26742
diff changeset
   190
2b97ea3130c2 added setup for Isar entities;
wenzelm
parents: 26742
diff changeset
   191
val _ = O.add_commands
26894
1120f6cc10b0 proper checking of various Isar elements;
wenzelm
parents: 26853
diff changeset
   192
 (entity_antiqs no_check "" "syntax" @
1120f6cc10b0 proper checking of various Isar elements;
wenzelm
parents: 26853
diff changeset
   193
  entity_antiqs (K (is_some o OuterSyntax.command_keyword)) "isacommand" "command" @
1120f6cc10b0 proper checking of various Isar elements;
wenzelm
parents: 26853
diff changeset
   194
  entity_antiqs (K OuterSyntax.is_keyword) "isakeyword" "keyword" @
1120f6cc10b0 proper checking of various Isar elements;
wenzelm
parents: 26853
diff changeset
   195
  entity_antiqs (K OuterSyntax.is_keyword) "isakeyword" "element" @
1120f6cc10b0 proper checking of various Isar elements;
wenzelm
parents: 26853
diff changeset
   196
  entity_antiqs (thy_check Method.intern Method.defined) "" "method" @
1120f6cc10b0 proper checking of various Isar elements;
wenzelm
parents: 26853
diff changeset
   197
  entity_antiqs (thy_check Attrib.intern Attrib.defined) "" "attribute" @
1120f6cc10b0 proper checking of various Isar elements;
wenzelm
parents: 26853
diff changeset
   198
  entity_antiqs no_check "" "fact" @
1120f6cc10b0 proper checking of various Isar elements;
wenzelm
parents: 26853
diff changeset
   199
  entity_antiqs no_check "" "variable" @
1120f6cc10b0 proper checking of various Isar elements;
wenzelm
parents: 26853
diff changeset
   200
  entity_antiqs no_check "" "case" @
1120f6cc10b0 proper checking of various Isar elements;
wenzelm
parents: 26853
diff changeset
   201
  entity_antiqs (K ThyOutput.defined_command) "" "antiquotation");
26751
2b97ea3130c2 added setup for Isar entities;
wenzelm
parents: 26742
diff changeset
   202
26742
5a86bc79431c misc cleanup;
wenzelm
parents: 26710
diff changeset
   203
end;
26751
2b97ea3130c2 added setup for Isar entities;
wenzelm
parents: 26742
diff changeset
   204
2b97ea3130c2 added setup for Isar entities;
wenzelm
parents: 26742
diff changeset
   205
end;