| author | wenzelm |
| Mon, 15 May 2023 20:55:17 +0200 | |
| changeset 78060 | b6c886b7184f |
| parent 73780 | 466fae6bf22e |
| child 80846 | 9ed32b8a03a9 |
| permissions | -rw-r--r-- |
| 48985 | 1 |
(* Title: Doc/antiquote_setup.ML |
| 21375 | 2 |
Author: Makarius |
3 |
||
| 26742 | 4 |
Auxiliary antiquotations for the Isabelle manuals. |
| 21375 | 5 |
*) |
6 |
||
|
56059
2390391584c2
some document antiquotations for Isabelle/jEdit elements;
wenzelm
parents:
55997
diff
changeset
|
7 |
structure Antiquote_Setup: sig end = |
| 26742 | 8 |
struct |
| 21375 | 9 |
|
| 26742 | 10 |
(* misc utils *) |
11 |
||
|
29736
ec3fc818b82e
clean_string/clean_name: proper treatment of \<dash>;
wenzelm
parents:
29726
diff
changeset
|
12 |
fun translate f = Symbol.explode #> map f #> implode; |
|
ec3fc818b82e
clean_string/clean_name: proper treatment of \<dash>;
wenzelm
parents:
29726
diff
changeset
|
13 |
|
|
ec3fc818b82e
clean_string/clean_name: proper treatment of \<dash>;
wenzelm
parents:
29726
diff
changeset
|
14 |
val clean_string = translate |
|
26853
52cb0e965041
clean_string: map "_" to "\\_" (best used with underscore.sty);
wenzelm
parents:
26843
diff
changeset
|
15 |
(fn "_" => "\\_" |
|
30120
aaa4667285c8
uniform treatment of ML indexing, using general \indexdef macro for formal Isabelle/Isar entities;
wenzelm
parents:
29736
diff
changeset
|
16 |
| "#" => "\\#" |
| 52408 | 17 |
| "$" => "\\$" |
18 |
| "%" => "\\%" |
|
| 26897 | 19 |
| "<" => "$<$" |
| 26768 | 20 |
| ">" => "$>$" |
21 |
| "{" => "\\{"
|
|
|
30120
aaa4667285c8
uniform treatment of ML indexing, using general \indexdef macro for formal Isabelle/Isar entities;
wenzelm
parents:
29736
diff
changeset
|
22 |
| "|" => "$\\mid$" |
| 26768 | 23 |
| "}" => "\\}" |
| 42666 | 24 |
| "\<hyphen>" => "-" |
| 26768 | 25 |
| c => c); |
| 26751 | 26 |
|
| 31546 | 27 |
fun clean_name "\<dots>" = "dots" |
| 26897 | 28 |
| clean_name ".." = "ddot" |
29 |
| clean_name "." = "dot" |
|
| 26910 | 30 |
| clean_name "_" = "underscore" |
| 26897 | 31 |
| clean_name "{" = "braceleft"
|
32 |
| clean_name "}" = "braceright" |
|
| 42666 | 33 |
| clean_name s = s |> translate (fn "_" => "-" | "\<hyphen>" => "-" | c => c); |
| 26897 | 34 |
|
| 26742 | 35 |
|
| 30394 | 36 |
(* named theorems *) |
| 23846 | 37 |
|
|
56059
2390391584c2
some document antiquotations for Isabelle/jEdit elements;
wenzelm
parents:
55997
diff
changeset
|
38 |
val _ = |
| 73761 | 39 |
Theory.setup (Document_Output.antiquotation_raw \<^binding>\<open>named_thms\<close> |
|
43564
9864182c6bad
document antiquotations are managed as theory data, with proper name space and entity markup;
wenzelm
parents:
43563
diff
changeset
|
40 |
(Scan.repeat (Attrib.thm -- Scan.lift (Args.parens Args.name))) |
| 67463 | 41 |
(fn ctxt => |
42 |
map (fn (thm, name) => |
|
43 |
Output.output |
|
44 |
(Document_Antiquotation.format ctxt |
|
| 73761 | 45 |
(Document_Antiquotation.delimit ctxt (Document_Output.pretty_thm ctxt thm))) ^ |
| 67468 | 46 |
enclose "\\rulename{" "}" (Output.output name))
|
| 67463 | 47 |
#> space_implode "\\par\\smallskip%\n" |
|
73780
466fae6bf22e
compose Latex text as XML, output exported YXML in Isabelle/Scala;
wenzelm
parents:
73765
diff
changeset
|
48 |
#> Latex.string |
| 73761 | 49 |
#> Document_Output.isabelle ctxt)); |
| 26742 | 50 |
|
51 |
||
| 30394 | 52 |
(* Isabelle/Isar entities (with index) *) |
| 26751 | 53 |
|
54 |
local |
|
55 |
||
| 61620 | 56 |
fun no_check (_: Proof.context) (name, _: Position.T) = name; |
| 26894 | 57 |
|
| 61620 | 58 |
fun check_keyword ctxt (name, pos) = |
59 |
if Keyword.is_keyword (Thy_Header.get_keywords' ctxt) name then name |
|
60 |
else error ("Bad outer syntax keyword " ^ quote name ^ Position.here pos);
|
|
| 53061 | 61 |
|
| 71913 | 62 |
fun check_system_option ctxt arg = |
63 |
(Completion.check_option (Options.default ()) ctxt arg; true) |
|
| 56467 | 64 |
handle ERROR _ => false; |
65 |
||
| 26751 | 66 |
val arg = enclose "{" "}" o clean_string;
|
67 |
||
| 56185 | 68 |
fun entity check markup binding index = |
| 73761 | 69 |
Document_Output.antiquotation_raw |
| 56185 | 70 |
(binding |> Binding.map_name (fn name => name ^ |
|
43564
9864182c6bad
document antiquotations are managed as theory data, with proper name space and entity markup;
wenzelm
parents:
43563
diff
changeset
|
71 |
(case index of NONE => "" | SOME true => "_def" | SOME false => "_ref"))) |
|
69349
7cef9e386ffe
more accurate positions for "name" (quoted string) and "embedded" (cartouche): refer to content without delimiters, which is e.g. relevant for systematic selection/renaming of scope groups;
wenzelm
parents:
68823
diff
changeset
|
72 |
(Scan.lift (Scan.optional (Args.parens Args.name) "" -- Args.name_position)) |
| 67463 | 73 |
(fn ctxt => fn (logic, (name, pos)) => |
| 30394 | 74 |
let |
| 56185 | 75 |
val kind = translate (fn "_" => " " | c => c) (Binding.name_of binding); |
| 30394 | 76 |
val hyper_name = |
77 |
"{" ^ Long_Name.append kind (Long_Name.append logic (clean_name name)) ^ "}";
|
|
78 |
val hyper = |
|
79 |
enclose ("\\hyperlink" ^ hyper_name ^ "{") "}" #>
|
|
80 |
index = SOME true ? enclose ("\\hypertarget" ^ hyper_name ^ "{") "}";
|
|
81 |
val idx = |
|
82 |
(case index of |
|
83 |
NONE => "" |
|
84 |
| SOME is_def => |
|
85 |
"\\index" ^ (if is_def then "def" else "ref") ^ arg logic ^ arg kind ^ arg name); |
|
|
66682
c4cbe609f6a8
avoid duplicate message for @{action} in particular (see also @{action} within Pure);
wenzelm
parents:
62829
diff
changeset
|
86 |
val _ = |
|
c4cbe609f6a8
avoid duplicate message for @{action} in particular (see also @{action} within Pure);
wenzelm
parents:
62829
diff
changeset
|
87 |
if Context_Position.is_reported ctxt pos then ignore (check ctxt (name, pos)) else (); |
| 67463 | 88 |
val latex = |
89 |
idx ^ |
|
90 |
(Output.output name |
|
91 |
|> (if markup = "" then I else enclose ("\\" ^ markup ^ "{") "}")
|
|
92 |
|> hyper o enclose "\\mbox{\\isa{" "}}");
|
|
93 |
in Latex.string latex end); |
|
| 26897 | 94 |
|
| 26894 | 95 |
fun entity_antiqs check markup kind = |
|
43564
9864182c6bad
document antiquotations are managed as theory data, with proper name space and entity markup;
wenzelm
parents:
43563
diff
changeset
|
96 |
entity check markup kind NONE #> |
|
9864182c6bad
document antiquotations are managed as theory data, with proper name space and entity markup;
wenzelm
parents:
43563
diff
changeset
|
97 |
entity check markup kind (SOME true) #> |
|
9864182c6bad
document antiquotations are managed as theory data, with proper name space and entity markup;
wenzelm
parents:
43563
diff
changeset
|
98 |
entity check markup kind (SOME false); |
| 26751 | 99 |
|
100 |
in |
|
101 |
||
|
56059
2390391584c2
some document antiquotations for Isabelle/jEdit elements;
wenzelm
parents:
55997
diff
changeset
|
102 |
val _ = |
|
2390391584c2
some document antiquotations for Isabelle/jEdit elements;
wenzelm
parents:
55997
diff
changeset
|
103 |
Theory.setup |
| 69593 | 104 |
(entity_antiqs no_check "" \<^binding>\<open>syntax\<close> #> |
105 |
entity_antiqs Outer_Syntax.check_command "isacommand" \<^binding>\<open>command\<close> #> |
|
106 |
entity_antiqs check_keyword "isakeyword" \<^binding>\<open>keyword\<close> #> |
|
107 |
entity_antiqs check_keyword "isakeyword" \<^binding>\<open>element\<close> #> |
|
108 |
entity_antiqs Method.check_name "" \<^binding>\<open>method\<close> #> |
|
109 |
entity_antiqs Attrib.check_name "" \<^binding>\<open>attribute\<close> #> |
|
110 |
entity_antiqs no_check "" \<^binding>\<open>fact\<close> #> |
|
111 |
entity_antiqs no_check "" \<^binding>\<open>variable\<close> #> |
|
112 |
entity_antiqs no_check "" \<^binding>\<open>case\<close> #> |
|
113 |
entity_antiqs Document_Antiquotation.check "" \<^binding>\<open>antiquotation\<close> #> |
|
114 |
entity_antiqs Document_Antiquotation.check_option "" \<^binding>\<open>antiquotation_option\<close> #> |
|
|
69962
82e945d472d5
documentation of document markers and re-interpreted command tags;
wenzelm
parents:
69593
diff
changeset
|
115 |
entity_antiqs Document_Marker.check "" \<^binding>\<open>document_marker\<close> #> |
| 69593 | 116 |
entity_antiqs no_check "isasystem" \<^binding>\<open>setting\<close> #> |
117 |
entity_antiqs check_system_option "isasystem" \<^binding>\<open>system_option\<close> #> |
|
118 |
entity_antiqs no_check "" \<^binding>\<open>inference\<close> #> |
|
119 |
entity_antiqs no_check "isasystem" \<^binding>\<open>executable\<close> #> |
|
| 72763 | 120 |
entity_antiqs Isabelle_Tool.check "isatool" \<^binding>\<open>tool\<close> #> |
| 69593 | 121 |
entity_antiqs ML_Context.check_antiquotation "" \<^binding>\<open>ML_antiquotation\<close> #> |
122 |
entity_antiqs (K JEdit.check_action) "isasystem" \<^binding>\<open>action\<close>); |
|
| 26751 | 123 |
|
| 26742 | 124 |
end; |
| 26751 | 125 |
|
| 73734 | 126 |
|
127 |
(* show symbols *) |
|
128 |
||
129 |
val _ = |
|
| 73761 | 130 |
Theory.setup (Document_Output.antiquotation_raw \<^binding>\<open>show_symbols\<close> (Scan.succeed ()) |
| 73734 | 131 |
(fn _ => fn _ => |
132 |
let |
|
133 |
val symbol_name = |
|
134 |
unprefix "\\newcommand{\\isasym"
|
|
135 |
#> raw_explode |
|
136 |
#> take_prefix Symbol.is_ascii_letter |
|
137 |
#> implode; |
|
138 |
||
139 |
val symbols = |
|
140 |
File.read \<^file>\<open>~~/lib/texinputs/isabellesym.sty\<close> |
|
141 |
|> split_lines |
|
142 |
|> map_filter (fn line => |
|
143 |
(case try symbol_name line of |
|
144 |
NONE => NONE |
|
145 |
| SOME "" => NONE |
|
146 |
| SOME name => SOME ("\\verb,\\" ^ "<" ^ name ^ ">, & {\\isasym" ^ name ^ "}")));
|
|
147 |
||
148 |
val eol = "\\\\\n"; |
|
149 |
fun table (a :: b :: rest) = a ^ " & " ^ b ^ eol :: table rest |
|
150 |
| table [a] = [a ^ eol] |
|
151 |
| table [] = []; |
|
152 |
in |
|
153 |
Latex.string |
|
154 |
("\\begin{supertabular}{ll@{\\qquad}ll}\n" ^ implode (table symbols) ^
|
|
155 |
"\\end{supertabular}\n")
|
|
156 |
end)) |
|
157 |
||
| 26751 | 158 |
end; |