author | wenzelm |
Sun, 24 Mar 2019 17:33:11 +0100 | |
changeset 69966 | cba5b866c633 |
parent 69892 | f752f3993db8 |
child 70122 | a0b21b4b7a4a |
permissions | -rw-r--r-- |
22124 | 1 |
(* Title: Pure/Thy/thy_output.ML |
67386 | 2 |
Author: Makarius |
22124 | 3 |
|
67386 | 4 |
Theory document output. |
22124 | 5 |
*) |
6 |
||
7 |
signature THY_OUTPUT = |
|
8 |
sig |
|
67569
5d71b114e7a3
avoid proliferation of language_document reports;
wenzelm
parents:
67567
diff
changeset
|
9 |
val output_document: Proof.context -> {markdown: bool} -> Input.source -> Latex.text list |
67381 | 10 |
val check_comments: Proof.context -> Symbol_Pos.T list -> unit |
11 |
val output_token: Proof.context -> Token.T -> Latex.text list |
|
67474
90def2b06305
more uniform output of source / text / theory_text, with handling of formal comments etc.;
wenzelm
parents:
67465
diff
changeset
|
12 |
val output_source: Proof.context -> string -> Latex.text list |
68182 | 13 |
type segment = {span: Command_Span.span, command: Toplevel.transition, state: Toplevel.state} |
68506 | 14 |
val present_thy: Options.T -> theory -> segment list -> Latex.text list |
28644 | 15 |
val pretty_term: Proof.context -> term -> Pretty.T |
16 |
val pretty_thm: Proof.context -> thm -> Pretty.T |
|
67508 | 17 |
val lines: Latex.text list -> Latex.text list |
67505
ceb324e34c14
clarified signature: items with \isasep are special;
wenzelm
parents:
67475
diff
changeset
|
18 |
val items: Latex.text list -> Latex.text list |
67463 | 19 |
val isabelle: Proof.context -> Latex.text list -> Latex.text |
20 |
val isabelle_typewriter: Proof.context -> Latex.text list -> Latex.text |
|
21 |
val typewriter: Proof.context -> string -> Latex.text |
|
22 |
val verbatim: Proof.context -> string -> Latex.text |
|
67474
90def2b06305
more uniform output of source / text / theory_text, with handling of formal comments etc.;
wenzelm
parents:
67465
diff
changeset
|
23 |
val source: Proof.context -> Token.src -> Latex.text |
67505
ceb324e34c14
clarified signature: items with \isasep are special;
wenzelm
parents:
67475
diff
changeset
|
24 |
val pretty: Proof.context -> Pretty.T -> Latex.text |
ceb324e34c14
clarified signature: items with \isasep are special;
wenzelm
parents:
67475
diff
changeset
|
25 |
val pretty_source: Proof.context -> Token.src -> Pretty.T -> Latex.text |
ceb324e34c14
clarified signature: items with \isasep are special;
wenzelm
parents:
67475
diff
changeset
|
26 |
val pretty_items: Proof.context -> Pretty.T list -> Latex.text |
ceb324e34c14
clarified signature: items with \isasep are special;
wenzelm
parents:
67475
diff
changeset
|
27 |
val pretty_items_source: Proof.context -> Token.src -> Pretty.T list -> Latex.text |
67463 | 28 |
val antiquotation_pretty: |
67505
ceb324e34c14
clarified signature: items with \isasep are special;
wenzelm
parents:
67475
diff
changeset
|
29 |
binding -> 'a context_parser -> (Proof.context -> 'a -> Pretty.T) -> theory -> theory |
69592
a80d8ec6c998
support for isabelle update -u control_cartouches;
wenzelm
parents:
68512
diff
changeset
|
30 |
val antiquotation_pretty_embedded: |
a80d8ec6c998
support for isabelle update -u control_cartouches;
wenzelm
parents:
68512
diff
changeset
|
31 |
binding -> 'a context_parser -> (Proof.context -> 'a -> Pretty.T) -> theory -> theory |
67463 | 32 |
val antiquotation_pretty_source: |
67505
ceb324e34c14
clarified signature: items with \isasep are special;
wenzelm
parents:
67475
diff
changeset
|
33 |
binding -> 'a context_parser -> (Proof.context -> 'a -> Pretty.T) -> theory -> theory |
69592
a80d8ec6c998
support for isabelle update -u control_cartouches;
wenzelm
parents:
68512
diff
changeset
|
34 |
val antiquotation_pretty_source_embedded: |
a80d8ec6c998
support for isabelle update -u control_cartouches;
wenzelm
parents:
68512
diff
changeset
|
35 |
binding -> 'a context_parser -> (Proof.context -> 'a -> Pretty.T) -> theory -> theory |
67463 | 36 |
val antiquotation_raw: |
37 |
binding -> 'a context_parser -> (Proof.context -> 'a -> Latex.text) -> theory -> theory |
|
69592
a80d8ec6c998
support for isabelle update -u control_cartouches;
wenzelm
parents:
68512
diff
changeset
|
38 |
val antiquotation_raw_embedded: |
a80d8ec6c998
support for isabelle update -u control_cartouches;
wenzelm
parents:
68512
diff
changeset
|
39 |
binding -> 'a context_parser -> (Proof.context -> 'a -> Latex.text) -> theory -> theory |
67463 | 40 |
val antiquotation_verbatim: |
41 |
binding -> 'a context_parser -> (Proof.context -> 'a -> string) -> theory -> theory |
|
69592
a80d8ec6c998
support for isabelle update -u control_cartouches;
wenzelm
parents:
68512
diff
changeset
|
42 |
val antiquotation_verbatim_embedded: |
a80d8ec6c998
support for isabelle update -u control_cartouches;
wenzelm
parents:
68512
diff
changeset
|
43 |
binding -> 'a context_parser -> (Proof.context -> 'a -> string) -> theory -> theory |
22124 | 44 |
end; |
45 |
||
37216
3165bc303f66
modernized some structure names, keeping a few legacy aliases;
wenzelm
parents:
37198
diff
changeset
|
46 |
structure Thy_Output: THY_OUTPUT = |
22124 | 47 |
struct |
48 |
||
67569
5d71b114e7a3
avoid proliferation of language_document reports;
wenzelm
parents:
67567
diff
changeset
|
49 |
(* output document source *) |
56548 | 50 |
|
67571
f858fe5531ac
more uniform treatment of formal comments within document source;
wenzelm
parents:
67570
diff
changeset
|
51 |
val output_symbols = single o Latex.symbols_output; |
f858fe5531ac
more uniform treatment of formal comments within document source;
wenzelm
parents:
67570
diff
changeset
|
52 |
|
f858fe5531ac
more uniform treatment of formal comments within document source;
wenzelm
parents:
67570
diff
changeset
|
53 |
fun output_comment ctxt (kind, syms) = |
f858fe5531ac
more uniform treatment of formal comments within document source;
wenzelm
parents:
67570
diff
changeset
|
54 |
(case kind of |
f858fe5531ac
more uniform treatment of formal comments within document source;
wenzelm
parents:
67570
diff
changeset
|
55 |
Comment.Comment => |
f858fe5531ac
more uniform treatment of formal comments within document source;
wenzelm
parents:
67570
diff
changeset
|
56 |
Input.cartouche_content syms |
f858fe5531ac
more uniform treatment of formal comments within document source;
wenzelm
parents:
67570
diff
changeset
|
57 |
|> output_document (ctxt |> Config.put Document_Antiquotation.thy_output_display false) |
f858fe5531ac
more uniform treatment of formal comments within document source;
wenzelm
parents:
67570
diff
changeset
|
58 |
{markdown = false} |
f858fe5531ac
more uniform treatment of formal comments within document source;
wenzelm
parents:
67570
diff
changeset
|
59 |
|> Latex.enclose_body "%\n\\isamarkupcmt{" "%\n}" |
f858fe5531ac
more uniform treatment of formal comments within document source;
wenzelm
parents:
67570
diff
changeset
|
60 |
| Comment.Cancel => |
f858fe5531ac
more uniform treatment of formal comments within document source;
wenzelm
parents:
67570
diff
changeset
|
61 |
Symbol_Pos.cartouche_content syms |
f858fe5531ac
more uniform treatment of formal comments within document source;
wenzelm
parents:
67570
diff
changeset
|
62 |
|> output_symbols |
f858fe5531ac
more uniform treatment of formal comments within document source;
wenzelm
parents:
67570
diff
changeset
|
63 |
|> Latex.enclose_body "%\n\\isamarkupcancel{" "}" |
69891
def3ec9cdb7e
document markers are formal comments, and may thus occur anywhere in the command-span;
wenzelm
parents:
69887
diff
changeset
|
64 |
| Comment.Latex => [Latex.symbols (Symbol_Pos.cartouche_content syms)] |
def3ec9cdb7e
document markers are formal comments, and may thus occur anywhere in the command-span;
wenzelm
parents:
69887
diff
changeset
|
65 |
| Comment.Marker => []) |
67571
f858fe5531ac
more uniform treatment of formal comments within document source;
wenzelm
parents:
67570
diff
changeset
|
66 |
and output_comment_document ctxt (comment, syms) = |
f858fe5531ac
more uniform treatment of formal comments within document source;
wenzelm
parents:
67570
diff
changeset
|
67 |
(case comment of |
f858fe5531ac
more uniform treatment of formal comments within document source;
wenzelm
parents:
67570
diff
changeset
|
68 |
SOME kind => output_comment ctxt (kind, syms) |
f858fe5531ac
more uniform treatment of formal comments within document source;
wenzelm
parents:
67570
diff
changeset
|
69 |
| NONE => [Latex.symbols syms]) |
f858fe5531ac
more uniform treatment of formal comments within document source;
wenzelm
parents:
67570
diff
changeset
|
70 |
and output_document_text ctxt syms = |
67572 | 71 |
Comment.read_body syms |> maps (output_comment_document ctxt) |
67571
f858fe5531ac
more uniform treatment of formal comments within document source;
wenzelm
parents:
67570
diff
changeset
|
72 |
and output_document ctxt {markdown} source = |
61457 | 73 |
let |
74 |
val pos = Input.pos_of source; |
|
75 |
val syms = Input.source_explode source; |
|
76 |
||
67571
f858fe5531ac
more uniform treatment of formal comments within document source;
wenzelm
parents:
67570
diff
changeset
|
77 |
val output_antiquotes = |
f858fe5531ac
more uniform treatment of formal comments within document source;
wenzelm
parents:
67570
diff
changeset
|
78 |
maps (Document_Antiquotation.evaluate (output_document_text ctxt) ctxt); |
61036
f6f2959bed67
clarified language context, e.g. relevant for symbols;
wenzelm
parents:
60100
diff
changeset
|
79 |
|
61461 | 80 |
fun output_line line = |
67194
1c0a6a957114
positions as postlude: avoid intrusion of odd %-forms into main tex source;
wenzelm
parents:
67191
diff
changeset
|
81 |
(if Markdown.line_is_item line then [Latex.string "\\item "] else []) @ |
61461 | 82 |
output_antiquotes (Markdown.line_content line); |
83 |
||
67194
1c0a6a957114
positions as postlude: avoid intrusion of odd %-forms into main tex source;
wenzelm
parents:
67191
diff
changeset
|
84 |
fun output_block (Markdown.Par lines) = |
1c0a6a957114
positions as postlude: avoid intrusion of odd %-forms into main tex source;
wenzelm
parents:
67191
diff
changeset
|
85 |
Latex.block (separate (Latex.string "\n") (map (Latex.block o output_line) lines)) |
61459
5f2ddeb15c06
clarified nesting of paragraphs: indentation is taken into account more uniformly;
wenzelm
parents:
61458
diff
changeset
|
86 |
| output_block (Markdown.List {kind, body, ...}) = |
67194
1c0a6a957114
positions as postlude: avoid intrusion of odd %-forms into main tex source;
wenzelm
parents:
67191
diff
changeset
|
87 |
Latex.environment_block (Markdown.print_kind kind) (output_blocks body) |
1c0a6a957114
positions as postlude: avoid intrusion of odd %-forms into main tex source;
wenzelm
parents:
67191
diff
changeset
|
88 |
and output_blocks blocks = separate (Latex.string "\n\n") (map output_block blocks); |
67184 | 89 |
in |
67381 | 90 |
if Toplevel.is_skipped_proof (Toplevel.presentation_state ctxt) then [] |
67184 | 91 |
else if markdown andalso exists (Markdown.is_control o Symbol_Pos.symbol) syms |
92 |
then |
|
93 |
let |
|
67571
f858fe5531ac
more uniform treatment of formal comments within document source;
wenzelm
parents:
67570
diff
changeset
|
94 |
val ants = Antiquote.parse_comments pos syms; |
67184 | 95 |
val reports = Antiquote.antiq_reports ants; |
96 |
val blocks = Markdown.read_antiquotes ants; |
|
67381 | 97 |
val _ = Context_Position.reports ctxt (reports @ Markdown.reports blocks); |
67186
a58bbe66ac81
avoid excessive whitespace between antiquotations and text;
wenzelm
parents:
67184
diff
changeset
|
98 |
in output_blocks blocks end |
67184 | 99 |
else |
100 |
let |
|
67571
f858fe5531ac
more uniform treatment of formal comments within document source;
wenzelm
parents:
67570
diff
changeset
|
101 |
val ants = Antiquote.parse_comments pos (trim (Symbol.is_blank o Symbol_Pos.symbol) syms); |
67184 | 102 |
val reports = Antiquote.antiq_reports ants; |
67381 | 103 |
val _ = Context_Position.reports ctxt (reports @ Markdown.text_reports ants); |
67186
a58bbe66ac81
avoid excessive whitespace between antiquotations and text;
wenzelm
parents:
67184
diff
changeset
|
104 |
in output_antiquotes ants end |
67184 | 105 |
end; |
48918
6e5fd4585512
check side-comments of command spans (normally filtered out in Outer_Syntax.toplevel_source);
wenzelm
parents:
47005
diff
changeset
|
106 |
|
6e5fd4585512
check side-comments of command spans (normally filtered out in Outer_Syntax.toplevel_source);
wenzelm
parents:
47005
diff
changeset
|
107 |
|
67425
7d4a088dbc0e
clarified modules: uniform notion of formal comments;
wenzelm
parents:
67421
diff
changeset
|
108 |
(* output tokens with formal comments *) |
22124 | 109 |
|
67353 | 110 |
local |
111 |
||
67358 | 112 |
val output_symbols_antiq = |
113 |
(fn Antiquote.Text syms => output_symbols syms |
|
67353 | 114 |
| Antiquote.Control {name = (name, _), body, ...} => |
67374
5a049cf98438
clarified output (see also 909dcdec2122, 34d1913f0b20);
wenzelm
parents:
67372
diff
changeset
|
115 |
Latex.string (Latex.output_symbols [Symbol.encode (Symbol.Control name)]) :: |
67358 | 116 |
output_symbols body |
67353 | 117 |
| Antiquote.Antiq {body, ...} => |
67358 | 118 |
Latex.enclose_body "%\n\\isaantiq\n" "{}%\n\\endisaantiq\n" (output_symbols body)); |
67353 | 119 |
|
67571
f858fe5531ac
more uniform treatment of formal comments within document source;
wenzelm
parents:
67570
diff
changeset
|
120 |
fun output_comment_symbols ctxt {antiq} (comment, syms) = |
67425
7d4a088dbc0e
clarified modules: uniform notion of formal comments;
wenzelm
parents:
67421
diff
changeset
|
121 |
(case (comment, antiq) of |
7d4a088dbc0e
clarified modules: uniform notion of formal comments;
wenzelm
parents:
67421
diff
changeset
|
122 |
(NONE, false) => output_symbols syms |
7d4a088dbc0e
clarified modules: uniform notion of formal comments;
wenzelm
parents:
67421
diff
changeset
|
123 |
| (NONE, true) => |
67571
f858fe5531ac
more uniform treatment of formal comments within document source;
wenzelm
parents:
67570
diff
changeset
|
124 |
Antiquote.parse_comments (#1 (Symbol_Pos.range syms)) syms |
67413 | 125 |
|> maps output_symbols_antiq |
67571
f858fe5531ac
more uniform treatment of formal comments within document source;
wenzelm
parents:
67570
diff
changeset
|
126 |
| (SOME comment, _) => output_comment ctxt (comment, syms)); |
67372 | 127 |
|
67381 | 128 |
fun output_body ctxt antiq bg en syms = |
67572 | 129 |
Comment.read_body syms |
130 |
|> maps (output_comment_symbols ctxt {antiq = antiq}) |
|
68194 | 131 |
|> Latex.enclose_body bg en; |
132 |
||
133 |
in |
|
134 |
||
135 |
fun output_token ctxt tok = |
|
67353 | 136 |
let |
67378 | 137 |
fun output antiq bg en = |
67381 | 138 |
output_body ctxt antiq bg en (Input.source_explode (Token.input_of tok)); |
67378 | 139 |
in |
140 |
(case Token.kind_of tok of |
|
67439
78759a7bd874
more uniform support for formal comments in outer syntax, notably \<^cancel> and \<^latex>;
wenzelm
parents:
67429
diff
changeset
|
141 |
Token.Comment NONE => [] |
69891
def3ec9cdb7e
document markers are formal comments, and may thus occur anywhere in the command-span;
wenzelm
parents:
69887
diff
changeset
|
142 |
| Token.Comment (SOME Comment.Marker) => [] |
67378 | 143 |
| Token.Command => output false "\\isacommand{" "}" |
144 |
| Token.Keyword => |
|
145 |
if Symbol.is_ascii_identifier (Token.content_of tok) |
|
146 |
then output false "\\isakeyword{" "}" |
|
147 |
else output false "" "" |
|
148 |
| Token.String => output false "{\\isachardoublequoteopen}" "{\\isachardoublequoteclose}" |
|
149 |
| Token.Alt_String => output false "{\\isacharbackquoteopen}" "{\\isacharbackquoteclose}" |
|
150 |
| Token.Verbatim => output true "{\\isacharverbatimopen}" "{\\isacharverbatimclose}" |
|
151 |
| Token.Cartouche => output false "{\\isacartoucheopen}" "{\\isacartoucheclose}" |
|
152 |
| _ => output false "" "") |
|
153 |
end handle ERROR msg => error (msg ^ Position.here (Token.pos_of tok)); |
|
67353 | 154 |
|
67474
90def2b06305
more uniform output of source / text / theory_text, with handling of formal comments etc.;
wenzelm
parents:
67465
diff
changeset
|
155 |
fun output_source ctxt s = |
90def2b06305
more uniform output of source / text / theory_text, with handling of formal comments etc.;
wenzelm
parents:
67465
diff
changeset
|
156 |
output_body ctxt false "" "" (Symbol_Pos.explode (s, Position.none)); |
90def2b06305
more uniform output of source / text / theory_text, with handling of formal comments etc.;
wenzelm
parents:
67465
diff
changeset
|
157 |
|
67381 | 158 |
fun check_comments ctxt = |
67572 | 159 |
Comment.read_body #> List.app (fn (comment, syms) => |
67388
5fc0b0c9a735
clarified markup: more like outer syntax side-comment;
wenzelm
parents:
67386
diff
changeset
|
160 |
let |
5fc0b0c9a735
clarified markup: more like outer syntax side-comment;
wenzelm
parents:
67386
diff
changeset
|
161 |
val pos = #1 (Symbol_Pos.range syms); |
5fc0b0c9a735
clarified markup: more like outer syntax side-comment;
wenzelm
parents:
67386
diff
changeset
|
162 |
val _ = |
67429 | 163 |
comment |> Option.app (fn kind => |
69966 | 164 |
Context_Position.reports ctxt (map (pair pos) (Comment.kind_markups kind))); |
67571
f858fe5531ac
more uniform treatment of formal comments within document source;
wenzelm
parents:
67570
diff
changeset
|
165 |
val _ = output_comment_symbols ctxt {antiq = false} (comment, syms); |
67425
7d4a088dbc0e
clarified modules: uniform notion of formal comments;
wenzelm
parents:
67421
diff
changeset
|
166 |
in if comment = SOME Comment.Comment then check_comments ctxt syms else () end); |
67377
143665524d8e
check formal comments recursively, within arbitrary cartouches (unknown sublanguages);
wenzelm
parents:
67375
diff
changeset
|
167 |
|
67353 | 168 |
end; |
169 |
||
170 |
||
67356
ba226b87c69e
output token content with formal comments and antiquotations;
wenzelm
parents:
67354
diff
changeset
|
171 |
|
ba226b87c69e
output token content with formal comments and antiquotations;
wenzelm
parents:
67354
diff
changeset
|
172 |
(** present theory source **) |
ba226b87c69e
output token content with formal comments and antiquotations;
wenzelm
parents:
67354
diff
changeset
|
173 |
|
22124 | 174 |
(* presentation tokens *) |
175 |
||
176 |
datatype token = |
|
67360 | 177 |
Ignore_Token |
59065 | 178 |
| Basic_Token of Token.T |
179 |
| Markup_Token of string * Input.source |
|
180 |
| Markup_Env_Token of string * Input.source |
|
61456 | 181 |
| Raw_Token of Input.source; |
22124 | 182 |
|
59065 | 183 |
fun basic_token pred (Basic_Token tok) = pred tok |
22124 | 184 |
| basic_token _ _ = false; |
185 |
||
69876 | 186 |
val white_token = basic_token Document_Source.is_white; |
187 |
val white_comment_token = basic_token Document_Source.is_white_comment; |
|
36959
f5417836dbea
renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents:
36950
diff
changeset
|
188 |
val blank_token = basic_token Token.is_blank; |
f5417836dbea
renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents:
36950
diff
changeset
|
189 |
val newline_token = basic_token Token.is_newline; |
22124 | 190 |
|
67381 | 191 |
fun present_token ctxt tok = |
61457 | 192 |
(case tok of |
67360 | 193 |
Ignore_Token => [] |
67381 | 194 |
| Basic_Token tok => output_token ctxt tok |
67357 | 195 |
| Markup_Token (cmd, source) => |
196 |
Latex.enclose_body ("%\n\\isamarkup" ^ cmd ^ "{") "%\n}\n" |
|
67569
5d71b114e7a3
avoid proliferation of language_document reports;
wenzelm
parents:
67567
diff
changeset
|
197 |
(output_document ctxt {markdown = false} source) |
61457 | 198 |
| Markup_Env_Token (cmd, source) => |
67569
5d71b114e7a3
avoid proliferation of language_document reports;
wenzelm
parents:
67567
diff
changeset
|
199 |
[Latex.environment_block ("isamarkup" ^ cmd) (output_document ctxt {markdown = true} source)] |
67186
a58bbe66ac81
avoid excessive whitespace between antiquotations and text;
wenzelm
parents:
67184
diff
changeset
|
200 |
| Raw_Token source => |
67569
5d71b114e7a3
avoid proliferation of language_document reports;
wenzelm
parents:
67567
diff
changeset
|
201 |
Latex.string "%\n" :: output_document ctxt {markdown = true} source @ [Latex.string "\n"]); |
61455 | 202 |
|
203 |
||
22124 | 204 |
(* command spans *) |
205 |
||
69887 | 206 |
type command = string * Position.T; (*name, position*) |
22124 | 207 |
type source = (token * (string * int)) list; (*token, markup flag, meta-comment depth*) |
208 |
||
209 |
datatype span = Span of command * (source * source * source * source) * bool; |
|
210 |
||
211 |
fun make_span cmd src = |
|
212 |
let |
|
67522 | 213 |
fun chop_newline (tok :: toks) = |
22124 | 214 |
if newline_token (fst tok) then ([tok], toks, true) |
215 |
else ([], tok :: toks, false) |
|
67522 | 216 |
| chop_newline [] = ([], [], false); |
22124 | 217 |
val (((src_prefix, src_main), src_suffix1), (src_suffix2, src_appendix, newline)) = |
218 |
src |
|
67522 | 219 |
|> chop_prefix (white_token o fst) |
220 |
||>> chop_suffix (white_token o fst) |
|
221 |
||>> chop_prefix (white_comment_token o fst) |
|
222 |
||> chop_newline; |
|
22124 | 223 |
in Span (cmd, (src_prefix, src_main, src_suffix1 @ src_suffix2, src_appendix), newline) end; |
224 |
||
225 |
||
226 |
(* present spans *) |
|
227 |
||
228 |
local |
|
229 |
||
230 |
fun err_bad_nesting pos = |
|
231 |
error ("Bad nesting of commands in presentation" ^ pos); |
|
232 |
||
233 |
fun edge which f (x: string option, y) = |
|
234 |
if x = y then I |
|
67194
1c0a6a957114
positions as postlude: avoid intrusion of odd %-forms into main tex source;
wenzelm
parents:
67191
diff
changeset
|
235 |
else (case which (x, y) of NONE => I | SOME txt => cons (Latex.string (f txt))); |
22124 | 236 |
|
237 |
val begin_tag = edge #2 Latex.begin_tag; |
|
238 |
val end_tag = edge #1 Latex.end_tag; |
|
239 |
fun open_delim delim e = edge #2 Latex.begin_delim e #> delim #> edge #2 Latex.end_delim e; |
|
240 |
fun close_delim delim e = edge #1 Latex.begin_delim e #> delim #> edge #1 Latex.end_delim e; |
|
241 |
||
68507 | 242 |
fun read_tag s = |
68512 | 243 |
(case space_explode "%" s of |
244 |
["", b] => (SOME b, NONE) |
|
68510
795f39bfe4e1
simplified: allow only command names, with dummy for default;
wenzelm
parents:
68509
diff
changeset
|
245 |
| [a, b] => (NONE, SOME (a, b)) |
68507 | 246 |
| _ => error ("Bad document_tags specification: " ^ quote s)); |
247 |
||
22124 | 248 |
in |
249 |
||
68506 | 250 |
fun make_command_tag options keywords = |
251 |
let |
|
68507 | 252 |
val document_tags = |
253 |
map read_tag (space_explode "," (Options.string options \<^system_option>\<open>document_tags\<close>)); |
|
254 |
val document_tags_default = map_filter #1 document_tags; |
|
68510
795f39bfe4e1
simplified: allow only command names, with dummy for default;
wenzelm
parents:
68509
diff
changeset
|
255 |
val document_tags_command = map_filter #2 document_tags; |
68506 | 256 |
in |
257 |
fn {cmd_name, cmd_tags, tag, active_tag} => fn state => fn state' => |
|
258 |
let |
|
259 |
val tag' = try hd (fold (update (op =)) cmd_tags (the_list tag)); |
|
68508 | 260 |
|
68509 | 261 |
val keyword_tags = |
262 |
if cmd_name = "end" andalso Toplevel.is_end_theory state' then ["theory"] |
|
263 |
else Keyword.command_tags keywords cmd_name; |
|
68508 | 264 |
val command_tags = |
265 |
the_list (AList.lookup (op =) document_tags_command cmd_name) @ |
|
266 |
keyword_tags @ document_tags_default; |
|
267 |
||
68506 | 268 |
val active_tag' = |
269 |
if is_some tag' then tag' |
|
270 |
else |
|
68508 | 271 |
(case command_tags of |
68506 | 272 |
default_tag :: _ => SOME default_tag |
273 |
| [] => |
|
274 |
if Keyword.is_vacuous keywords cmd_name andalso Toplevel.is_proof state |
|
275 |
then active_tag |
|
276 |
else NONE); |
|
277 |
in {tag' = tag', active_tag' = active_tag'} end |
|
278 |
end; |
|
279 |
||
69892 | 280 |
fun present_span command_tag span state state' |
67194
1c0a6a957114
positions as postlude: avoid intrusion of odd %-forms into main tex source;
wenzelm
parents:
67191
diff
changeset
|
281 |
(tag_stack, active_tag, newline, latex, present_cont) = |
22124 | 282 |
let |
69892 | 283 |
val ctxt' = Toplevel.presentation_context state'; |
22124 | 284 |
val present = fold (fn (tok, (flag, 0)) => |
67381 | 285 |
fold cons (present_token ctxt' tok) |
67194
1c0a6a957114
positions as postlude: avoid intrusion of odd %-forms into main tex source;
wenzelm
parents:
67191
diff
changeset
|
286 |
#> cons (Latex.string flag) |
22124 | 287 |
| _ => I); |
288 |
||
69887 | 289 |
val Span ((cmd_name, cmd_pos), srcs, span_newline) = span; |
69892 | 290 |
val cmd_tags = Document_Source.get_tags ctxt'; |
22124 | 291 |
|
292 |
val (tag, tags) = tag_stack; |
|
68506 | 293 |
val {tag', active_tag'} = |
294 |
command_tag {cmd_name = cmd_name, cmd_tags = cmd_tags, tag = tag, active_tag = active_tag} |
|
295 |
state state'; |
|
296 |
val edge = (active_tag, active_tag'); |
|
22124 | 297 |
|
58999
ed09ae4ea2d8
uniform treatment of all document markup commands: 'text' and 'txt' merely differ in LaTeX style;
wenzelm
parents:
58992
diff
changeset
|
298 |
val nesting = Toplevel.level state' - Toplevel.level state; |
ed09ae4ea2d8
uniform treatment of all document markup commands: 'text' and 'txt' merely differ in LaTeX style;
wenzelm
parents:
58992
diff
changeset
|
299 |
|
22124 | 300 |
val newline' = |
301 |
if is_none active_tag' then span_newline else newline; |
|
302 |
||
303 |
val tag_stack' = |
|
304 |
if nesting = 0 andalso not (Toplevel.is_proof state) then tag_stack |
|
305 |
else if nesting >= 0 then (tag', replicate nesting tag @ tags) |
|
306 |
else |
|
33957 | 307 |
(case drop (~ nesting - 1) tags of |
58999
ed09ae4ea2d8
uniform treatment of all document markup commands: 'text' and 'txt' merely differ in LaTeX style;
wenzelm
parents:
58992
diff
changeset
|
308 |
tg :: tgs => (tg, tgs) |
48992 | 309 |
| [] => err_bad_nesting (Position.here cmd_pos)); |
22124 | 310 |
|
67194
1c0a6a957114
positions as postlude: avoid intrusion of odd %-forms into main tex source;
wenzelm
parents:
67191
diff
changeset
|
311 |
val latex' = |
1c0a6a957114
positions as postlude: avoid intrusion of odd %-forms into main tex source;
wenzelm
parents:
67191
diff
changeset
|
312 |
latex |
22124 | 313 |
|> end_tag edge |
314 |
|> close_delim (fst present_cont) edge |
|
315 |
|> snd present_cont |
|
316 |
|> open_delim (present (#1 srcs)) edge |
|
317 |
|> begin_tag edge |
|
318 |
|> present (#2 srcs); |
|
319 |
val present_cont' = |
|
320 |
if newline then (present (#3 srcs), present (#4 srcs)) |
|
321 |
else (I, present (#3 srcs) #> present (#4 srcs)); |
|
67194
1c0a6a957114
positions as postlude: avoid intrusion of odd %-forms into main tex source;
wenzelm
parents:
67191
diff
changeset
|
322 |
in (tag_stack', active_tag', newline', latex', present_cont') end; |
22124 | 323 |
|
67194
1c0a6a957114
positions as postlude: avoid intrusion of odd %-forms into main tex source;
wenzelm
parents:
67191
diff
changeset
|
324 |
fun present_trailer ((_, tags), active_tag, _, latex, present_cont) = |
22124 | 325 |
if not (null tags) then err_bad_nesting " at end of theory" |
326 |
else |
|
67194
1c0a6a957114
positions as postlude: avoid intrusion of odd %-forms into main tex source;
wenzelm
parents:
67191
diff
changeset
|
327 |
latex |
22124 | 328 |
|> end_tag (active_tag, NONE) |
329 |
|> close_delim (fst present_cont) (active_tag, NONE) |
|
330 |
|> snd present_cont; |
|
331 |
||
332 |
end; |
|
333 |
||
334 |
||
28427
cc9f7d99fb73
turned process_thy into present_thy, which merely does presentation (wrt. persistent intermediate states);
wenzelm
parents:
28273
diff
changeset
|
335 |
(* present_thy *) |
22124 | 336 |
|
337 |
local |
|
338 |
||
61455 | 339 |
val markup_true = "\\isamarkuptrue%\n"; |
340 |
val markup_false = "\\isamarkupfalse%\n"; |
|
341 |
||
36959
f5417836dbea
renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents:
36950
diff
changeset
|
342 |
val opt_newline = Scan.option (Scan.one Token.is_newline); |
22124 | 343 |
|
344 |
val ignore = |
|
36959
f5417836dbea
renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents:
36950
diff
changeset
|
345 |
Scan.depend (fn d => opt_newline |-- Scan.one Token.is_begin_ignore |
22124 | 346 |
>> pair (d + 1)) || |
36959
f5417836dbea
renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents:
36950
diff
changeset
|
347 |
Scan.depend (fn d => Scan.one Token.is_end_ignore --| |
43947
9b00f09f7721
defer evaluation of Scan.message, for improved performance in the frequent situation where failure is handled later (e.g. via ||);
wenzelm
parents:
43564
diff
changeset
|
348 |
(if d = 0 then Scan.fail_with (K (fn () => "Bad nesting of meta-comments")) else opt_newline) |
22124 | 349 |
>> pair (d - 1)); |
350 |
||
351 |
val locale = |
|
69876 | 352 |
Scan.option ((Parse.$$$ "(" -- Document_Source.improper -- Parse.$$$ "in") |-- |
353 |
Parse.!!! |
|
354 |
(Document_Source.improper |-- Parse.name --| (Document_Source.improper -- Parse.$$$ ")"))); |
|
22124 | 355 |
|
356 |
in |
|
357 |
||
68182 | 358 |
type segment = {span: Command_Span.span, command: Toplevel.transition, state: Toplevel.state}; |
68178 | 359 |
|
68506 | 360 |
fun present_thy options thy (segments: segment list) = |
22124 | 361 |
let |
58928
23d0ffd48006
plain value Keywords.keywords, which might be used outside theory for bootstrap purposes;
wenzelm
parents:
58923
diff
changeset
|
362 |
val keywords = Thy_Header.get_keywords thy; |
23d0ffd48006
plain value Keywords.keywords, which might be used outside theory for bootstrap purposes;
wenzelm
parents:
58923
diff
changeset
|
363 |
|
23d0ffd48006
plain value Keywords.keywords, which might be used outside theory for bootstrap purposes;
wenzelm
parents:
58923
diff
changeset
|
364 |
|
22124 | 365 |
(* tokens *) |
366 |
||
367 |
val ignored = Scan.state --| ignore |
|
67360 | 368 |
>> (fn d => (NONE, (Ignore_Token, ("", d)))); |
22124 | 369 |
|
58999
ed09ae4ea2d8
uniform treatment of all document markup commands: 'text' and 'txt' merely differ in LaTeX style;
wenzelm
parents:
58992
diff
changeset
|
370 |
fun markup pred mk flag = Scan.peek (fn d => |
69876 | 371 |
Document_Source.improper |-- |
58999
ed09ae4ea2d8
uniform treatment of all document markup commands: 'text' and 'txt' merely differ in LaTeX style;
wenzelm
parents:
58992
diff
changeset
|
372 |
Parse.position (Scan.one (fn tok => |
ed09ae4ea2d8
uniform treatment of all document markup commands: 'text' and 'txt' merely differ in LaTeX style;
wenzelm
parents:
58992
diff
changeset
|
373 |
Token.is_command tok andalso pred keywords (Token.content_of tok))) -- |
69887 | 374 |
(Document_Source.annotation |-- |
375 |
Parse.!!!! ((Document_Source.improper -- locale -- Document_Source.improper) |-- |
|
376 |
Parse.document_source --| Document_Source.improper_end)) |
|
377 |
>> (fn ((tok, pos'), source) => |
|
378 |
let val name = Token.content_of tok |
|
379 |
in (SOME (name, pos'), (mk (name, source), (flag, d))) end)); |
|
22124 | 380 |
|
381 |
val command = Scan.peek (fn d => |
|
69876 | 382 |
Scan.optional (Scan.one Token.is_command_modifier ::: Document_Source.improper) [] -- |
69887 | 383 |
Scan.one Token.is_command --| Document_Source.annotation |
384 |
>> (fn (cmd_mod, cmd) => |
|
59939
7d46aa03696e
support for 'restricted' modifier: only qualified accesses outside the local scope;
wenzelm
parents:
59924
diff
changeset
|
385 |
map (fn tok => (NONE, (Basic_Token tok, ("", d)))) cmd_mod @ |
69887 | 386 |
[(SOME (Token.content_of cmd, Token.pos_of cmd), |
61455 | 387 |
(Basic_Token cmd, (markup_false, d)))])); |
22124 | 388 |
|
389 |
val cmt = Scan.peek (fn d => |
|
69876 | 390 |
Scan.one Document_Source.is_black_comment >> (fn tok => (NONE, (Basic_Token tok, ("", d))))); |
22124 | 391 |
|
392 |
val other = Scan.peek (fn d => |
|
59065 | 393 |
Parse.not_eof >> (fn tok => (NONE, (Basic_Token tok, ("", d))))); |
22124 | 394 |
|
59924
801b979ec0c2
more general notion of command span: command keyword not necessarily at start;
wenzelm
parents:
59917
diff
changeset
|
395 |
val tokens = |
801b979ec0c2
more general notion of command span: command keyword not necessarily at start;
wenzelm
parents:
59917
diff
changeset
|
396 |
(ignored || |
61455 | 397 |
markup Keyword.is_document_heading Markup_Token markup_true || |
398 |
markup Keyword.is_document_body Markup_Env_Token markup_true || |
|
61456 | 399 |
markup Keyword.is_document_raw (Raw_Token o #2) "") >> single || |
59924
801b979ec0c2
more general notion of command span: command keyword not necessarily at start;
wenzelm
parents:
59917
diff
changeset
|
400 |
command || |
801b979ec0c2
more general notion of command span: command keyword not necessarily at start;
wenzelm
parents:
59917
diff
changeset
|
401 |
(cmt || other) >> single; |
22124 | 402 |
|
403 |
||
404 |
(* spans *) |
|
405 |
||
59065 | 406 |
val is_eof = fn (_, (Basic_Token x, _)) => Token.is_eof x | _ => false; |
407 |
val stopper = Scan.stopper (K (NONE, (Basic_Token Token.eof, ("", 0)))) is_eof; |
|
22124 | 408 |
|
409 |
val cmd = Scan.one (is_some o fst); |
|
27732 | 410 |
val non_cmd = Scan.one (is_none o fst andf not o is_eof) >> #2; |
22124 | 411 |
|
67439
78759a7bd874
more uniform support for formal comments in outer syntax, notably \<^cancel> and \<^latex>;
wenzelm
parents:
67429
diff
changeset
|
412 |
val white_comments = Scan.many (white_comment_token o fst o snd); |
22124 | 413 |
val blank = Scan.one (blank_token o fst o snd); |
414 |
val newline = Scan.one (newline_token o fst o snd); |
|
415 |
val before_cmd = |
|
67439
78759a7bd874
more uniform support for formal comments in outer syntax, notably \<^cancel> and \<^latex>;
wenzelm
parents:
67429
diff
changeset
|
416 |
Scan.option (newline -- white_comments) -- |
78759a7bd874
more uniform support for formal comments in outer syntax, notably \<^cancel> and \<^latex>;
wenzelm
parents:
67429
diff
changeset
|
417 |
Scan.option (newline -- white_comments) -- |
78759a7bd874
more uniform support for formal comments in outer syntax, notably \<^cancel> and \<^latex>;
wenzelm
parents:
67429
diff
changeset
|
418 |
Scan.option (blank -- white_comments) -- cmd; |
22124 | 419 |
|
420 |
val span = |
|
421 |
Scan.repeat non_cmd -- cmd -- |
|
422 |
Scan.repeat (Scan.unless before_cmd non_cmd) -- |
|
423 |
Scan.option (newline >> (single o snd)) |
|
424 |
>> (fn (((toks1, (cmd, tok2)), toks3), tok4) => |
|
425 |
make_span (the cmd) (toks1 @ (tok2 :: (toks3 @ the_default [] tok4)))); |
|
426 |
||
68178 | 427 |
val spans = segments |
428 |
|> maps (Command_Span.content o #span) |
|
67522 | 429 |
|> drop_suffix Token.is_space |
57080
0e5fa27d3293
strip trailing white space, to avoid notorious problems of jEdit with last line;
wenzelm
parents:
56548
diff
changeset
|
430 |
|> Source.of_list |
59924
801b979ec0c2
more general notion of command span: command keyword not necessarily at start;
wenzelm
parents:
59917
diff
changeset
|
431 |
|> Source.source' 0 Token.stopper (Scan.error (Scan.bulk tokens >> flat)) |
58864 | 432 |
|> Source.source stopper (Scan.error (Scan.bulk span)) |
22124 | 433 |
|> Source.exhaust; |
28427
cc9f7d99fb73
turned process_thy into present_thy, which merely does presentation (wrt. persistent intermediate states);
wenzelm
parents:
28273
diff
changeset
|
434 |
|
68178 | 435 |
val command_results = |
68182 | 436 |
segments |> map_filter (fn {command, state, ...} => |
437 |
if Toplevel.is_ignored command then NONE else SOME (command, state)); |
|
68178 | 438 |
|
28427
cc9f7d99fb73
turned process_thy into present_thy, which merely does presentation (wrt. persistent intermediate states);
wenzelm
parents:
28273
diff
changeset
|
439 |
|
cc9f7d99fb73
turned process_thy into present_thy, which merely does presentation (wrt. persistent intermediate states);
wenzelm
parents:
28273
diff
changeset
|
440 |
(* present commands *) |
cc9f7d99fb73
turned process_thy into present_thy, which merely does presentation (wrt. persistent intermediate states);
wenzelm
parents:
28273
diff
changeset
|
441 |
|
68506 | 442 |
val command_tag = make_command_tag options keywords; |
67138 | 443 |
|
28427
cc9f7d99fb73
turned process_thy into present_thy, which merely does presentation (wrt. persistent intermediate states);
wenzelm
parents:
28273
diff
changeset
|
444 |
fun present_command tr span st st' = |
69892 | 445 |
Toplevel.setmp_thread_position tr (present_span command_tag span st st'); |
28427
cc9f7d99fb73
turned process_thy into present_thy, which merely does presentation (wrt. persistent intermediate states);
wenzelm
parents:
28273
diff
changeset
|
446 |
|
cc9f7d99fb73
turned process_thy into present_thy, which merely does presentation (wrt. persistent intermediate states);
wenzelm
parents:
28273
diff
changeset
|
447 |
fun present _ [] = I |
68178 | 448 |
| present st ((span, (tr, st')) :: rest) = present_command tr span st st' #> present st' rest; |
22124 | 449 |
in |
28427
cc9f7d99fb73
turned process_thy into present_thy, which merely does presentation (wrt. persistent intermediate states);
wenzelm
parents:
28273
diff
changeset
|
450 |
if length command_results = length spans then |
67194
1c0a6a957114
positions as postlude: avoid intrusion of odd %-forms into main tex source;
wenzelm
parents:
67191
diff
changeset
|
451 |
((NONE, []), NONE, true, [], (I, I)) |
69886 | 452 |
|> present (Toplevel.init_toplevel ()) (spans ~~ command_results) |
22124 | 453 |
|> present_trailer |
67194
1c0a6a957114
positions as postlude: avoid intrusion of odd %-forms into main tex source;
wenzelm
parents:
67191
diff
changeset
|
454 |
|> rev |
22124 | 455 |
else error "Messed-up outer syntax for presentation" |
456 |
end; |
|
457 |
||
458 |
end; |
|
459 |
||
460 |
||
461 |
||
67386 | 462 |
(** standard output operations **) |
22124 | 463 |
|
67463 | 464 |
(* pretty printing *) |
22124 | 465 |
|
67463 | 466 |
fun pretty_term ctxt t = |
467 |
Syntax.pretty_term (Variable.auto_fixes t ctxt) t; |
|
24920 | 468 |
|
32898
e871d897969c
term styles also cover antiquotations term_type and typeof
haftmann
parents:
32890
diff
changeset
|
469 |
fun pretty_thm ctxt = pretty_term ctxt o Thm.full_prop_of; |
e871d897969c
term styles also cover antiquotations term_type and typeof
haftmann
parents:
32890
diff
changeset
|
470 |
|
22124 | 471 |
|
30390
ad591ee76c78
simplified interface to define document antiquotations, cf. antiquotatation, maybe_pretty_source, output;
wenzelm
parents:
30381
diff
changeset
|
472 |
(* default output *) |
ad591ee76c78
simplified interface to define document antiquotations, cf. antiquotatation, maybe_pretty_source, output;
wenzelm
parents:
30381
diff
changeset
|
473 |
|
67508 | 474 |
val lines = separate (Latex.string "\\isanewline%\n"); |
67505
ceb324e34c14
clarified signature: items with \isasep are special;
wenzelm
parents:
67475
diff
changeset
|
475 |
val items = separate (Latex.string "\\isasep\\isanewline%\n"); |
22124 | 476 |
|
67463 | 477 |
fun isabelle ctxt body = |
478 |
if Config.get ctxt Document_Antiquotation.thy_output_display |
|
479 |
then Latex.environment_block "isabelle" body |
|
480 |
else Latex.block (Latex.enclose_body "\\isa{" "}" body); |
|
59175
bf465f335e85
system option "pretty_margin" is superseded by "thy_output_margin";
wenzelm
parents:
59067
diff
changeset
|
481 |
|
67463 | 482 |
fun isabelle_typewriter ctxt body = |
483 |
if Config.get ctxt Document_Antiquotation.thy_output_display |
|
484 |
then Latex.environment_block "isabellett" body |
|
485 |
else Latex.block (Latex.enclose_body "\\isatt{" "}" body); |
|
486 |
||
487 |
fun typewriter ctxt s = |
|
488 |
isabelle_typewriter ctxt [Latex.string (Latex.output_ascii s)]; |
|
489 |
||
490 |
fun verbatim ctxt = |
|
491 |
if Config.get ctxt Document_Antiquotation.thy_output_display |
|
492 |
then Document_Antiquotation.indent_lines ctxt #> typewriter ctxt |
|
67508 | 493 |
else split_lines #> map (typewriter ctxt) #> lines #> Latex.block; |
22124 | 494 |
|
67474
90def2b06305
more uniform output of source / text / theory_text, with handling of formal comments etc.;
wenzelm
parents:
67465
diff
changeset
|
495 |
fun source ctxt = |
90def2b06305
more uniform output of source / text / theory_text, with handling of formal comments etc.;
wenzelm
parents:
67465
diff
changeset
|
496 |
Token.args_of_src |
90def2b06305
more uniform output of source / text / theory_text, with handling of formal comments etc.;
wenzelm
parents:
67465
diff
changeset
|
497 |
#> map (Token.unparse #> Document_Antiquotation.prepare_lines ctxt) |
90def2b06305
more uniform output of source / text / theory_text, with handling of formal comments etc.;
wenzelm
parents:
67465
diff
changeset
|
498 |
#> space_implode " " |
90def2b06305
more uniform output of source / text / theory_text, with handling of formal comments etc.;
wenzelm
parents:
67465
diff
changeset
|
499 |
#> output_source ctxt |
90def2b06305
more uniform output of source / text / theory_text, with handling of formal comments etc.;
wenzelm
parents:
67465
diff
changeset
|
500 |
#> isabelle ctxt; |
90def2b06305
more uniform output of source / text / theory_text, with handling of formal comments etc.;
wenzelm
parents:
67465
diff
changeset
|
501 |
|
67463 | 502 |
fun pretty ctxt = |
67505
ceb324e34c14
clarified signature: items with \isasep are special;
wenzelm
parents:
67475
diff
changeset
|
503 |
Document_Antiquotation.output ctxt #> Latex.string #> single #> isabelle ctxt; |
ceb324e34c14
clarified signature: items with \isasep are special;
wenzelm
parents:
67475
diff
changeset
|
504 |
|
ceb324e34c14
clarified signature: items with \isasep are special;
wenzelm
parents:
67475
diff
changeset
|
505 |
fun pretty_source ctxt src prt = |
ceb324e34c14
clarified signature: items with \isasep are special;
wenzelm
parents:
67475
diff
changeset
|
506 |
if Config.get ctxt Document_Antiquotation.thy_output_source |
ceb324e34c14
clarified signature: items with \isasep are special;
wenzelm
parents:
67475
diff
changeset
|
507 |
then source ctxt src else pretty ctxt prt; |
67463 | 508 |
|
67505
ceb324e34c14
clarified signature: items with \isasep are special;
wenzelm
parents:
67475
diff
changeset
|
509 |
fun pretty_items ctxt = |
ceb324e34c14
clarified signature: items with \isasep are special;
wenzelm
parents:
67475
diff
changeset
|
510 |
map (Document_Antiquotation.output ctxt #> Latex.string) #> items #> isabelle ctxt; |
ceb324e34c14
clarified signature: items with \isasep are special;
wenzelm
parents:
67475
diff
changeset
|
511 |
|
ceb324e34c14
clarified signature: items with \isasep are special;
wenzelm
parents:
67475
diff
changeset
|
512 |
fun pretty_items_source ctxt src prts = |
67474
90def2b06305
more uniform output of source / text / theory_text, with handling of formal comments etc.;
wenzelm
parents:
67465
diff
changeset
|
513 |
if Config.get ctxt Document_Antiquotation.thy_output_source |
67505
ceb324e34c14
clarified signature: items with \isasep are special;
wenzelm
parents:
67475
diff
changeset
|
514 |
then source ctxt src else pretty_items ctxt prts; |
61473
34d1913f0b20
clarified control antiquotations: decode control symbol to get name;
wenzelm
parents:
61471
diff
changeset
|
515 |
|
67465 | 516 |
|
517 |
(* antiquotation variants *) |
|
518 |
||
69592
a80d8ec6c998
support for isabelle update -u control_cartouches;
wenzelm
parents:
68512
diff
changeset
|
519 |
local |
67463 | 520 |
|
69592
a80d8ec6c998
support for isabelle update -u control_cartouches;
wenzelm
parents:
68512
diff
changeset
|
521 |
fun gen_setup name embedded = |
a80d8ec6c998
support for isabelle update -u control_cartouches;
wenzelm
parents:
68512
diff
changeset
|
522 |
if embedded |
a80d8ec6c998
support for isabelle update -u control_cartouches;
wenzelm
parents:
68512
diff
changeset
|
523 |
then Document_Antiquotation.setup_embedded name |
a80d8ec6c998
support for isabelle update -u control_cartouches;
wenzelm
parents:
68512
diff
changeset
|
524 |
else Document_Antiquotation.setup name; |
a80d8ec6c998
support for isabelle update -u control_cartouches;
wenzelm
parents:
68512
diff
changeset
|
525 |
|
a80d8ec6c998
support for isabelle update -u control_cartouches;
wenzelm
parents:
68512
diff
changeset
|
526 |
fun gen_antiquotation_pretty name embedded scan f = |
a80d8ec6c998
support for isabelle update -u control_cartouches;
wenzelm
parents:
68512
diff
changeset
|
527 |
gen_setup name embedded scan (fn {context = ctxt, argument = x, ...} => pretty ctxt (f ctxt x)); |
a80d8ec6c998
support for isabelle update -u control_cartouches;
wenzelm
parents:
68512
diff
changeset
|
528 |
|
a80d8ec6c998
support for isabelle update -u control_cartouches;
wenzelm
parents:
68512
diff
changeset
|
529 |
fun gen_antiquotation_pretty_source name embedded scan f = |
a80d8ec6c998
support for isabelle update -u control_cartouches;
wenzelm
parents:
68512
diff
changeset
|
530 |
gen_setup name embedded scan |
67463 | 531 |
(fn {context = ctxt, source = src, argument = x} => pretty_source ctxt src (f ctxt x)); |
532 |
||
69592
a80d8ec6c998
support for isabelle update -u control_cartouches;
wenzelm
parents:
68512
diff
changeset
|
533 |
fun gen_antiquotation_raw name embedded scan f = |
a80d8ec6c998
support for isabelle update -u control_cartouches;
wenzelm
parents:
68512
diff
changeset
|
534 |
gen_setup name embedded scan (fn {context = ctxt, argument = x, ...} => f ctxt x); |
a80d8ec6c998
support for isabelle update -u control_cartouches;
wenzelm
parents:
68512
diff
changeset
|
535 |
|
a80d8ec6c998
support for isabelle update -u control_cartouches;
wenzelm
parents:
68512
diff
changeset
|
536 |
fun gen_antiquotation_verbatim name embedded scan f = |
a80d8ec6c998
support for isabelle update -u control_cartouches;
wenzelm
parents:
68512
diff
changeset
|
537 |
gen_antiquotation_raw name embedded scan (fn ctxt => verbatim ctxt o f ctxt); |
a80d8ec6c998
support for isabelle update -u control_cartouches;
wenzelm
parents:
68512
diff
changeset
|
538 |
|
a80d8ec6c998
support for isabelle update -u control_cartouches;
wenzelm
parents:
68512
diff
changeset
|
539 |
in |
67463 | 540 |
|
69592
a80d8ec6c998
support for isabelle update -u control_cartouches;
wenzelm
parents:
68512
diff
changeset
|
541 |
fun antiquotation_pretty name = gen_antiquotation_pretty name false; |
a80d8ec6c998
support for isabelle update -u control_cartouches;
wenzelm
parents:
68512
diff
changeset
|
542 |
fun antiquotation_pretty_embedded name = gen_antiquotation_pretty name true; |
a80d8ec6c998
support for isabelle update -u control_cartouches;
wenzelm
parents:
68512
diff
changeset
|
543 |
|
a80d8ec6c998
support for isabelle update -u control_cartouches;
wenzelm
parents:
68512
diff
changeset
|
544 |
fun antiquotation_pretty_source name = gen_antiquotation_pretty_source name false; |
a80d8ec6c998
support for isabelle update -u control_cartouches;
wenzelm
parents:
68512
diff
changeset
|
545 |
fun antiquotation_pretty_source_embedded name = gen_antiquotation_pretty_source name true; |
a80d8ec6c998
support for isabelle update -u control_cartouches;
wenzelm
parents:
68512
diff
changeset
|
546 |
|
a80d8ec6c998
support for isabelle update -u control_cartouches;
wenzelm
parents:
68512
diff
changeset
|
547 |
fun antiquotation_raw name = gen_antiquotation_raw name false; |
a80d8ec6c998
support for isabelle update -u control_cartouches;
wenzelm
parents:
68512
diff
changeset
|
548 |
fun antiquotation_raw_embedded name = gen_antiquotation_raw name true; |
a80d8ec6c998
support for isabelle update -u control_cartouches;
wenzelm
parents:
68512
diff
changeset
|
549 |
|
a80d8ec6c998
support for isabelle update -u control_cartouches;
wenzelm
parents:
68512
diff
changeset
|
550 |
fun antiquotation_verbatim name = gen_antiquotation_verbatim name false; |
a80d8ec6c998
support for isabelle update -u control_cartouches;
wenzelm
parents:
68512
diff
changeset
|
551 |
fun antiquotation_verbatim_embedded name = gen_antiquotation_verbatim name true; |
61491
97261e6c1d42
another antiquotation short form: undecorated cartouche as alias for @{text};
wenzelm
parents:
61473
diff
changeset
|
552 |
|
30390
ad591ee76c78
simplified interface to define document antiquotations, cf. antiquotatation, maybe_pretty_source, output;
wenzelm
parents:
30381
diff
changeset
|
553 |
end; |
69592
a80d8ec6c998
support for isabelle update -u control_cartouches;
wenzelm
parents:
68512
diff
changeset
|
554 |
|
a80d8ec6c998
support for isabelle update -u control_cartouches;
wenzelm
parents:
68512
diff
changeset
|
555 |
end; |