239 fun open_delim delim e = edge #2 Latex.begin_delim e #> delim #> edge #2 Latex.end_delim e; |
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; |
240 fun close_delim delim e = edge #1 Latex.begin_delim e #> delim #> edge #1 Latex.end_delim e; |
241 |
241 |
242 fun read_tag s = |
242 fun read_tag s = |
243 (case space_explode "=" s of |
243 (case space_explode "=" s of |
244 [] => (SOME s, NONE, NONE) |
244 ["*", b] => (SOME b, NONE) |
245 | [_] => (SOME s, NONE, NONE) |
245 | [a, b] => (NONE, SOME (a, b)) |
246 | [a, b] => |
|
247 if String.isPrefix "[" a andalso String.isSuffix "]" a |
|
248 then (NONE, SOME (unenclose a, b), NONE) |
|
249 else (NONE, NONE, SOME (a, b)) |
|
250 | _ => error ("Bad document_tags specification: " ^ quote s)); |
246 | _ => error ("Bad document_tags specification: " ^ quote s)); |
251 |
247 |
252 in |
248 in |
253 |
249 |
254 fun make_command_tag options keywords = |
250 fun make_command_tag options keywords = |
255 let |
251 let |
256 val document_tags = |
252 val document_tags = |
257 map read_tag (space_explode "," (Options.string options \<^system_option>\<open>document_tags\<close>)); |
253 map read_tag (space_explode "," (Options.string options \<^system_option>\<open>document_tags\<close>)); |
258 val document_tags_default = map_filter #1 document_tags; |
254 val document_tags_default = map_filter #1 document_tags; |
259 val document_tags_category = map_filter #2 document_tags; |
255 val document_tags_command = map_filter #2 document_tags; |
260 val document_tags_command = map_filter #3 document_tags; |
|
261 in |
256 in |
262 fn {cmd_name, cmd_tags, tag, active_tag} => fn state => fn state' => |
257 fn {cmd_name, cmd_tags, tag, active_tag} => fn state => fn state' => |
263 let |
258 let |
264 val tag' = try hd (fold (update (op =)) cmd_tags (the_list tag)); |
259 val tag' = try hd (fold (update (op =)) cmd_tags (the_list tag)); |
265 |
260 |
266 val keyword_tags = |
261 val keyword_tags = |
267 if cmd_name = "end" andalso Toplevel.is_end_theory state' then ["theory"] |
262 if cmd_name = "end" andalso Toplevel.is_end_theory state' then ["theory"] |
268 else Keyword.command_tags keywords cmd_name; |
263 else Keyword.command_tags keywords cmd_name; |
269 val command_tags = |
264 val command_tags = |
270 the_list (AList.lookup (op =) document_tags_command cmd_name) @ |
265 the_list (AList.lookup (op =) document_tags_command cmd_name) @ |
271 map_filter (AList.lookup (op =) document_tags_category) keyword_tags @ |
|
272 keyword_tags @ document_tags_default; |
266 keyword_tags @ document_tags_default; |
273 |
267 |
274 val active_tag' = |
268 val active_tag' = |
275 if is_some tag' then tag' |
269 if is_some tag' then tag' |
276 else |
270 else |